fix some things

This commit is contained in:
MeowcaTheoRange 2024-05-09 16:12:50 -05:00
parent db91e054f3
commit 12ff17f794

View file

@ -168,7 +168,7 @@ export default function Home() {
setConnected(true); setConnected(true);
if (token != null) if (token != null)
socket.emit('SIG_CHAT_JOIN', { token }, joinChatRes); socket.emit('SIG_CHAT_JOIN', { token }, joinChatRes);
else
socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes); socket.emit('SIG_CHAT_CHANNELS', {}, channelsChatRes);
setTextBox(<div className={styles.textBox}> setTextBox(<div className={styles.textBox}>
@ -267,17 +267,6 @@ export default function Home() {
removeUser(userId); 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 // message stuff
function addMessage(messagesdata:MessageType) { function addMessage(messagesdata:MessageType) {
@ -335,6 +324,7 @@ export default function Home() {
setError(type, spec, data); setError(type, spec, data);
} else { } else {
setWhoAmI(data); 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) { function chgchannelChatRes({ type, spec, data }:Res) {
unsetError(); unsetError();
if (type.includes("ERR")) { if (type.includes("ERR")) {
@ -366,6 +358,7 @@ export default function Home() {
let [ messageLayout, setMessageLayout ] = useState<React.ReactNode>(); let [ messageLayout, setMessageLayout ] = useState<React.ReactNode>();
useEffect(() => { useEffect(() => {
if (messages.length > 0) if (messages.length > 0)
setMessageLayout(messages.map(Message.current)); setMessageLayout(messages.map(Message.current));
else if (whoami.admin || channels.find(x => x.name == channel)?.writable) else if (whoami.admin || channels.find(x => x.name == channel)?.writable)
@ -390,6 +383,16 @@ export default function Home() {
</>); </>);
}, [affectedByUpdate, messages]); }, [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 ( return (
<ChatLayout <ChatLayout
title="Chat" title="Chat"