From 67acee4b72881bfe96d63ca6850bf3867d3b1204 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Tue, 23 Dec 2025 18:15:27 +0100 Subject: [PATCH] Fixed a few bugs --- src/app/chat/[id]/page.tsx | 41 ++++++++++-------- src/components/app/AppLayout.tsx | 61 +++++++++++++++------------ src/components/channel/MessageBox.tsx | 22 +++++++--- 3 files changed, 72 insertions(+), 52 deletions(-) diff --git a/src/app/chat/[id]/page.tsx b/src/app/chat/[id]/page.tsx index 351f38f..7053bb2 100644 --- a/src/app/chat/[id]/page.tsx +++ b/src/app/chat/[id]/page.tsx @@ -9,6 +9,7 @@ import auth from "@/lib/auth"; import useAsync from "@/hooks/use-async"; import { Button } from "@/components/ui/button"; import useIndicators from "@/hooks/use-indicators"; +import { useEffectOnceWhenReady } from "@/hooks/use-once"; export default function DMs() { const { id } = useParams<{ id: string }>(); @@ -18,25 +19,29 @@ export default function DMs() { const router = useRouter(); const { indicators, addIndicator } = useIndicators(); - useEffect(() => { - async function connectTargetNode() { - if (!target) return; - auth({ - id: target.node_address, - wsRef: targetNode, - messageStore: app.privateMessages, - onIndicator: addIndicator, + useEffectOnceWhenReady( + () => { + async function connectTargetNode() { + if (!target) return; + auth({ + id: target.node_address, + wsRef: targetNode, + messageStore: app.privateMessages, + onIndicator: addIndicator, + }); + } + + connectTargetNode(); + + app.setCurrentChannel({ + id: id, + name: target?.display_name || id, + kind: "text", }); - } - - connectTargetNode(); - - app.setCurrentChannel({ - id: id, - name: target?.display_name || id, - kind: "text", - }); - }, [target]); + }, + [target], + [(v) => v] + ); return loading || target ? ( diff --git a/src/components/app/AppLayout.tsx b/src/components/app/AppLayout.tsx index 77de524..164250e 100644 --- a/src/components/app/AppLayout.tsx +++ b/src/components/app/AppLayout.tsx @@ -13,6 +13,7 @@ import SidebarServers from "./SidebarServers"; import SidebarDMs from "./SidebarDMs"; import SidebarChannels from "./SidebarChannels"; import DMItem from "./DMItem"; +import { useEffectOnceWhenReady } from "@/hooks/use-once"; export default function AppLayout({ children, @@ -28,36 +29,42 @@ export default function AppLayout({ const router = useRouter(); const isMobile = useIsMobile(); - useEffect(() => { - if (!app.profile?.node_address) return; + useEffectOnceWhenReady( + () => { + if (!app.profile?.node_address) return; - auth({ - id: app.profile.node_address, - wsRef: app.node, - onNewMessage: (m) => { - if (m.from !== chatWith && m.from !== app.profile?.id) - toast( - `New message from ${app.profiles[m.from]?.display_name || m.from}`, - { - description: m.contents.slice(0, 80), - action: { - label: "View", - onClick: () => router.push(`/chat/${m.from}`), - }, - position: "top-right", - } - ); + auth({ + id: app.profile.node_address, + wsRef: app.node, + onNewMessage: (m) => { + if (m.from !== chatWith && m.from !== app.profile?.id) + toast( + `New message from ${ + app.profiles[m.from]?.display_name || m.from + }`, + { + description: m.contents.slice(0, 80), + action: { + label: "View", + onClick: () => router.push(`/chat/${m.from}`), + }, + position: "top-right", + } + ); - if (onNewMessage) onNewMessage(m); - }, - messageStore: app.privateMessages, - }); + if (onNewMessage) onNewMessage(m); + }, + messageStore: app.privateMessages, + }); - app.setProfiles((prev) => { - if (app.profile) prev[app.profile.id] = app.profile; - return prev; - }); - }, [chatWith, app.profile]); + app.setProfiles((prev) => { + if (app.profile) prev[app.profile.id] = app.profile; + return prev; + }); + }, + [chatWith, app.profile], + [undefined, undefined] + ); return (
diff --git a/src/components/channel/MessageBox.tsx b/src/components/channel/MessageBox.tsx index 22c438f..110608c 100644 --- a/src/components/channel/MessageBox.tsx +++ b/src/components/channel/MessageBox.tsx @@ -27,6 +27,7 @@ import { } from "@/components/ui/context-menu"; import { ClientMessage, IndicatorContext } from "@/types/protocol"; import { AnimatePresence, motion } from "framer-motion"; +import AsyncValue from "../AsyncValue"; function MessageContainer({ message, @@ -429,13 +430,20 @@ export default function MessageBox({ exit={{ opacity: 0, y: -10 }} transition={{ duration: 0.3 }} > - {indicators - .map( - (indicator) => - app.profiles[indicator.indicator.params.user_id] - ?.display_name ?? null - ) - .join(", ")} + + await Promise.all( + indicators.map((indicator) => + app.getUserById(indicator.indicator.params.user_id) + ) + ) + } + render={({ value: indicators }) => + indicators + ?.map((indicator) => indicator?.display_name) + .join(", ") + } + /> {indicators.length > 0 && " is typing"} )}