Skip to content

Commit 780be7b

Browse files
author
Working On It
committed
fix: default avatar and text are always showed at first (casibase#1300)
1 parent 900d79f commit 780be7b

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

web/src/ChatBox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class ChatBox extends React.Component {
330330
return (
331331
<Layout style={{display: "flex", width: "100%", height: "100%", borderRadius: "6px"}}>
332332
<Card style={{display: "flex", width: "100%", height: "100%", flexDirection: "column", position: "relative", padding: "24px"}}>
333-
{messages.length === 0 && <WelcomeHeader store={this.props.store} />}
333+
{messages.length === 0 && <WelcomeHeader store={this.props.store} isStoreLoading={this.props.isStoreLoading} isStoreLoadingError={this.props.isStoreLoadingError} />}
334334

335335
<MessageList
336336
ref={this.messageListRef}

web/src/ChatPage.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class ChatPage extends BaseListPage {
5454
defaultStore: null,
5555
filteredStores: [],
5656
paneCount: 1,
57+
isStoreLoading: true,
58+
isStoreLoadingError: false,
5759
});
5860

5961
this.fetch();
@@ -115,6 +117,7 @@ class ChatPage extends BaseListPage {
115117
};
116118

117119
getGlobalStores() {
120+
this.state.isStoreLoading = true;
118121
StoreBackend.getGlobalStores("", "", "", "", "", "").then((res) => {
119122
if (res.status === "ok") {
120123
const stores = res?.data;
@@ -130,9 +133,13 @@ class ChatPage extends BaseListPage {
130133
stores: stores,
131134
defaultStore: defaultStore,
132135
filteredStores: filteredStores,
136+
isStoreLoading: false,
133137
});
134138
} else {
135139
Setting.showMessage("error", `${i18next.t("general:Failed to get")}: ${res.msg}`);
140+
this.setState({
141+
isStoreLoadingError: true,
142+
});
136143
}
137144
});
138145
}
@@ -754,6 +761,8 @@ class ChatPage extends BaseListPage {
754761
name={this.state.chat?.name}
755762
displayName={this.state.chat?.displayName}
756763
store={this.state.chat ? this.state.stores?.find(store => store.name === this.state.chat.store) : this.state.stores?.find(store => store.isDefault === true)}
764+
isStoreLoading={this.state.isStoreLoading}
765+
isStoreLoadingError={this.state.isStoreLoadingError}
757766
/>
758767
</div>
759768
)}

web/src/chat/WelcomeHeader.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,48 @@ import {Welcome} from "@ant-design/x";
1717
import * as Setting from "../Setting";
1818
import i18next from "i18next";
1919

20-
const WelcomeHeader = ({store}) => {
21-
const avatar = store?.avatar || Setting.AiAvatar;
20+
const WelcomeHeader = ({store, isStoreLoading, isStoreLoadingError}) => {
21+
22+
const getTitle = () => {
23+
if (isStoreLoading) {
24+
return null;
25+
}
26+
if (isStoreLoadingError) {
27+
return i18next.t("chat:Hello, I'm Casibase AI Assistant");
28+
}
29+
return store?.welcomeTitle || i18next.t("chat:Hello, I'm Casibase AI Assistant");
30+
};
31+
32+
const getDescription = () => {
33+
if (isStoreLoading) {
34+
return null;
35+
}
36+
if (isStoreLoadingError) {
37+
return i18next.t("chat:I'm here to help answer your questions");
38+
}
39+
return store?.welcomeText || i18next.t("chat:I'm here to help answer your questions");
40+
};
41+
42+
const getAvatar = () => {
43+
if (isStoreLoading) {
44+
return null;
45+
}
46+
if (isStoreLoadingError) {
47+
return Setting.AiAvatar;
48+
}
49+
return store?.avatar || Setting.AiAvatar;
50+
};
51+
52+
const avatar = getAvatar();
53+
const title = getTitle();
54+
const description = getDescription();
2255

2356
return (
2457
<Welcome
2558
variant="borderless"
2659
icon={avatar}
27-
title={store?.welcomeTitle || i18next.t("chat:Hello, I'm Casibase AI Assistant")}
28-
description={store?.welcomeText || i18next.t("chat:I'm here to help answer your questions")}
60+
title={title}
61+
description={description}
2962
/>
3063
);
3164
};

0 commit comments

Comments
 (0)