From f780a8eb3ee6b6eeb0144436e9e3304e5b11c662 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Mon, 22 Dec 2025 20:32:52 +0100 Subject: [PATCH] Message chunk loading --- src/components/channel/MessageBox.tsx | 32 +++++++++++++++++++++++++++ src/lib/auth.ts | 18 +++++++-------- src/types/protocol.ts | 3 ++- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/components/channel/MessageBox.tsx b/src/components/channel/MessageBox.tsx index 1ccbb59..26999d0 100644 --- a/src/components/channel/MessageBox.tsx +++ b/src/components/channel/MessageBox.tsx @@ -286,6 +286,37 @@ export default function MessageBox({ }) { const [text, setText] = useState(""); + const ref = useRef(null); + const chunkRef = useRef(0); + + useEffect(() => { + if (!ref.current) return; + + const observer = new IntersectionObserver( + ([entry]) => { + if (entry.isIntersecting) { + console.log("Element is in view!"); + if (!app.currentChannel) return; + sendRequest({ + type: "load_chunk", + params: { + channel_id: app.currentChannel.id, + chunk_id: chunkRef.current, + }, + }); + chunkRef.current += 1; + } + }, + { + threshold: 0.5, + } + ); + + observer.observe(ref.current); + + return () => observer.disconnect(); + }, []); + const sendMessage = () => { if (!app.currentChannel) { return; @@ -346,6 +377,7 @@ export default function MessageBox({ /> ))} +