From aa871b32472d4ecb8c4284603ff61a04263419e6 Mon Sep 17 00:00:00 2001 From: Alejandro Gomez Date: Wed, 5 Jul 2023 21:45:23 +0200 Subject: [PATCH] feat: popout chat link --- public/icons.svg | 4 ++ src/element/icon.tsx | 9 ++++- src/element/live-chat.css | 16 ++++++-- src/element/live-chat.tsx | 80 +++++++++++++++++++++++++++------------ 4 files changed, 80 insertions(+), 29 deletions(-) diff --git a/public/icons.svg b/public/icons.svg index d8f8556..1e2f16a 100644 --- a/public/icons.svg +++ b/public/icons.svg @@ -24,5 +24,9 @@ + + + + diff --git a/src/element/icon.tsx b/src/element/icon.tsx index bf3473c..54d4a1d 100644 --- a/src/element/icon.tsx +++ b/src/element/icon.tsx @@ -12,8 +12,13 @@ export function Icon(props: Props) { const href = `/icons.svg#` + props.name; return ( - + ); -}; +} diff --git a/src/element/live-chat.css b/src/element/live-chat.css index 1481a6f..6c0f4f1 100644 --- a/src/element/live-chat.css +++ b/src/element/live-chat.css @@ -47,10 +47,20 @@ } } -.live-chat>.header { - font-weight: 600; +.live-chat > .header { + display: flex; + justify-content: space-between +} + +.live-chat .header .title { font-size: 24px; - line-height: 30px; + font-weight: 600; + line-height: normal; + margin: 0; +} + +.live-chat .header .popout-link { + color: #FFFFFF80; } .live-chat>.messages { diff --git a/src/element/live-chat.tsx b/src/element/live-chat.tsx index 0cc061b..b35ceca 100644 --- a/src/element/live-chat.tsx +++ b/src/element/live-chat.tsx @@ -1,14 +1,13 @@ import "./live-chat.css"; import { EventKind, + NostrPrefix, NostrLink, ParsedZap, parseZap, + encodeTLV, } from "@snort/system"; -import { - useEffect, - useMemo, -} from "react"; +import { useEffect, useMemo } from "react"; import { System } from "../index"; import { useLiveChatFeed } from "../hooks/live-chat"; @@ -54,11 +53,21 @@ function TopZappers({ zaps }: { zaps: ParsedZap[] }) { ); } -export function LiveChat({ link, options, height, }: { link: NostrLink, options?: LiveChatOptions, height?: number }) { +export function LiveChat({ + link, + options, + height, +}: { + link: NostrLink; + options?: LiveChatOptions; + height?: number; +}) { const feed = useLiveChatFeed(link); const login = useLogin(); useEffect(() => { - const pubkeys = [...new Set(feed.zaps.flatMap(a => [a.pubkey, findTag(a, "p")!]))]; + const pubkeys = [ + ...new Set(feed.zaps.flatMap((a) => [a.pubkey, findTag(a, "p")!])), + ]; System.ProfileLoader.TrackMetadata(pubkeys); return () => System.ProfileLoader.UntrackMetadata(pubkeys); }, [feed.zaps]); @@ -73,11 +82,30 @@ export function LiveChat({ link, options, height, }: { link: NostrLink, options? }, [feed.messages, feed.zaps]); const { data: ev } = useEventFeed(link); const streamer = getHost(ev); + const naddr = useMemo(() => { + return encodeTLV( + NostrPrefix.Address, + link.id, + undefined, + link.kind, + link.author + ); + }, [link]); return (
{(options?.showHeader ?? true) && ( -
Stream Chat
+
+

Stream Chat

+ + + +
)} {zaps.length > 0 && (
@@ -98,7 +126,9 @@ export function LiveChat({ link, options, height, }: { link: NostrLink, options? ); } case EventKind.ZapReceipt: { - const zap = zaps.find(b => b.id === a.id && b.receiver === streamer); + const zap = zaps.find( + (b) => b.id === a.id && b.receiver === streamer + ); if (zap) { return ; } @@ -126,20 +156,22 @@ function ChatZap({ zap }: { zap: ParsedZap }) { return null; } - return
-
- - - zapped - {formatSats(zap.amount)} - sats + return ( +
+
+ + + zapped + {formatSats(zap.amount)} + sats +
+ {zap.content &&
{zap.content}
}
- {zap.content &&
{zap.content}
} -
-} \ No newline at end of file + ); +}