From f074daa47b1ab84e026f37e610fda37bf3e54a7d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 8 May 2024 11:15:45 +0530 Subject: [PATCH] chore: added 500ms delay after msg send to prevent spam --- src/components/InputArea.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/InputArea.tsx b/src/components/InputArea.tsx index 09f8da7..c1715f4 100644 --- a/src/components/InputArea.tsx +++ b/src/components/InputArea.tsx @@ -21,6 +21,7 @@ function InputArea({ chatId }: { chatId: string }) { if (text == '') return console.log('Sending data...') const currTime = new Date().toLocaleString() + const delay = (ms:number) => new Promise(res => setTimeout(res, ms)); const data = { jwt: localStorage.getItem('jwt'), msg: await encryptSymmetric(text), @@ -30,6 +31,11 @@ function InputArea({ chatId }: { chatId: string }) { setText('') socket.emit('message', data) textAreaRef.current ? (textAreaRef.current.value = '') : null + textAreaRef.current ? (textAreaRef.current.disabled = true) : null + delay(500).then(() => { + textAreaRef.current ? (textAreaRef.current.disabled = false) : null + textAreaRef.current ? (textAreaRef.current.focus()) : null + }) } const emojiPicked = (e: any) => {