diff --git a/web/src/ChatBox.js b/web/src/ChatBox.js index 9140cd58..67abe68f 100644 --- a/web/src/ChatBox.js +++ b/web/src/ChatBox.js @@ -51,6 +51,27 @@ class ChatBox extends React.Component { this.addCursorPositionListener(); } + componentDidUpdate(prevProps, prevState, snapshot) { + // clear old status when the name(chat) changes + if (prevProps.name !== this.props.name) { + this.clearOldStatus(); + } + } + + clearOldStatus() { + this.recognition?.abort(); + this.synth.cancel(); + this.setState({ + value: "", + files: [], + messages: this.props.messages, + currentReadingMessage: null, + isReading: false, + isVoiceInput: false, + }); + this.cursorPosition = undefined; + } + addCursorPositionListener() { const inputElement = document.querySelector(".cs-message-input__content-editor"); const updateCursorPosition = () => { @@ -63,7 +84,7 @@ class ChatBox extends React.Component { this.cursorPosition = preSelectionRange.toString().length; if (this.state.isVoiceInput) { this.recognition.abort(); - this.recognition.onresult = this.insertVoiceMessage.call(this); + // this.recognition.onresult = this.insertVoiceMessage.call(this); } } }; diff --git a/web/src/ChatPage.js b/web/src/ChatPage.js index 75c86b0a..e1663317 100644 --- a/web/src/ChatPage.js +++ b/web/src/ChatPage.js @@ -531,7 +531,7 @@ class ChatPage extends BaseListPage { ) } - {this.sendMessage(text, fileName, false, regenerate);}} account={this.props.account} dots={this.state.dots} /> + {this.sendMessage(text, fileName, false, regenerate);}} account={this.props.account} dots={this.state.dots} name={this.state.chat?.name} /> );