diff --git a/packages/app/src/Element/LiveChat.css b/packages/app/src/Element/LiveChat.css new file mode 100644 index 00000000..5423adf5 --- /dev/null +++ b/packages/app/src/Element/LiveChat.css @@ -0,0 +1,11 @@ +.live-chat { + height: calc(100vh - 73px); + display: flex; + flex-direction: column; +} + +.live-chat > div:nth-child(1) { + flex-grow: 1; + display: flex; + flex-direction: column-reverse; +} diff --git a/packages/app/src/Element/LiveChat.tsx b/packages/app/src/Element/LiveChat.tsx new file mode 100644 index 00000000..306dc9cd --- /dev/null +++ b/packages/app/src/Element/LiveChat.tsx @@ -0,0 +1,63 @@ +import "./LiveChat.css"; +import { NostrLink, TaggedRawEvent } from "@snort/system"; +import { useUserProfile } from "@snort/system-react"; +import { useState } from "react"; +import Textarea from "./Textarea"; +import { useLiveChatFeed } from "Feed/LiveChatFeed"; +import useEventPublisher from "Feed/EventPublisher"; +import { System } from "index"; +import { getDisplayName } from "Element/ProfileImage"; + +export function LiveChat({ ev, link }: { ev: TaggedRawEvent; link: NostrLink }) { + const [chat, setChat] = useState(""); + const messages = useLiveChatFeed(link); + const pub = useEventPublisher(); + + async function sendChatMessage() { + const reply = await pub?.note(chat, eb => { + return eb.tag(["a", `${link.kind}:${link.author}:${link.id}`]); + }); + if (reply) { + console.debug(reply); + System.BroadcastEvent(reply); + } + setChat(""); + } + return ( +
+
+ {[...(messages.data ?? [])] + .sort((a, b) => b.created_at - a.created_at) + .map(a => ( + + ))} +
+
+