chore: Refactor deleteChatHistory method to deleteAllChatHistory

This commit is contained in:
n4ze3m 2024-05-15 10:30:11 +05:30
parent 182f914275
commit d6fff4bfa1
2 changed files with 10 additions and 2 deletions

View File

@ -116,7 +116,7 @@ export const SettingOther = () => {
if (confirm) { if (confirm) {
const db = new PageAssitDatabase() const db = new PageAssitDatabase()
await db.deleteChatHistory() await db.deleteAllChatHistory()
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: ["fetchChatHistory"] queryKey: ["fetchChatHistory"]
}) })

View File

@ -121,6 +121,14 @@ export class PageAssitDatabase {
this.db.remove(id) 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) { async deleteMessage(history_id: string) {
await this.db.remove(history_id) await this.db.remove(history_id)
} }
@ -456,4 +464,4 @@ export const importPrompts = async (prompts: Prompts) => {
for (const prompt of prompts) { for (const prompt of prompts) {
await db.addPrompt(prompt) await db.addPrompt(prompt)
} }
} }