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 (