From c708870e04bb0b829d80c818d4c7dbe6061bd96a Mon Sep 17 00:00:00 2001 From: verbiricha Date: Tue, 1 Aug 2023 17:11:40 +0200 Subject: [PATCH] fix: don't crash when no follows --- src/element/new-stream.css | 2 +- src/element/nostr-provider-dialog.tsx | 82 +++++++++++++++++---------- src/pages/root.tsx | 7 ++- src/providers/index.ts | 12 ++-- src/providers/owncast.ts | 2 +- 5 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/element/new-stream.css b/src/element/new-stream.css index 53bf2f2..db2c63d 100644 --- a/src/element/new-stream.css +++ b/src/element/new-stream.css @@ -53,4 +53,4 @@ .new-stream .tos-link:hover { text-decoration: underline; -} \ No newline at end of file +} diff --git a/src/element/nostr-provider-dialog.tsx b/src/element/nostr-provider-dialog.tsx index 9364462..ef8dd9a 100644 --- a/src/element/nostr-provider-dialog.tsx +++ b/src/element/nostr-provider-dialog.tsx @@ -88,26 +88,41 @@ export function NostrProviderDialog({ function tosInput() { if (!info) return; - return <> -
-
- setTos(e.target.checked)} /> -

- I have read and agree with {info.name}'s window.open(info.tosLink, "popup", "width=400,height=800")}>terms and conditions. -

+ return ( + <> +
+
+ setTos(e.target.checked)} + /> +

+ I have read and agree with {info.name}'s{" "} + + window.open(info.tosLink, "popup", "width=400,height=800") + } + > + terms and conditions + + . +

+
-
-
- - Continue - -
- +
+ + Continue + +
+ + ); } return ( @@ -167,26 +182,33 @@ export function NostrProviderDialog({ ))}
- {info.tosAccepted === false ? tosInput() : + {info.tosAccepted === false ? ( + tosInput() + ) : ( { provider.updateStreamInfo(ex); others.onFinish?.(ex); }} - ev={{ - tags: [ - ["title", info.streamInfo?.title ?? ""], - ["summary", info.streamInfo?.summary ?? ""], - ["image", info.streamInfo?.image ?? ""], - ...(info.streamInfo?.content_warning ? [["content-warning", info.streamInfo?.content_warning]] : []), - ...(info.streamInfo?.tags?.map(a => ["t", a]) ?? []) - ] - } as NostrEvent} + ev={ + { + tags: [ + ["title", info.streamInfo?.title ?? ""], + ["summary", info.streamInfo?.summary ?? ""], + ["image", info.streamInfo?.image ?? ""], + ...(info.streamInfo?.content_warning + ? [["content-warning", info.streamInfo?.content_warning]] + : []), + ...(info.streamInfo?.tags?.map((a) => ["t", a]) ?? []), + ], + } as NostrEvent + } options={{ canSetStream: false, canSetStatus: false, }} - />} + /> + )} ); } diff --git a/src/pages/root.tsx b/src/pages/root.tsx index c6c7928..090dfc2 100644 --- a/src/pages/root.tsx +++ b/src/pages/root.tsx @@ -12,13 +12,14 @@ export function RootPage() { const { live, planned, ended } = useStreamsFeed(); const mutedHosts = new Set(getTagValues(login?.muted.tags ?? [], "p")); + const tags = login?.follows.tags ?? []; const followsHost = useCallback( (ev: NostrEvent) => { - return login?.follows.tags.find((t) => t.at(1) === getHost(ev)); + return tags.find((t) => t.at(1) === getHost(ev)); }, - [login?.follows] + [tags] ); - const hashtags = getTagValues(login?.follows.tags ?? [], "t"); + const hashtags = getTagValues(tags, "t"); const following = live.filter(followsHost); const liveNow = live.filter((e) => !following.includes(e)); const hasFollowingLive = following.length > 0; diff --git a/src/providers/index.ts b/src/providers/index.ts index 5fc85ad..a6efd88 100644 --- a/src/providers/index.ts +++ b/src/providers/index.ts @@ -53,7 +53,7 @@ export interface StreamProviderInfo { balance?: number; endpoints: Array; tosAccepted?: boolean; - tosLink?: string + tosLink?: string; } export interface StreamProviderEndpoint { @@ -66,11 +66,11 @@ export interface StreamProviderEndpoint { } export interface StreamProviderStreamInfo { - title: string - summary: string - image: string - tags: Array - content_warning: string + title: string; + summary: string; + image: string; + tags: Array; + content_warning: string; } export class ProviderStore extends ExternalStore> { diff --git a/src/providers/owncast.ts b/src/providers/owncast.ts index f2da89d..b828a65 100644 --- a/src/providers/owncast.ts +++ b/src/providers/owncast.ts @@ -51,7 +51,7 @@ export class OwncastProvider implements StreamProvider { acceptTos(): Promise { throw new Error("Method not implemented."); } - + async #getJson( method: "GET" | "POST", path: string,