From 30abf3ed150f8e50dd40ec2e8a9bd8c05e178830 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Mon, 27 Mar 2023 13:15:23 +0800 Subject: [PATCH] auto create new chatStore if there any params in URL --- src/app.tsx | 54 +++++++++++++++++++++++++++++++------------------ src/chatbox.tsx | 6 +++++- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index b151ff3..1cc3cb0 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -89,31 +89,45 @@ export function App() { _setChatStore(getChatStoreByIndex(selectedChatIndex)); }, [selectedChatIndex]); + const handleNewChatStore = () => { + const max = Math.max(...allChatStoreIndexes); + const next = max + 1; + console.log("save next chat", next); + localStorage.setItem( + `${STORAGE_NAME}-${next}`, + JSON.stringify( + newChatStore( + chatStore.apiKey, + chatStore.systemMessageContent, + chatStore.apiEndpoint, + chatStore.streamMode + ) + ) + ); + allChatStoreIndexes.push(next); + setAllChatStoreIndexes([...allChatStoreIndexes]); + setSelectedChatIndex(next); + }; + + // if there are any params in URL, create a new chatStore + useEffect(() => { + if ( + getDefaultParams("api", "") || + getDefaultParams("key", "") || + getDefaultParams("mode", "") || + getDefaultParams("sys", "") + ) { + handleNewChatStore(); + } + }, []); + return (
@@ -126,7 +140,7 @@ export function App() { return (