From 0af9230c6e604f3a48fc33d381022349dee0a682 Mon Sep 17 00:00:00 2001 From: ecwu Date: Mon, 20 Jan 2025 14:14:24 +0000 Subject: [PATCH 1/4] feat: enhance chat session notifications with API endpoint details --- src/pages/App.tsx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 50f9283..8a205a9 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -90,6 +90,7 @@ import { useToast } from "@/hooks/use-toast"; import { ModeToggle } from "@/components/ModeToggle"; import Navbar from "@/components/navbar"; +import { is } from "date-fns/locale"; export function App() { // init selected index @@ -109,8 +110,12 @@ export function App() { const { toast } = useToast(); const getChatStoreByIndex = async (index: number): Promise => { + let isOverrideEndpoint = false; const ret: ChatStore = await (await db).get(STORAGE_NAME, index); - if (ret === null || ret === undefined) return newChatStore({}); + if (ret === null || ret === undefined) { + isOverrideEndpoint = true; + return newChatStore({}); + } // handle read from old version chatstore if (ret.maxGenTokens === undefined) ret.maxGenTokens = 2048; if (ret.maxGenTokens_enabled === undefined) ret.maxGenTokens_enabled = true; @@ -126,6 +131,19 @@ export function App() { message.token = calculate_token_length(message.content); } if (ret.cost === undefined) ret.cost = 0; + if (isOverrideEndpoint) { + // if the chatStore is not found, we need to override the endpoint + // with the default one + toast({ + title: "New chat session created", + description: `API Endpoint: ${ret.apiEndpoint}`, + }); + } else { + toast({ + title: "Chat history loaded", + description: `Current API Endpoint: ${ret.apiEndpoint}`, + }); + } return ret; }; @@ -140,7 +158,7 @@ export function App() { setAllChatStoreIndexes(await (await db).getAllKeys(STORAGE_NAME)); toast({ title: "New chat session created", - description: `A new chat session (ID. ${newKey}) has been created.`, + description: `Current API Endpoint: ${chatStore.apiEndpoint}`, }); }; const handleNewChatStore = async () => { From 02935d7a0f12487d31d449c78298ca3ff26e477d Mon Sep 17 00:00:00 2001 From: ecwu Date: Mon, 20 Jan 2025 14:54:08 +0000 Subject: [PATCH 2/4] fix: update toast messages for clarity in chat session notifications --- src/pages/App.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 8a205a9..2b9c939 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -135,12 +135,12 @@ export function App() { // if the chatStore is not found, we need to override the endpoint // with the default one toast({ - title: "New chat session created", + title: "New chat created", description: `API Endpoint: ${ret.apiEndpoint}`, }); } else { toast({ - title: "Chat history loaded", + title: "Chat ready", description: `Current API Endpoint: ${ret.apiEndpoint}`, }); } @@ -157,7 +157,7 @@ export function App() { setSelectedChatIndex(newKey as number); setAllChatStoreIndexes(await (await db).getAllKeys(STORAGE_NAME)); toast({ - title: "New chat session created", + title: "New chat created", description: `Current API Endpoint: ${chatStore.apiEndpoint}`, }); }; From cb1d25bbf6c9cbe6c086d7068fde6c42f1c59cf0 Mon Sep 17 00:00:00 2001 From: ecwu Date: Mon, 20 Jan 2025 15:01:34 +0000 Subject: [PATCH 3/4] fix: create a new toast when this is the first time visit --- src/pages/App.tsx | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 2b9c939..d5b56da 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -110,11 +110,14 @@ export function App() { const { toast } = useToast(); const getChatStoreByIndex = async (index: number): Promise => { - let isOverrideEndpoint = false; const ret: ChatStore = await (await db).get(STORAGE_NAME, index); if (ret === null || ret === undefined) { - isOverrideEndpoint = true; - return newChatStore({}); + const newStore = newChatStore({}); + toast({ + title: "New chat created", + description: `Current API Endpoint: ${newStore.apiEndpoint}`, + }); + return newStore; } // handle read from old version chatstore if (ret.maxGenTokens === undefined) ret.maxGenTokens = 2048; @@ -131,19 +134,11 @@ export function App() { message.token = calculate_token_length(message.content); } if (ret.cost === undefined) ret.cost = 0; - if (isOverrideEndpoint) { - // if the chatStore is not found, we need to override the endpoint - // with the default one - toast({ - title: "New chat created", - description: `API Endpoint: ${ret.apiEndpoint}`, - }); - } else { - toast({ - title: "Chat ready", - description: `Current API Endpoint: ${ret.apiEndpoint}`, - }); - } + + toast({ + title: "Chat ready", + description: `Current API Endpoint: ${ret.apiEndpoint}`, + }); return ret; }; From 26cd5d1022787061436e57ea83ac6d02b5d6722b Mon Sep 17 00:00:00 2001 From: ecwu Date: Mon, 20 Jan 2025 15:02:02 +0000 Subject: [PATCH 4/4] fix: remove unused import from App component --- src/pages/App.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index d5b56da..04c7984 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -90,7 +90,6 @@ import { useToast } from "@/hooks/use-toast"; import { ModeToggle } from "@/components/ModeToggle"; import Navbar from "@/components/navbar"; -import { is } from "date-fns/locale"; export function App() { // init selected index