fix: create a new toast when this is the first time visit

This commit is contained in:
ecwu
2025-01-20 15:01:34 +00:00
parent 02935d7a0f
commit cb1d25bbf6

View File

@@ -110,11 +110,14 @@ export function App() {
const { toast } = useToast(); const { toast } = useToast();
const getChatStoreByIndex = async (index: number): Promise<ChatStore> => { const getChatStoreByIndex = async (index: number): Promise<ChatStore> => {
let isOverrideEndpoint = false;
const ret: ChatStore = await (await db).get(STORAGE_NAME, index); const ret: ChatStore = await (await db).get(STORAGE_NAME, index);
if (ret === null || ret === undefined) { if (ret === null || ret === undefined) {
isOverrideEndpoint = true; const newStore = newChatStore({});
return newChatStore({}); toast({
title: "New chat created",
description: `Current API Endpoint: ${newStore.apiEndpoint}`,
});
return newStore;
} }
// handle read from old version chatstore // handle read from old version chatstore
if (ret.maxGenTokens === undefined) ret.maxGenTokens = 2048; if (ret.maxGenTokens === undefined) ret.maxGenTokens = 2048;
@@ -131,19 +134,11 @@ export function App() {
message.token = calculate_token_length(message.content); message.token = calculate_token_length(message.content);
} }
if (ret.cost === undefined) ret.cost = 0; if (ret.cost === undefined) ret.cost = 0;
if (isOverrideEndpoint) {
// if the chatStore is not found, we need to override the endpoint toast({
// with the default one title: "Chat ready",
toast({ description: `Current API Endpoint: ${ret.apiEndpoint}`,
title: "New chat created", });
description: `API Endpoint: ${ret.apiEndpoint}`,
});
} else {
toast({
title: "Chat ready",
description: `Current API Endpoint: ${ret.apiEndpoint}`,
});
}
return ret; return ret;
}; };