diff --git a/src/element/live-chat.tsx b/src/element/live-chat.tsx index 1caf24e..61ce96d 100644 --- a/src/element/live-chat.tsx +++ b/src/element/live-chat.tsx @@ -12,7 +12,6 @@ import { Profile } from "element/profile"; import { ChatMessage } from "element/chat-message"; import { Goal } from "element/goal"; import { Badge } from "element/badge"; -import { NewGoalDialog } from "element/new-goal"; import { WriteMessage } from "element/write-message"; import useEmoji, { packId } from "hooks/emoji"; import { useLiveChatFeed } from "hooks/live-chat"; @@ -117,7 +116,6 @@ export function LiveChat({ {goal && } - {login?.pubkey === host && } )}
diff --git a/src/element/new-goal.tsx b/src/element/new-goal.tsx index cd950e6..48264bb 100644 --- a/src/element/new-goal.tsx +++ b/src/element/new-goal.tsx @@ -2,19 +2,15 @@ import "./new-goal.css"; import * as Dialog from "@radix-ui/react-dialog"; import AsyncButton from "./async-button"; -import { NostrLink } from "@snort/system"; import { Icon } from "element/icon"; import { useState } from "react"; import { System } from "index"; import { GOAL } from "const"; import { useLogin } from "hooks/login"; import { FormattedMessage } from "react-intl"; +import { defaultRelays } from "const"; -interface NewGoalDialogProps { - link: NostrLink; -} - -export function NewGoalDialog({ link }: NewGoalDialogProps) { +export function NewGoalDialog() { const [open, setOpen] = useState(false); const login = useLogin(); @@ -26,12 +22,9 @@ export function NewGoalDialog({ link }: NewGoalDialogProps) { if (pub) { const evNew = await pub.generic(eb => { eb.kind(GOAL) - .tag(["a", `${link.kind}:${link.author}:${link.id}`]) .tag(["amount", String(Number(goalAmount) * 1000)]) + .tag(["relays", ...Object.keys(defaultRelays)]) .content(goalName); - if (link.relays?.length) { - eb.tag(["relays", ...link.relays]); - } return eb; }); console.debug(evNew); diff --git a/src/element/stream-editor.tsx b/src/element/stream-editor.tsx index 9270594..3710300 100644 --- a/src/element/stream-editor.tsx +++ b/src/element/stream-editor.tsx @@ -3,12 +3,14 @@ import { useEffect, useState, useCallback } from "react"; import { NostrEvent } from "@snort/system"; import { unixNow } from "@snort/shared"; import { TagsInput } from "react-tag-input-component"; +import { FormattedMessage, useIntl } from "react-intl"; import AsyncButton from "./async-button"; import { StreamState } from "../index"; import { findTag } from "../utils"; import { useLogin } from "hooks/login"; -import { FormattedMessage, useIntl } from "react-intl"; +import { NewGoalDialog } from "element/new-goal"; +import { useGoals } from "hooks/goals"; export interface StreamEditorProps { ev?: NostrEvent; @@ -24,6 +26,27 @@ export interface StreamEditorProps { }; } +interface GoalSelectorProps { + goal?: string; + pubkey: string; + onGoalSelect: (g: string) => void; +} + +function GoalSelector({ goal, pubkey, onGoalSelect }: GoalSelectorProps) { + const goals = useGoals(pubkey, true); + const { formatMessage } = useIntl(); + return ( + + ); +} + export function StreamEditor({ ev, onFinish, options }: StreamEditorProps) { const [title, setTitle] = useState(""); const [summary, setSummary] = useState(""); @@ -34,6 +57,7 @@ export function StreamEditor({ ev, onFinish, options }: StreamEditorProps) { const [tags, setTags] = useState([]); const [contentWarning, setContentWarning] = useState(false); const [isValid, setIsValid] = useState(false); + const [goal, setGoal] = useState(); const login = useLogin(); const { formatMessage } = useIntl(); @@ -46,6 +70,7 @@ export function StreamEditor({ ev, onFinish, options }: StreamEditorProps) { setStart(findTag(ev, "starts")); setTags(ev?.tags.filter(a => a[0] === "t").map(a => a[1]) ?? []); setContentWarning(findTag(ev, "content-warning") !== undefined); + setGoal(findTag(ev, "goal")); }, [ev?.id]); const validate = useCallback(() => { @@ -90,6 +115,9 @@ export function StreamEditor({ ev, onFinish, options }: StreamEditorProps) { if (contentWarning) { eb.tag(["content-warning", "nsfw"]); } + if (goal && goal.length > 0) { + eb.tag(["goal", goal]); + } return eb; }); console.debug(evNew); @@ -201,6 +229,19 @@ export function StreamEditor({ ev, onFinish, options }: StreamEditorProps) {
)} + {login?.pubkey && ( + <> +
+

+ +

+
+ +
+
+ + + )} {(options?.canSetContentWarning ?? true) && (
diff --git a/src/hooks/goals.ts b/src/hooks/goals.ts index 76d067e..d97bcdd 100644 --- a/src/hooks/goals.ts +++ b/src/hooks/goals.ts @@ -1,22 +1,31 @@ import { useMemo } from "react"; -import { RequestBuilder, ReplaceableNoteStore, NostrLink } from "@snort/system"; +import { RequestBuilder, FlatNoteStore, ReplaceableNoteStore } from "@snort/system"; import { useRequestBuilder } from "@snort/system-react"; -import { unwrap } from "@snort/shared"; import { GOAL } from "const"; -export function useZapGoal(host: string, link?: NostrLink, leaveOpen = false) { +export function useZapGoal(id?: string) { const sub = useMemo(() => { - if (!link) return null; - const b = new RequestBuilder(`goals:${host.slice(0, 12)}`); - b.withOptions({ leaveOpen }); - b.withFilter() - .kinds([GOAL]) - .authors([host]) - .tag("a", [`${link.kind}:${unwrap(link.author)}:${link.id}`]); + if (!id) return null; + const b = new RequestBuilder(`goal:${id.slice(0, 12)}`); + b.withFilter().kinds([GOAL]).ids([id]); return b; - }, [link, leaveOpen]); + }, [id]); const { data } = useRequestBuilder(ReplaceableNoteStore, sub); return data; } + +export function useGoals(pubkey?: string, leaveOpen = false) { + const sub = useMemo(() => { + if (!pubkey) return null; + const b = new RequestBuilder(`goals:${pubkey.slice(0, 12)}`); + b.withOptions({ leaveOpen }); + b.withFilter().kinds([GOAL]).authors([pubkey]); + return b; + }, [pubkey, leaveOpen]); + + const { data } = useRequestBuilder(FlatNoteStore, sub); + + return data; +} diff --git a/src/index.css b/src/index.css index 1411e7e..dcd7ab0 100644 --- a/src/index.css +++ b/src/index.css @@ -190,6 +190,16 @@ input[type="number"] { font-weight: 500; } +select { + font-family: inherit; + border: unset; + background-color: unset; + color: inherit; + width: 100%; + font-size: 16px; + font-weight: 500; +} + input[type="checkbox"] { -webkit-appearance: none; -moz-appearance: none; diff --git a/src/lang.json b/src/lang.json index efce7e3..1701d9f 100644 --- a/src/lang.json +++ b/src/lang.json @@ -23,6 +23,9 @@ "0GfNiL": { "defaultMessage": "Stream Zap Goals" }, + "0VV/sK": { + "defaultMessage": "Goal" + }, "1EYCdR": { "defaultMessage": "Tags" }, @@ -128,6 +131,9 @@ "HAlOn1": { "defaultMessage": "Name" }, + "I/TubD": { + "defaultMessage": "Select a goal..." + }, "I1kjHI": { "defaultMessage": "Supports {markdown}" }, diff --git a/src/pages/stream-page.tsx b/src/pages/stream-page.tsx index a0016df..3973d46 100644 --- a/src/pages/stream-page.tsx +++ b/src/pages/stream-page.tsx @@ -114,7 +114,7 @@ export function StreamPage({ link, evPreload }: { evPreload?: NostrEvent; link: const ev = useCurrentStreamFeed(link, true, evPreload); const host = getHost(ev); const evLink = ev ? eventToLink(ev) : undefined; - const goal = useZapGoal(host, evLink, true); + const goal = useZapGoal(findTag(ev, "goal")); const title = findTag(ev, "title"); const summary = findTag(ev, "summary"); diff --git a/src/providers/zsz.ts b/src/providers/zsz.ts index 77f06a4..fe11c72 100644 --- a/src/providers/zsz.ts +++ b/src/providers/zsz.ts @@ -59,12 +59,14 @@ export class Nip103StreamProvider implements StreamProvider { const image = findTag(ev, "image"); const tags = ev?.tags.filter(a => a[0] === "t").map(a => a[1]); const contentWarning = findTag(ev, "content-warning"); + const goal = findTag(ev, "goal"); await this.#getJson("PATCH", "event", { title, summary, image, tags, content_warning: contentWarning, + goal, }); } diff --git a/src/translations/af_ZA.json b/src/translations/af_ZA.json index af4cd96..efce7e3 100644 --- a/src/translations/af_ZA.json +++ b/src/translations/af_ZA.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/ar_SA.json b/src/translations/ar_SA.json index af4cd96..efce7e3 100644 --- a/src/translations/ar_SA.json +++ b/src/translations/ar_SA.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/ca_ES.json b/src/translations/ca_ES.json index af4cd96..efce7e3 100644 --- a/src/translations/ca_ES.json +++ b/src/translations/ca_ES.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/cs_CZ.json b/src/translations/cs_CZ.json index af4cd96..efce7e3 100644 --- a/src/translations/cs_CZ.json +++ b/src/translations/cs_CZ.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/da_DK.json b/src/translations/da_DK.json index af4cd96..efce7e3 100644 --- a/src/translations/da_DK.json +++ b/src/translations/da_DK.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/de_DE.json b/src/translations/de_DE.json index 3a35daf..662625c 100644 --- a/src/translations/de_DE.json +++ b/src/translations/de_DE.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/el_GR.json b/src/translations/el_GR.json index af4cd96..efce7e3 100644 --- a/src/translations/el_GR.json +++ b/src/translations/el_GR.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/en.json b/src/translations/en.json index d3ee781..e01d1b1 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -7,6 +7,7 @@ "/GCoTA": "Clear", "04lmFi": "Save Key", "0GfNiL": "Stream Zap Goals", + "0VV/sK": "Goal", "1EYCdR": "Tags", "1qsXCO": "eg. name@wallet.com", "2/2yg+": "Add", @@ -42,6 +43,7 @@ "H/bNs9": "Save this and keep it safe! If you lose this key, you won't be able to access your account ever again. Yep, it's that serious!", "H5+NAX": "Balance", "HAlOn1": "Name", + "I/TubD": "Select a goal...", "I1kjHI": "Supports {markdown}", "IJDKz3": "Zap amount in {currency}", "INlWvJ": "OR", @@ -126,4 +128,4 @@ "x82IOl": "Mute", "yzKwBQ": "eg. nsec1xyz", "zVDHAu": "Zap Alert" -} +} \ No newline at end of file diff --git a/src/translations/es_ES.json b/src/translations/es_ES.json index 4a5d003..5d5af7c 100644 --- a/src/translations/es_ES.json +++ b/src/translations/es_ES.json @@ -381,4 +381,3 @@ "defaultMessage": "Alerta de Zap" } } - diff --git a/src/translations/fa_IR.json b/src/translations/fa_IR.json index ec4f398..af1b6e9 100644 --- a/src/translations/fa_IR.json +++ b/src/translations/fa_IR.json @@ -381,4 +381,3 @@ "defaultMessage": "هشدار زپ" } } - diff --git a/src/translations/fi_FI.json b/src/translations/fi_FI.json index af4cd96..efce7e3 100644 --- a/src/translations/fi_FI.json +++ b/src/translations/fi_FI.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/fr_FR.json b/src/translations/fr_FR.json index af4cd96..efce7e3 100644 --- a/src/translations/fr_FR.json +++ b/src/translations/fr_FR.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/he_IL.json b/src/translations/he_IL.json index af4cd96..efce7e3 100644 --- a/src/translations/he_IL.json +++ b/src/translations/he_IL.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/hu_HU.json b/src/translations/hu_HU.json index af4cd96..efce7e3 100644 --- a/src/translations/hu_HU.json +++ b/src/translations/hu_HU.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/it_IT.json b/src/translations/it_IT.json index af4cd96..efce7e3 100644 --- a/src/translations/it_IT.json +++ b/src/translations/it_IT.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/ja_JP.json b/src/translations/ja_JP.json index ebedc8e..2743ab1 100644 --- a/src/translations/ja_JP.json +++ b/src/translations/ja_JP.json @@ -381,4 +381,3 @@ "defaultMessage": "ザップアラート" } } - diff --git a/src/translations/ko_KR.json b/src/translations/ko_KR.json index af4cd96..efce7e3 100644 --- a/src/translations/ko_KR.json +++ b/src/translations/ko_KR.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/nl_NL.json b/src/translations/nl_NL.json index 361bbe8..2d1107a 100644 --- a/src/translations/nl_NL.json +++ b/src/translations/nl_NL.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/no_NO.json b/src/translations/no_NO.json index af4cd96..efce7e3 100644 --- a/src/translations/no_NO.json +++ b/src/translations/no_NO.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/pl_PL.json b/src/translations/pl_PL.json index af4cd96..efce7e3 100644 --- a/src/translations/pl_PL.json +++ b/src/translations/pl_PL.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/pt_BR.json b/src/translations/pt_BR.json index af4cd96..efce7e3 100644 --- a/src/translations/pt_BR.json +++ b/src/translations/pt_BR.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/pt_PT.json b/src/translations/pt_PT.json index af4cd96..efce7e3 100644 --- a/src/translations/pt_PT.json +++ b/src/translations/pt_PT.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/ro_RO.json b/src/translations/ro_RO.json index af4cd96..efce7e3 100644 --- a/src/translations/ro_RO.json +++ b/src/translations/ro_RO.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/ru_RU.json b/src/translations/ru_RU.json index af4cd96..efce7e3 100644 --- a/src/translations/ru_RU.json +++ b/src/translations/ru_RU.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/sr_SP.json b/src/translations/sr_SP.json index af4cd96..efce7e3 100644 --- a/src/translations/sr_SP.json +++ b/src/translations/sr_SP.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/sv_SE.json b/src/translations/sv_SE.json index 1e73098..836fda9 100644 --- a/src/translations/sv_SE.json +++ b/src/translations/sv_SE.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/sw_KE.json b/src/translations/sw_KE.json index b1594fb..ab5b241 100644 --- a/src/translations/sw_KE.json +++ b/src/translations/sw_KE.json @@ -381,4 +381,3 @@ "defaultMessage": "Tahadhari ya Zap" } } - diff --git a/src/translations/th_TH.json b/src/translations/th_TH.json index 5abe53d..b5edbf8 100644 --- a/src/translations/th_TH.json +++ b/src/translations/th_TH.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/tr_TR.json b/src/translations/tr_TR.json index af4cd96..efce7e3 100644 --- a/src/translations/tr_TR.json +++ b/src/translations/tr_TR.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/uk_UA.json b/src/translations/uk_UA.json index af4cd96..efce7e3 100644 --- a/src/translations/uk_UA.json +++ b/src/translations/uk_UA.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/vi_VN.json b/src/translations/vi_VN.json index af4cd96..efce7e3 100644 --- a/src/translations/vi_VN.json +++ b/src/translations/vi_VN.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/zh_CN.json b/src/translations/zh_CN.json index af4cd96..efce7e3 100644 --- a/src/translations/zh_CN.json +++ b/src/translations/zh_CN.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } - diff --git a/src/translations/zh_TW.json b/src/translations/zh_TW.json index af4cd96..efce7e3 100644 --- a/src/translations/zh_TW.json +++ b/src/translations/zh_TW.json @@ -381,4 +381,3 @@ "defaultMessage": "Zap Alert" } } -