From a1605e31d5d81b90356362483ca522e999f75584 Mon Sep 17 00:00:00 2001 From: Kieran Date: Sat, 15 Jul 2023 16:27:44 +0100 Subject: [PATCH] bugfix since for live chat feed --- src/element/goal.tsx | 2 +- src/hooks/live-chat.tsx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/element/goal.tsx b/src/element/goal.tsx index b33b380..d9bd6c5 100644 --- a/src/element/goal.tsx +++ b/src/element/goal.tsx @@ -32,7 +32,7 @@ export function Goal({ .reduce((acc, z) => acc + z.amount, 0); }, [zaps]); - const progress = (soFar / goalAmount) * 100; + const progress = Math.max(0, Math.min(100, (soFar / goalAmount) * 100)); const isFinished = progress >= 100; const previousValue = usePreviousValue(isFinished); diff --git a/src/hooks/live-chat.tsx b/src/hooks/live-chat.tsx index 96ab990..f18a64c 100644 --- a/src/hooks/live-chat.tsx +++ b/src/hooks/live-chat.tsx @@ -11,20 +11,23 @@ import { useMemo } from "react"; import { LIVE_STREAM_CHAT } from "const"; export function useLiveChatFeed(link: NostrLink, eZaps?: Array) { + const since = useMemo(() => + unixNow() - (60 * 60 * 24 * 7), // 7-days of zaps + [link.id]); const sub = useMemo(() => { const rb = new RequestBuilder(`live:${link.id}:${link.author}`); rb.withOptions({ leaveOpen: true, }); - const zapsSince = unixNow() - (60 * 60 * 24 * 7); // 7-days of zaps + const aTag = `${link.kind}:${link.author}:${link.id}`; rb.withFilter().kinds([LIVE_STREAM_CHAT]).tag("a", [aTag]).limit(100); - rb.withFilter().kinds([EventKind.ZapReceipt]).tag("a", [aTag]).since(zapsSince); + rb.withFilter().kinds([EventKind.ZapReceipt]).tag("a", [aTag]).since(since); if (eZaps) { rb.withFilter().kinds([EventKind.ZapReceipt]).tag("e", eZaps); } return rb; - }, [link, eZaps]); + }, [link.id, since, eZaps]); const feed = useRequestBuilder(System, FlatNoteStore, sub);