Skip to content

Commit

Permalink
Chat improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sendouc committed Sep 28, 2023
1 parent ce661ed commit 3c862d6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export function Chat({
const handleSubmit = React.useCallback(
(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();

// can't send empty messages
if (inputRef.current!.value.trim().length === 0) {
return;
}

send(inputRef.current!.value);
inputRef.current!.value = "";
},
Expand Down Expand Up @@ -255,6 +261,17 @@ export function useChat({
};
}, [rooms, onNewMessage, rootLoaderData.skalopUrl]);

React.useEffect(() => {
// ping every minute to keep connection alive
const interval = setInterval(() => {
ws.current?.send("");
}, 1000 * 60);

return () => {
clearInterval(interval);
};
}, [messages]);

const send = React.useCallback(
(contents: string) => {
invariant(currentRoom);
Expand Down

0 comments on commit 3c862d6

Please sign in to comment.