fix some things
This commit is contained in:
parent
db91e054f3
commit
12ff17f794
1 changed files with 16 additions and 13 deletions
|
@ -168,8 +168,8 @@ 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}>
|
||||||
<textarea rows={2} className={styles.textBoxInput} ref={chatInput}></textarea>
|
<textarea rows={2} className={styles.textBoxInput} ref={chatInput}></textarea>
|
||||||
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue