From 1c6ff7f729d0c9ce6a0d03584b9fc31aab671ae7 Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 5 Dec 2023 12:58:50 +0000 Subject: [PATCH] chore: formatting --- src/element/alby-button.tsx | 4 +- src/element/chat-message.tsx | 16 +- src/element/summary-chart.tsx | 388 +++++++++++++++++----------------- src/lang.json | 9 + src/pages/layout.tsx | 33 +-- src/translations/en.json | 3 + 6 files changed, 235 insertions(+), 218 deletions(-) diff --git a/src/element/alby-button.tsx b/src/element/alby-button.tsx index 7977db4..167338a 100644 --- a/src/element/alby-button.tsx +++ b/src/element/alby-button.tsx @@ -1,5 +1,5 @@ import { Button as AlbyZapsButton } from "@getalby/bitcoin-connect-react"; export default function AlbyButton() { - return -} \ No newline at end of file + return ; +} diff --git a/src/element/chat-message.tsx b/src/element/chat-message.tsx index 0f53e2d..8eb9c1f 100644 --- a/src/element/chat-message.tsx +++ b/src/element/chat-message.tsx @@ -176,15 +176,15 @@ export function ChatMessage({ style={ isTablet ? { - display: showZapDialog || isHovering ? "flex" : "none", - } + display: showZapDialog || isHovering ? "flex" : "none", + } : { - position: "fixed", - top: topOffset ? topOffset - 12 : 0, - left: leftOffset ? leftOffset - 32 : 0, - opacity: showZapDialog || isHovering ? 1 : 0, - pointerEvents: showZapDialog || isHovering ? "auto" : "none", - } + position: "fixed", + top: topOffset ? topOffset - 12 : 0, + left: leftOffset ? leftOffset - 32 : 0, + opacity: showZapDialog || isHovering ? 1 : 0, + pointerEvents: showZapDialog || isHovering ? "auto" : "none", + } }> {zapTarget && ( { - return Object.entries( - data.messages.reduce((acc, v) => { - acc[v.pubkey] ??= []; - acc[v.pubkey].push(v); - return acc; - }, {} as Record>) - ) - .map(([k, v]) => ({ - pubkey: k, - messages: v, - })) - .sort((a, b) => (a.messages.length > b.messages.length ? -1 : 1)); - }, [data.messages]); + const chatSummary = useMemo(() => { + return Object.entries( + data.messages.reduce((acc, v) => { + acc[v.pubkey] ??= []; + acc[v.pubkey].push(v); + return acc; + }, {} as Record>) + ) + .map(([k, v]) => ({ + pubkey: k, + messages: v, + })) + .sort((a, b) => (a.messages.length > b.messages.length ? -1 : 1)); + }, [data.messages]); - const zapsSummary = useMemo(() => { - return Object.entries( - reactions.zaps.reduce((acc, v) => { - if (!v.sender) return acc; - acc[v.sender] ??= []; - acc[v.sender].push(v); - return acc; - }, {} as Record>) - ) - .map(([k, v]) => ({ - pubkey: k, - zaps: v, - total: v.reduce((acc, vv) => acc + vv.amount, 0), - })) - .sort((a, b) => (a.total > b.total ? -1 : 1)); - }, [reactions.zaps]); + const zapsSummary = useMemo(() => { + return Object.entries( + reactions.zaps.reduce((acc, v) => { + if (!v.sender) return acc; + acc[v.sender] ??= []; + acc[v.sender].push(v); + return acc; + }, {} as Record>) + ) + .map(([k, v]) => ({ + pubkey: k, + zaps: v, + total: v.reduce((acc, vv) => acc + vv.amount, 0), + })) + .sort((a, b) => (a.total > b.total ? -1 : 1)); + }, [reactions.zaps]); - const title = findTag(ev, "title"); - const summary = findTag(ev, "summary"); - const status = findTag(ev, "status"); - const starts = findTag(ev, "starts"); + const title = findTag(ev, "title"); + const summary = findTag(ev, "summary"); + const status = findTag(ev, "status"); + const starts = findTag(ev, "starts"); - const Day = 60 * 60 * 24; - const startTime = starts ? Number(starts) : ev?.created_at ?? unixNow(); - const endTime = status === StreamState.Live ? unixNow() : ev?.created_at ?? unixNow(); + const Day = 60 * 60 * 24; + const startTime = starts ? Number(starts) : ev?.created_at ?? unixNow(); + const endTime = status === StreamState.Live ? unixNow() : ev?.created_at ?? unixNow(); - const streamLength = endTime - startTime; - const windowSize = streamLength > Day ? Day : 60 * 10; + const streamLength = endTime - startTime; + const windowSize = streamLength > Day ? Day : 60 * 10; - const stats = useMemo(() => { - let min = unixNow(); - let max = 0; - const ret = [...data.messages, ...data.reactions] - .sort((a, b) => (a.created_at > b.created_at ? -1 : 1)) - .reduce((acc, v) => { - const time = Math.floor(v.created_at - (v.created_at % windowSize)); - if (time < min) { - min = time; - } - if (time > max) { - max = time; - } - const key = time.toString(); - acc[key] ??= { - time, - zaps: 0, - messages: 0, - reactions: 0, - }; - - if (v.kind === LIVE_STREAM_CHAT) { - acc[key].messages++; - } else if (v.kind === EventKind.ZapReceipt) { - acc[key].zaps++; - } else if (v.kind === EventKind.Reaction) { - acc[key].reactions++; - } else { - console.debug("Uncounted stat", v); - } - return acc; - }, {} as Record); - - // fill empty time slots - for (let x = min; x < max; x += windowSize) { - ret[x.toString()] ??= { - time: x, - zaps: 0, - messages: 0, - reactions: 0, - }; + const stats = useMemo(() => { + let min = unixNow(); + let max = 0; + const ret = [...data.messages, ...data.reactions] + .sort((a, b) => (a.created_at > b.created_at ? -1 : 1)) + .reduce((acc, v) => { + const time = Math.floor(v.created_at - (v.created_at % windowSize)); + if (time < min) { + min = time; } - return ret; - }, [data]); + if (time > max) { + max = time; + } + const key = time.toString(); + acc[key] ??= { + time, + zaps: 0, + messages: 0, + reactions: 0, + }; - return ( -
-

{title}

-

{summary}

-
- - {streamLength > 0 && ( - , - }} - /> - )} -
-

- -

- - - - - - - - { - if (active && payload && payload.length) { - const data = payload[0].payload as StatSlot; - return ( -
-
- -
-
-
- -
-
{data.messages}
-
-
-
- -
-
{data.reactions}
-
-
-
- -
-
{data.zaps}
-
-
- ); - } - return null; - }} - /> -
-
+ if (v.kind === LIVE_STREAM_CHAT) { + acc[key].messages++; + } else if (v.kind === EventKind.ZapReceipt) { + acc[key].zaps++; + } else if (v.kind === EventKind.Reaction) { + acc[key].reactions++; + } else { + console.debug("Uncounted stat", v); + } + return acc; + }, {} as Record); -
-
-

- -

-
- {chatSummary.slice(0, 5).map(a => ( -
- -
- , - }} - /> -
-
- ))} + // fill empty time slots + for (let x = min; x < max; x += windowSize) { + ret[x.toString()] ??= { + time: x, + zaps: 0, + messages: 0, + reactions: 0, + }; + } + return ret; + }, [data]); + + return ( +
+

{title}

+

{summary}

+
+ + {streamLength > 0 && ( + , + }} + /> + )} +
+

+ +

+ + + + + + + + { + if (active && payload && payload.length) { + const data = payload[0].payload as StatSlot; + return ( +
+
+
-
-
-

- -

-
- {zapsSummary.slice(0, 5).map(a => ( -
- -
- -
-
- ))} +
+
+ +
+
{data.messages}
+
+
+ +
+
{data.reactions}
+
+
+
+ +
+
{data.zaps}
+
+
+ ); + } + return null; + }} + /> + + + +
+
+

+ +

+
+ {chatSummary.slice(0, 5).map(a => ( +
+ +
+ , + }} + />
-
+
+ ))} +
- ); +
+

+ +

+
+ {zapsSummary.slice(0, 5).map(a => ( +
+ +
+ +
+
+ ))} +
+
+
+
+ ); } diff --git a/src/lang.json b/src/lang.json index 93a52f5..94eeb3e 100644 --- a/src/lang.json +++ b/src/lang.json @@ -140,6 +140,9 @@ "GGaJMU": { "defaultMessage": "Top Chatters" }, + "Gmiwnd": { + "defaultMessage": "Refresh the page to use the latest version" + }, "Gq6x9o": { "defaultMessage": "Cover Image" }, @@ -227,6 +230,9 @@ "Qe1MJu": { "defaultMessage": "{name} with {amount}" }, + "RJ2VxG": { + "defaultMessage": "A new version has been detected" + }, "RJOmzk": { "defaultMessage": "I have read and agree with {provider}''s {terms}." }, @@ -381,6 +387,9 @@ "r2Jjms": { "defaultMessage": "Log In" }, + "rELDbB": { + "defaultMessage": "Refresh" + }, "rWBFZA": { "defaultMessage": "Sexually explicit material ahead!" }, diff --git a/src/pages/layout.tsx b/src/pages/layout.tsx index 66ea0e6..08e9b31 100644 --- a/src/pages/layout.tsx +++ b/src/pages/layout.tsx @@ -145,20 +145,25 @@ export function LayoutPage() { } function NewVersionBanner() { - const newVersion = useSyncExternalStore(c => NewVersion.hook(c), () => NewVersion.snapshot()); + const newVersion = useSyncExternalStore( + c => NewVersion.hook(c), + () => NewVersion.snapshot() + ); if (!newVersion) return; - return
-
-

- -

-

- -

+ return ( +
+
+

+ +

+

+ +

+
+ window.location.reload()} className="btn"> + +
- window.location.reload()} className="btn"> - - -
-} \ No newline at end of file + ); +} diff --git a/src/translations/en.json b/src/translations/en.json index 4c8a0c2..4219ecd 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -46,6 +46,7 @@ "Fodi9+": "Get paid by viewers", "G/yZLu": "Remove", "GGaJMU": "Top Chatters", + "Gmiwnd": "Refresh the page to use the latest version", "Gq6x9o": "Cover Image", "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", @@ -75,6 +76,7 @@ "QRRCp0": "Stream URL", "QceMQZ": "Goal: {amount}", "Qe1MJu": "{name} with {amount}", + "RJ2VxG": "A new version has been detected", "RJOmzk": "I have read and agree with {provider}''s {terms}.", "RXQdxR": "Please login to write messages!", "RrCui3": "Summary", @@ -126,6 +128,7 @@ "oZrFyI": "Stream type should be HLS", "pO/lPX": "Scheduled for {date}", "r2Jjms": "Log In", + "rELDbB": "Refresh", "rWBFZA": "Sexually explicit material ahead!", "rbrahO": "Close", "rfC1Zq": "Save card",