diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/App.jsx b/app/src/App.jsx index e0026ed..5a06b36 100644 --- a/app/src/App.jsx +++ b/app/src/App.jsx @@ -6,6 +6,7 @@ import { Select } from "@thisbeyond/solid-select"; import "@thisbeyond/solid-select/style.css"; const options = [ + { label: 'Tony Cark', name: 'npub1pmzw37x9fznr0a3znjy4t9rspgx8cs8duqw9tf7d72x2rykr6ypqzyxhmy' }, { label: "Purple Text, Orange Highlights (article by Gigi)", name: "naddr1qqxnzd3cxqmrzv3exgmr2wfeqgsxu35yyt0mwjjh8pcz4zprhxegz69t4wr9t74vk6zne58wzh0waycrqsqqqa28pjfdhz" }, { label: "Nostr (fiatjaf's blog)", name: "https://fiatjaf.com/nostr.html" }, { label: "A native internet protocol for social media (article by Jack)", name: "naddr1qqxnzd3cxyerxd3h8qerwwfcqgsgydql3q4ka27d9wnlrmus4tvkrnc8ftc4h8h5fgyln54gl0a7dgsrqsqqqa28387u5u" }, @@ -41,11 +42,11 @@ function App() { Code on GitHub

zapthreads

- {/*

+

{npub() && Logged in as {npub()}}

-
*/} +

Select a resource:   setRelays(e.target.value)}>

- {anchor() && } + {anchor() && }
; } diff --git a/embedded.html b/embedded.html index b1060fd..ce8a6a6 100644 --- a/embedded.html +++ b/embedded.html @@ -11,11 +11,15 @@ - + - {content() &&
} - {anchor().type === 'error' && <> -

Error!

-
-
{anchor().value}
-

- Only properly formed NIP-19 naddr, note and nevent encoded entities and URLs are supported.

+ return ( + <> +
+ + {content() &&
} + {anchor().type === "error" && ( + <> +

Error!

+
+
{anchor().value}
+

+ Only properly formed NIP-19 naddr, note and nevent encoded + entities and URLs are supported. +

+
+ + )} + {anchor().type !== "error" && ( + <> + {!store.disableFeatures!.includes("reply") && ( + + )} +

+ {commentsLength() > 0 && + `${commentsLength()} comment${ + commentsLength() == 1 ? "" : "s" + }`} +

+ {isChatMode ? ( + + ) : ( + + )} + + )} + +
setShowAdvanced(!showAdvanced())} + > + {ellipsisSvg()}
- } - {anchor().type !== 'error' && <> - {!store.disableFeatures!.includes('reply') && } -

- {commentsLength() > 0 && `${commentsLength()} comment${commentsLength() == 1 ? '' : 's'}`} -

- - } - -
setShowAdvanced(!showAdvanced())}>{ellipsisSvg()}
- {showAdvanced() && <>

Powered by zapthreads

- {store.version &&

Anchor version: {store.version}

} - } -
; + {showAdvanced() && ( + <> +

+ Powered by{" "} + zapthreads +

+ {store.version &&

Anchor version: {store.version}

} + + + )} +
+ + ); }; export default ZapThreads; // NOTE that the element seems to lose reactivity (in Solid, at least) // when using multiple word attributes -customElement('zap-threads', { - anchor: "", - version: "", - relays: "", - user: "", - author: "", - disable: "", - urls: "", - 'reply-placeholder': "", - 'legacy-url': "", -}, (props) => { - return ; -}); +customElement( + "zap-threads", + { + anchor: "", + version: "", + mode: "", + npubpro: "", + relays: "", + user: "", + author: "", + disable: "", + urls: "", + "reply-placeholder": "", + "legacy-url": "", + }, + (props) => { + return ( + + ); + } +); export type ZapThreadsAttributes = { - [key in 'anchor' | 'version' | 'relays' | 'user' | 'author' | 'disable' | 'urls' | 'reply-placeholder' | 'legacy-url']?: string; + [key in + | "anchor" + | "version" + | "relays" + | "user" + | "author" + | "disable" + | "urls" + | "reply-placeholder" + | "legacy-url" + | "mode" + | "npubpro"]?: string; } & JSX.HTMLAttributes; diff --git a/src/reply.tsx b/src/reply.tsx index 48deeff..e8eb770 100644 --- a/src/reply.tsx +++ b/src/reply.tsx @@ -11,19 +11,25 @@ import { decode, npubEncode } from "nostr-tools/nip19"; import { Relay } from "nostr-tools/relay"; import { normalizeURL } from "nostr-tools/utils"; -export const ReplyEditor = (props: { replyTo?: string; onDone?: Function; }) => { +export const ReplyEditor = (props: { replyTo?: string; onDone?: Function; input?: boolean; isFocus?: boolean }) => { const [comment, setComment] = createSignal(''); const [loading, setLoading] = createSignal(false); + const [isLoginProcess, setLoginProcess] = createSignal(false); const [loggedInUser, setLoggedInUser] = createSignal(); const [errorMessage, setErrorMessage] = createSignal(''); const anchor = () => store.anchor!; const profiles = store.profiles!; const relays = () => store.relays!; + const isNpubPro = store.npubPro === 'true' // Sessions const login = async () => { + if(isNpubPro) { + setLoginProcess(true) + } + if (!window.nostr) { onError('Error: No NIP-07 extension!'); return; @@ -55,6 +61,20 @@ export const ReplyEditor = (props: { replyTo?: string; onDone?: Function; }) => } }); + // for npubPro mode this will publish the + // comment after login was executed + createEffect(async () => { + if(isNpubPro) { + if(loggedInUser() && isLoginProcess()) { + setLoginProcess(false) + + if(comment().length) { + await publish(loggedInUser()) + } + } + } + }); + // Publishing const onSuccess = async (event: Event, notice?: string) => { @@ -184,22 +204,29 @@ export const ReplyEditor = (props: { replyTo?: string; onDone?: Function; }) => // Simulate publishing setTimeout(() => onSuccess(event), 1000); } else { - const failures = []; + const failures: string[] = []; + const promises = []; for (const relayUrl of relays()) { - try { - const relay = await Relay.connect(relayUrl); - await relay.publish(event); - } catch (e) { - console.error(e); - failures.push(relayUrl); - } + promises.push(new Promise(async (ok) => { + try { + const relay = await Relay.connect(relayUrl); + await relay.publish(event); + } catch (e) { + console.warn(e); + failures.push(relayUrl); + } + ok(); + })) } + // publish in parallel + await Promise.allSettled(promises); + if (failures.length === relays().length) { onError('Error: Your comment was not published to any relay'); } else { const msg = `Published to ${failures.length}/${relays().length} relays (see console for more info)`; - const notice = failures.length > 0 ? msg : undefined; + const notice = !isNpubPro && failures.length > 0 ? msg : undefined; onSuccess(event, notice); } // clear up failure log @@ -209,19 +236,31 @@ export const ReplyEditor = (props: { replyTo?: string; onDone?: Function; }) => // Only autofocus if const autofocus = props.replyTo !== undefined; - let ref!: HTMLTextAreaElement; - createAutofocus(() => autofocus && ref); + let ref!: HTMLInputElement & HTMLTextAreaElement ; + createAutofocus(() => props.isFocus ? (autofocus && ref) : false); return
-