Skip to content

Commit

Permalink
feat: fix the retained old status bug during chat switch (casibase#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherlocksuper authored Jul 30, 2024
1 parent 062d830 commit aeee771
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion web/src/ChatBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion web/src/ChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class ChatPage extends BaseListPage {
</div>
)
}
<ChatBox disableInput={this.state.disableInput} messages={this.state.messages} sendMessage={(text, fileName, regenerate = false) => {this.sendMessage(text, fileName, false, regenerate);}} account={this.props.account} dots={this.state.dots} />
<ChatBox disableInput={this.state.disableInput} messages={this.state.messages} sendMessage={(text, fileName, regenerate = false) => {this.sendMessage(text, fileName, false, regenerate);}} account={this.props.account} dots={this.state.dots} name={this.state.chat?.name} />
</div>
</div>
);
Expand Down

0 comments on commit aeee771

Please sign in to comment.