fix: don't crash when no follows

This commit is contained in:
2023-08-01 17:11:40 +02:00
parent 508abaad1f
commit c708870e04
5 changed files with 64 additions and 41 deletions

View File

@ -88,12 +88,26 @@ export function NostrProviderDialog({
function tosInput() { function tosInput() {
if (!info) return; if (!info) return;
return <> return (
<>
<div> <div>
<div className="flex g12"> <div className="flex g12">
<input type="checkbox" checked={tos} onChange={e => setTos(e.target.checked)} /> <input
type="checkbox"
checked={tos}
onChange={(e) => setTos(e.target.checked)}
/>
<p> <p>
I have read and agree with {info.name}'s <span className="tos-link" onClick={() => window.open(info.tosLink, "popup", "width=400,height=800")}>terms and conditions</span>. I have read and agree with {info.name}'s{" "}
<span
className="tos-link"
onClick={() =>
window.open(info.tosLink, "popup", "width=400,height=800")
}
>
terms and conditions
</span>
.
</p> </p>
</div> </div>
</div> </div>
@ -108,6 +122,7 @@ export function NostrProviderDialog({
</AsyncButton> </AsyncButton>
</div> </div>
</> </>
);
} }
return ( return (
@ -167,26 +182,33 @@ export function NostrProviderDialog({
))} ))}
</div> </div>
</div> </div>
{info.tosAccepted === false ? tosInput() : {info.tosAccepted === false ? (
tosInput()
) : (
<StreamEditor <StreamEditor
onFinish={(ex) => { onFinish={(ex) => {
provider.updateStreamInfo(ex); provider.updateStreamInfo(ex);
others.onFinish?.(ex); others.onFinish?.(ex);
}} }}
ev={{ ev={
{
tags: [ tags: [
["title", info.streamInfo?.title ?? ""], ["title", info.streamInfo?.title ?? ""],
["summary", info.streamInfo?.summary ?? ""], ["summary", info.streamInfo?.summary ?? ""],
["image", info.streamInfo?.image ?? ""], ["image", info.streamInfo?.image ?? ""],
...(info.streamInfo?.content_warning ? [["content-warning", info.streamInfo?.content_warning]] : []), ...(info.streamInfo?.content_warning
...(info.streamInfo?.tags?.map(a => ["t", a]) ?? []) ? [["content-warning", info.streamInfo?.content_warning]]
] : []),
} as NostrEvent} ...(info.streamInfo?.tags?.map((a) => ["t", a]) ?? []),
],
} as NostrEvent
}
options={{ options={{
canSetStream: false, canSetStream: false,
canSetStatus: false, canSetStatus: false,
}} }}
/>} />
)}
</> </>
); );
} }

View File

@ -12,13 +12,14 @@ export function RootPage() {
const { live, planned, ended } = useStreamsFeed(); const { live, planned, ended } = useStreamsFeed();
const mutedHosts = new Set(getTagValues(login?.muted.tags ?? [], "p")); const mutedHosts = new Set(getTagValues(login?.muted.tags ?? [], "p"));
const tags = login?.follows.tags ?? [];
const followsHost = useCallback( const followsHost = useCallback(
(ev: NostrEvent) => { (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 following = live.filter(followsHost);
const liveNow = live.filter((e) => !following.includes(e)); const liveNow = live.filter((e) => !following.includes(e));
const hasFollowingLive = following.length > 0; const hasFollowingLive = following.length > 0;

View File

@ -53,7 +53,7 @@ export interface StreamProviderInfo {
balance?: number; balance?: number;
endpoints: Array<StreamProviderEndpoint>; endpoints: Array<StreamProviderEndpoint>;
tosAccepted?: boolean; tosAccepted?: boolean;
tosLink?: string tosLink?: string;
} }
export interface StreamProviderEndpoint { export interface StreamProviderEndpoint {
@ -66,11 +66,11 @@ export interface StreamProviderEndpoint {
} }
export interface StreamProviderStreamInfo { export interface StreamProviderStreamInfo {
title: string title: string;
summary: string summary: string;
image: string image: string;
tags: Array<string> tags: Array<string>;
content_warning: string content_warning: string;
} }
export class ProviderStore extends ExternalStore<Array<StreamProvider>> { export class ProviderStore extends ExternalStore<Array<StreamProvider>> {