fix some things

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

View file

@ -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(<div className={styles.textBox}>
<textarea rows={2} className={styles.textBoxInput} ref={chatInput}></textarea>
@ -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<React.ReactNode>();
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 (
<ChatLayout
title="Chat"