Fix new chat button

This commit is contained in:
Yang Luo
2023-05-01 13:27:49 +08:00
parent 8d531b8880
commit e4fd9cca92
2 changed files with 27 additions and 5 deletions

View File

@@ -110,6 +110,12 @@ class ChatMenu extends React.Component {
return items.map((item, index) => `${index}`); return items.map((item, index) => `${index}`);
} }
setSelectedKeyToNewChat() {
this.setState({
selectedKeys: ["0-0"],
});
}
onOpenChange = (keys) => { onOpenChange = (keys) => {
const items = this.chatsToItems(this.props.chats); const items = this.chatsToItems(this.props.chats);
const rootSubmenuKeys = this.getRootSubmenuKeys(items); const rootSubmenuKeys = this.getRootSubmenuKeys(items);

View File

@@ -24,6 +24,12 @@ import i18next from "i18next";
import BaseListPage from "./BaseListPage"; import BaseListPage from "./BaseListPage";
class ChatPage extends BaseListPage { class ChatPage extends BaseListPage {
constructor(props) {
super(props);
this.menu = React.createRef();
}
newChat(chat) { newChat(chat) {
const randomName = Setting.getRandomName(); const randomName = Setting.getRandomName();
return { return {
@@ -94,7 +100,7 @@ class ChatPage extends BaseListPage {
this.getMessages(newChat.name); this.getMessages(newChat.name);
const {pagination} = this.state; const {pagination} = this.state;
this.fetch({pagination}); this.fetch({pagination}, false);
} else { } else {
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`); Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
} }
@@ -135,6 +141,10 @@ class ChatPage extends BaseListPage {
}); });
} }
getCurrentChat() {
return this.state.data.filter(chat => chat.name === this.state.chatName)[0];
}
renderTable(chats) { renderTable(chats) {
const onSelectChat = (i) => { const onSelectChat = (i) => {
const chat = chats[i]; const chat = chats[i];
@@ -146,7 +156,7 @@ class ChatPage extends BaseListPage {
}; };
const onAddChat = () => { const onAddChat = () => {
const chat = this.state.data.filter(chat => chat.name === this.state.chatName)[0]; const chat = this.getCurrentChat();
this.addChat(chat); this.addChat(chat);
}; };
@@ -166,7 +176,7 @@ class ChatPage extends BaseListPage {
return ( return (
<div style={{display: "flex", height: "calc(100vh - 140px)"}}> <div style={{display: "flex", height: "calc(100vh - 140px)"}}>
<div style={{width: "250px", height: "100%", backgroundColor: "white", borderRight: "1px solid rgb(245,245,245)"}}> <div style={{width: "250px", height: "100%", backgroundColor: "white", borderRight: "1px solid rgb(245,245,245)"}}>
<ChatMenu chats={chats} onSelectChat={onSelectChat} onAddChat={onAddChat} onDeleteChat={onDeleteChat} /> <ChatMenu ref={this.menu} chats={chats} onSelectChat={onSelectChat} onAddChat={onAddChat} onDeleteChat={onDeleteChat} />
</div> </div>
<div style={{flex: 1, height: "100%", backgroundColor: "white", position: "relative"}}> <div style={{flex: 1, height: "100%", backgroundColor: "white", position: "relative"}}>
{ {
@@ -194,7 +204,7 @@ class ChatPage extends BaseListPage {
); );
} }
fetch = (params = {}) => { fetch = (params = {}, setLoading = true) => {
let field = params.searchedColumn, value = params.searchText; let field = params.searchedColumn, value = params.searchText;
const sortField = params.sortField, sortOrder = params.sortOrder; const sortField = params.sortField, sortOrder = params.sortOrder;
if (params.category !== undefined && params.category !== null) { if (params.category !== undefined && params.category !== null) {
@@ -204,7 +214,9 @@ class ChatPage extends BaseListPage {
field = "type"; field = "type";
value = params.type; value = params.type;
} }
this.setState({loading: true}); if (setLoading) {
this.setState({loading: true});
}
ChatBackend.getChats("admin", params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder) ChatBackend.getChats("admin", params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder)
.then((res) => { .then((res) => {
if (res.status === "ok") { if (res.status === "ok") {
@@ -227,6 +239,10 @@ class ChatPage extends BaseListPage {
chatName: chat.name, chatName: chat.name,
}); });
} }
if (!setLoading) {
this.menu.current.setSelectedKeyToNewChat();
}
} else { } else {
if (Setting.isResponseDenied(res)) { if (Setting.isResponseDenied(res)) {
this.setState({ this.setState({