From 12ff17f79484da823efadadc40e92606d0dc1ae6 Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Thu, 9 May 2024 16:12:50 -0500 Subject: [PATCH] fix some things --- src/app/chat/page.tsx | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/app/chat/page.tsx b/src/app/chat/page.tsx index 97c68cb..c3505b1 100644 --- a/src/app/chat/page.tsx +++ b/src/app/chat/page.tsx @@ -168,8 +168,8 @@ export default function Home() { setConnected(true); if (token != null) socket.emit('SIG_CHAT_JOIN', { token }, joinChatRes); - - socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes); + else + socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes); setTextBox(
@@ -267,17 +267,6 @@ export default function Home() { removeUser(userId); }); - const prevscrtop = useRef(0); - useEffect(() => { - if ( - chatPaneRef.current != null - && chatPaneRef.current.scrollTop >= prevscrtop.current - ) { - chatPaneRef.current.scrollTop = chatPaneRef.current.scrollHeight; - prevscrtop.current = chatPaneRef.current.scrollTop; - } - }, [messages]) - // message stuff function addMessage(messagesdata:MessageType) { @@ -335,6 +324,7 @@ export default function Home() { setError(type, spec, data); } else { setWhoAmI(data); + socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes); } } @@ -352,6 +342,8 @@ export default function Home() { } } + const prevscrtop = useRef(0); + function chgchannelChatRes({ type, spec, data }:Res) { unsetError(); if (type.includes("ERR")) { @@ -366,6 +358,7 @@ export default function Home() { let [ messageLayout, setMessageLayout ] = useState(); useEffect(() => { + if (messages.length > 0) setMessageLayout(messages.map(Message.current)); else if (whoami.admin || channels.find(x => x.name == channel)?.writable) @@ -390,6 +383,16 @@ export default function Home() { ); }, [affectedByUpdate, messages]); + useEffect(() => { + if ( + chatPaneRef.current != null + && chatPaneRef.current.scrollTop >= prevscrtop.current - 100 + ) { + chatPaneRef.current.scrollTop = chatPaneRef.current.scrollHeight; + prevscrtop.current = chatPaneRef.current.scrollTop; + } + }, [messageLayout]) + return (