fix delete and save new chat

This commit is contained in:
2023-03-17 01:16:21 +08:00
parent 09e9d18e71
commit 1372121e32

View File

@@ -79,7 +79,7 @@ export function App() {
console.log("saved chat", selectedChatIndex, chatStore); console.log("saved chat", selectedChatIndex, chatStore);
localStorage.setItem( localStorage.setItem(
`${STORAGE_NAME}-${selectedChatIndex}`, `${STORAGE_NAME}-${selectedChatIndex}`,
JSON.stringify(chatStore) JSON.stringify(cs)
); );
}; };
@@ -92,6 +92,7 @@ export function App() {
onClick={() => { onClick={() => {
const max = Math.max(...allChatStoreIndexes); const max = Math.max(...allChatStoreIndexes);
const next = max + 1; const next = max + 1;
console.log("save next chat", next);
localStorage.setItem( localStorage.setItem(
`${STORAGE_NAME}-${next}`, `${STORAGE_NAME}-${next}`,
JSON.stringify( JSON.stringify(
@@ -138,6 +139,7 @@ export function App() {
onClick={() => { onClick={() => {
if (!confirm("Are you sure you want to delete this chat history?")) if (!confirm("Are you sure you want to delete this chat history?"))
return; return;
console.log("remove item", `${STORAGE_NAME}-${selectedChatIndex}`);
localStorage.removeItem(`${STORAGE_NAME}-${selectedChatIndex}`); localStorage.removeItem(`${STORAGE_NAME}-${selectedChatIndex}`);
const newAllChatStoreIndexes = [ const newAllChatStoreIndexes = [
...allChatStoreIndexes.filter((v) => v !== selectedChatIndex), ...allChatStoreIndexes.filter((v) => v !== selectedChatIndex),
@@ -145,7 +147,6 @@ export function App() {
if (newAllChatStoreIndexes.length === 0) { if (newAllChatStoreIndexes.length === 0) {
newAllChatStoreIndexes.push(0); newAllChatStoreIndexes.push(0);
}
setChatStore( setChatStore(
newChatStore( newChatStore(
chatStore.apiKey, chatStore.apiKey,
@@ -154,6 +155,7 @@ export function App() {
chatStore.streamMode chatStore.streamMode
) )
); );
}
// find nex selected chat index // find nex selected chat index
const next = newAllChatStoreIndexes[0]; const next = newAllChatStoreIndexes[0];