Message chunk loading
This commit is contained in:
@@ -286,6 +286,37 @@ export default function MessageBox({
|
|||||||
}) {
|
}) {
|
||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
|
|
||||||
|
const ref = useRef<HTMLDivElement | null>(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 = () => {
|
const sendMessage = () => {
|
||||||
if (!app.currentChannel) {
|
if (!app.currentChannel) {
|
||||||
return;
|
return;
|
||||||
@@ -346,6 +377,7 @@ export default function MessageBox({
|
|||||||
/>
|
/>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
))}
|
))}
|
||||||
|
<div ref={ref} />
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</div>
|
</div>
|
||||||
<footer className="flex gap-3 pr-5 w-full h-max">
|
<footer className="flex gap-3 pr-5 w-full h-max">
|
||||||
|
|||||||
+9
-9
@@ -66,15 +66,15 @@ export default async function auth({
|
|||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "authenticated":
|
case "authenticated":
|
||||||
ws.send(
|
// ws.send(
|
||||||
JSON.stringify({
|
// JSON.stringify({
|
||||||
type: "load_chunk",
|
// type: "load_chunk",
|
||||||
params: {
|
// params: {
|
||||||
channel_id: "general",
|
// channel_id: "general",
|
||||||
chunk_id: 0,
|
// chunk_id: 0,
|
||||||
},
|
// },
|
||||||
})
|
// })
|
||||||
);
|
// );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "message_create":
|
case "message_create":
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ export interface MessageType<T = string, P = object> {
|
|||||||
export type ClientMessage =
|
export type ClientMessage =
|
||||||
| MessageType<"send_message", { channel_id: string; contents: string }>
|
| MessageType<"send_message", { channel_id: string; contents: string }>
|
||||||
| MessageType<"delete_message", { message_id: number }>
|
| MessageType<"delete_message", { message_id: number }>
|
||||||
| MessageType<"edit_message", { message_id: number; new_contents: string }>;
|
| MessageType<"edit_message", { message_id: number; new_contents: string }>
|
||||||
|
| MessageType<"load_chunk", { channel_id: string; chunk_id: number }>;
|
||||||
|
|||||||
Reference in New Issue
Block a user