Skip to content

Commit

Permalink
feat: keep unsent content in chat message box (casibase#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherlocksuper authored Jul 30, 2024
1 parent 997839c commit d23e5e7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions web/src/ChatBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import {ThemeDefault} from "./Conf";
import {AudioFilled, AudioOutlined, CopyOutlined, DislikeFilled, DislikeOutlined, LikeFilled, LikeOutlined, PauseCircleOutlined, PlayCircleOutlined, ReloadOutlined} from "@ant-design/icons";
import ChatPrompts from "./ChatPrompts";

// store the input value when the name(chat) leaves
const inputStore = new Map();

class ChatBox extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -54,8 +57,18 @@ class ChatBox extends React.Component {
componentDidUpdate(prevProps, prevState, snapshot) {
// clear old status when the name(chat) changes
if (prevProps.name !== this.props.name) {
inputStore.set(prevProps.name, this.state.value);
this.clearOldStatus();
}
if (inputStore.has(this.props.name)) {
this.setState({value: inputStore.get(this.props.name)});
inputStore.delete(this.props.name);
}
}

componentWillUnmount() {
inputStore.set(this.props.name, this.state.value);
this.clearOldStatus();
}

clearOldStatus() {
Expand Down

0 comments on commit d23e5e7

Please sign in to comment.