diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-01-14 14:50:37 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-01-14 14:50:37 +0200 |
commit | 4d1d0d7d98746b8abcdae8ae48b740929e427f41 (patch) | |
tree | ff3f24a230bebc251df749a801d37da3fef211b6 | |
parent | 1f696f34c2ea50b35f166417c4b56b2dac46b340 (diff) | |
download | epq-web-4d1d0d7d98746b8abcdae8ae48b740929e427f41.tar.gz epq-web-4d1d0d7d98746b8abcdae8ae48b740929e427f41.tar.bz2 epq-web-4d1d0d7d98746b8abcdae8ae48b740929e427f41.zip |
Temporarily resolved keydown repeat event bug by circumventing sendData empty string alert.
-rw-r--r-- | src/Chat/Chat.tsx | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/Chat/Chat.tsx b/src/Chat/Chat.tsx index 648628e..e2edfcb 100644 --- a/src/Chat/Chat.tsx +++ b/src/Chat/Chat.tsx @@ -36,7 +36,6 @@ const Chat = ({ user }: { user: string }): React.ReactElement => { />, ]); }); - console.log(messages); }); stompClientRef.current.publish({ body: JSON.stringify({ @@ -62,14 +61,11 @@ const Chat = ({ user }: { user: string }): React.ReactElement => { // Button press event handler. const sendData = () => { - console.log("WebSockets handler invoked."); - // There must be a react-native and non-document-getElementById way to do this - // TODO Explore + const entryElement: HTMLInputElement = document.getElementById( "data-entry" ) as HTMLInputElement; - if (!entryElement.value) { - alert("Message cannot be empty!"); + if (entryElement.value === "") { return; } const messageData: Message = { @@ -98,10 +94,10 @@ const Chat = ({ user }: { user: string }): React.ReactElement => { return () => { stompClientRef.current.deactivate(); }; - }, [stompClientRef]); + }, []); // https://www.w3schools.com/jsref/obj_keyboardevent.asp - document.addEventListener("keypress", (ev: KeyboardEvent) => { - if (ev.key == "Enter") { + document.addEventListener("keydown", (ev: KeyboardEvent) => { + if (ev.key === "Enter") { sendData(); } }); |