Temporarily resolved keydown repeat event bug by circumventing sendData empty string alert.
This commit is contained in:
parent
1f696f34c2
commit
4d1d0d7d98
1 changed files with 5 additions and 9 deletions
|
@ -36,7 +36,6 @@ const Chat = ({ user }: { user: string }): React.ReactElement => {
|
||||||
/>,
|
/>,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
console.log(messages);
|
|
||||||
});
|
});
|
||||||
stompClientRef.current.publish({
|
stompClientRef.current.publish({
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -62,14 +61,11 @@ const Chat = ({ user }: { user: string }): React.ReactElement => {
|
||||||
|
|
||||||
// Button press event handler.
|
// Button press event handler.
|
||||||
const sendData = () => {
|
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(
|
const entryElement: HTMLInputElement = document.getElementById(
|
||||||
"data-entry"
|
"data-entry"
|
||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
if (!entryElement.value) {
|
if (entryElement.value === "") {
|
||||||
alert("Message cannot be empty!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const messageData: Message = {
|
const messageData: Message = {
|
||||||
|
@ -98,10 +94,10 @@ const Chat = ({ user }: { user: string }): React.ReactElement => {
|
||||||
return () => {
|
return () => {
|
||||||
stompClientRef.current.deactivate();
|
stompClientRef.current.deactivate();
|
||||||
};
|
};
|
||||||
}, [stompClientRef]);
|
}, []);
|
||||||
// https://www.w3schools.com/jsref/obj_keyboardevent.asp
|
// https://www.w3schools.com/jsref/obj_keyboardevent.asp
|
||||||
document.addEventListener("keypress", (ev: KeyboardEvent) => {
|
document.addEventListener("keydown", (ev: KeyboardEvent) => {
|
||||||
if (ev.key == "Enter") {
|
if (ev.key === "Enter") {
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue