Skip to content

Commit

Permalink
feat: clear indexDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogtiti committed Aug 26, 2024
1 parent 492b55c commit 0b75894
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { createPersistStore } from "../utils/store";
import { collectModelsWithDefaultModel } from "../utils/model";
import { useAccessStore } from "./access";
import { isDalle3 } from "../utils";
import { clear } from "idb-keyval";
import { indexDBStorage } from "@/app/utils/indexDB-storage";

export type ChatMessage = RequestMessage & {
date: string;
Expand Down Expand Up @@ -667,7 +667,7 @@ export const useChatStore = createPersistStore(
},

async clearAllData() {
await clear();
await indexDBStorage.clear();
localStorage.clear();
location.reload();
},
Expand Down
8 changes: 5 additions & 3 deletions app/utils/indexDB-storage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { StateStorage } from "zustand/middleware";
import { get, set, del } from "idb-keyval";
import { get, set, del, clear } from "idb-keyval";

class IndexDBStorage implements StateStorage {
constructor() {}

public async getItem(name: string): Promise<string | null> {
return (await get(name)) || localStorage.getItem(name);
}
Expand All @@ -15,6 +13,10 @@ class IndexDBStorage implements StateStorage {
public async removeItem(name: string): Promise<void> {
await del(name);
}

public async clear(): Promise<void> {
await clear();
}
}

export const indexDBStorage = new IndexDBStorage();

0 comments on commit 0b75894

Please sign in to comment.