From 3c862d6e81f3c48644041cbd11fe35b787877ede Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 28 Sep 2023 21:25:01 +0300 Subject: [PATCH] Chat improvements --- app/components/Chat.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/components/Chat.tsx b/app/components/Chat.tsx index aa00beb170..b6b6afeb85 100644 --- a/app/components/Chat.tsx +++ b/app/components/Chat.tsx @@ -57,6 +57,12 @@ export function Chat({ const handleSubmit = React.useCallback( (e: React.FormEvent) => { e.preventDefault(); + + // can't send empty messages + if (inputRef.current!.value.trim().length === 0) { + return; + } + send(inputRef.current!.value); inputRef.current!.value = ""; }, @@ -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);