From 9aa795ae4946fb42f7ca2acbd3cf65866821c13f Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 4 Oct 2025 22:07:05 +0200 Subject: [PATCH] Direct messages with /id --- src/app/home/[id]/page.tsx | 55 ++++++++++++++++++++++++++++++++++++++ src/components/Sidebar.tsx | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/app/home/[id]/page.tsx diff --git a/src/app/home/[id]/page.tsx b/src/app/home/[id]/page.tsx new file mode 100644 index 0000000..ecdc88c --- /dev/null +++ b/src/app/home/[id]/page.tsx @@ -0,0 +1,55 @@ +"use client"; + +import { useEffect, useRef, useState } from "react"; +import MessageBox from "@/components/MessageBox"; +import AppSidebar from "@/components/Sidebar"; +import Message from "@/types/message"; +import useUser, { User } from "@/hooks/get-user"; +import { NumberMap } from "@/types/typeUtils"; +import auth, { makeAddress } from "@/lib/auth"; +import { useParams } from "next/navigation"; + +// In this testing instance we are assuming that the target's node is localhost +// To make this functional we need to add a settings feature to the api + +export default function DMs() { + const { id } = useParams<{ id: string }>(); + const numericId = id ? Number(id) : undefined; + const wsRef = useRef(null); + const [messages, setMessages] = useState([]); + const { user, loading } = useUser(); + const [userList, setUserList] = useState>({}); + + useEffect(() => { + if (!numericId || !user || loading) return; + auth(makeAddress("localhost", 7090), wsRef, () => {}, setMessages); + setUserList((prev) => { + prev[user.id] = user; + return prev; + }); + }, [id, user, loading]); + + return ( + + m.channel_id === numericId || m.from === numericId) + .toReversed()} + sendMessage={(message) => { + wsRef.current?.send( + JSON.stringify({ + type: "send_message", + params: { + channel_id: numericId, + contents: message, + }, + }) + ); + }} + /> + + ); +} diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 86e5a29..1a21f36 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -40,7 +40,7 @@ export default function AppSidebar({ }: Readonly<{ server?: Server; user: User | null; - children: React.ReactNode; + children?: React.ReactNode; }>) { const [servers, setServers] = useState<[string, string][]>([]); const [newServer, setNewServer] = useState({ name: "", ip: "" });