From d6fff4bfa131c67c2cfa0531834fa01737ae15b5 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Wed, 15 May 2024 10:30:11 +0530 Subject: [PATCH] chore: Refactor deleteChatHistory method to deleteAllChatHistory --- src/components/Option/Settings/other.tsx | 2 +- src/db/index.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/Option/Settings/other.tsx b/src/components/Option/Settings/other.tsx index e33b389..edb4349 100644 --- a/src/components/Option/Settings/other.tsx +++ b/src/components/Option/Settings/other.tsx @@ -116,7 +116,7 @@ export const SettingOther = () => { if (confirm) { const db = new PageAssitDatabase() - await db.deleteChatHistory() + await db.deleteAllChatHistory() queryClient.invalidateQueries({ queryKey: ["fetchChatHistory"] }) diff --git a/src/db/index.ts b/src/db/index.ts index 088038a..1b85d11 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -121,6 +121,14 @@ export class PageAssitDatabase { this.db.remove(id) } + async deleteAllChatHistory() { + const chatHistories = await this.getChatHistories() + chatHistories.forEach((history) => { + this.db.remove(history.id) + }) + this.db.set({ chatHistories: [] }) + } + async deleteMessage(history_id: string) { await this.db.remove(history_id) } @@ -456,4 +464,4 @@ export const importPrompts = async (prompts: Prompts) => { for (const prompt of prompts) { await db.addPrompt(prompt) } -} \ No newline at end of file +}