From 38f4f24e3c4bc81d10a8100ee0922f5094eea5bf Mon Sep 17 00:00:00 2001 From: Sasha Date: Thu, 2 Mar 2023 00:06:04 +0100 Subject: [PATCH] improve condition for message sending, fix clear input issue --- examples/web-chat/src/MessageInput.tsx | 3 ++- examples/web-chat/src/Room.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/web-chat/src/MessageInput.tsx b/examples/web-chat/src/MessageInput.tsx index 78f3fae..86b0f4c 100644 --- a/examples/web-chat/src/MessageInput.tsx +++ b/examples/web-chat/src/MessageInput.tsx @@ -23,13 +23,14 @@ export default function MessageInput(props: Props) { const [isActive, setActiveButton] = useState(false); const onMessage = async () => { - if (props.sendMessage) { + if (props.sendMessage && inputText) { await props.sendMessage(inputText); setInputText(""); } }; const onChange = (event: ChangeEvent) => { + event.preventDefault(); setInputText(event.target.value); }; diff --git a/examples/web-chat/src/Room.tsx b/examples/web-chat/src/Room.tsx index d661fa2..432f567 100644 --- a/examples/web-chat/src/Room.tsx +++ b/examples/web-chat/src/Room.tsx @@ -22,7 +22,7 @@ export default function Room(props: Props) { const { storePeers, filterPeers, lightPushPeers } = usePeers({ node }); const onSend = async (text: string) => { - if (!onPush) { + if (!onPush || !text) { return; }