From 2a4579cf89cf1bb7b8d5c471d90623872334497d Mon Sep 17 00:00:00 2001 From: Leo dev Date: Tue, 23 Dec 2025 12:44:13 +0100 Subject: [PATCH] Typing indicator send --- src/components/channel/MessageBox.tsx | 44 +++++++++++++++++++++++++-- src/types/protocol.ts | 3 +- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/components/channel/MessageBox.tsx b/src/components/channel/MessageBox.tsx index 7ade402..d22cf06 100644 --- a/src/components/channel/MessageBox.tsx +++ b/src/components/channel/MessageBox.tsx @@ -206,17 +206,41 @@ function MessageInput({ text, setText, onEnter, + onTyping, }: { text: string; setText: SetState; onEnter: () => void; + onTyping?: () => void; }) { + const TYPING_INTERVAL = 2000; const inputRef = useRef(null); + const lastTypingSent = useRef(0); + const stopTypingTimeout = useRef(null); useEffect(() => { inputRef.current?.focus(); }, [inputRef]); + useEffect(() => { + if (!onTyping || !text) return; + + const now = Date.now(); + + if (now - lastTypingSent.current > TYPING_INTERVAL) { + lastTypingSent.current = now; + onTyping(); + } + + if (stopTypingTimeout.current) { + clearTimeout(stopTypingTimeout.current); + } + + stopTypingTimeout.current = setTimeout(() => { + lastTypingSent.current = 0; + }, TYPING_INTERVAL); + }, [text]); + return text.includes("\n") ? (