diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-05-03 10:05:03 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-05-03 10:05:03 -0500 |
| commit | 8a22018aefbb89d1b74788a0d6bda97b0d8da6b0 (patch) | |
| tree | 007f0ea9380774c399929482a3de79b48fc07ecd | |
| parent | 8ddc38f768e18a7c72a3b904446fdb01835092bd (diff) | |
| download | slskd-8a22018aefbb89d1b74788a0d6bda97b0d8da6b0.tar.gz | |
use state for message input instead of dom ref (causing delay in updates)
| -rw-r--r-- | src/web/src/components/Chat/Chat.jsx | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 23619bd1..9e3605b8 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -20,6 +20,7 @@ const initialState = { conversations: {}, interval: undefined, loading: false, + message: '', }; class Chat extends Component { @@ -106,21 +107,15 @@ class Chat extends Component { await chat.acknowledge({ username }); }; - sendMessage = async (username, message) => { - if (!username || !message || username === '') return; - await chat.send({ message, username }); - }; - sendReply = async () => { - const { active } = this.state; - const message = this.messageRef.current.value; + const { active, message } = this.state; if (!this.validInput()) { return; } - await this.sendMessage(active, message); - this.messageRef.current.value = ''; + await chat.send({ username: active, message }); + this.setState({ message: '' }); // force a refresh to append the message // we could probably do this in the browser but we can be lazy @@ -129,12 +124,7 @@ class Chat extends Component { validInput = () => (this.state.active || '').length > 0 && - ( - (this.messageRef && - this.messageRef.current && - this.messageRef.current.value) || - '' - ).length > 0; + (this.state.message || '').length > 0; focusInput = () => { this.messageRef.current.focus(); @@ -294,7 +284,7 @@ class Chat extends Component { name="send" /> ), - onClick: this.sendMessage, + onClick: this.sendReply, }} fluid input={ @@ -302,7 +292,11 @@ class Chat extends Component { autoComplete="off" data-lpignore="true" id="chat-message-input" + onChange={(event) => + this.setState({ message: event.target.value }) + } type="text" + value={this.state.message} /> } onKeyUp={(event) => |
