Added backlog to chat

This commit is contained in:
2021-03-18 02:40:22 +11:00
parent 13e3ce6db8
commit 1c3d24575e
+5
View File
@@ -20,6 +20,7 @@ const PopupChat = props => {
useEffect(() => { useEffect(() => {
socket.on('message', message => pushChatlog(message)); socket.on('message', message => pushChatlog(message));
socket.on('backlog', messages => setChatlog(prev => [...prev, ...messages]));
socket.on('disconnect', reason => pushChatlog({ emphasis: true, text: 'Lost connection' })); socket.on('disconnect', reason => pushChatlog({ emphasis: true, text: 'Lost connection' }));
}, []); }, []);
@@ -66,6 +67,10 @@ const handleClose = setOpen => {
}; };
const handleSend = (inputRef, pushChatlog, username, accessToken) => { const handleSend = (inputRef, pushChatlog, username, accessToken) => {
if (inputRef.current.value == '') {
return;
}
socket.emit('message', { socket.emit('message', {
accessToken, accessToken,
text: inputRef.current.value text: inputRef.current.value