diff --git a/README.md b/README.md index b6f974bd457..9811f1d353c 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ One-Click to get a well-designed cross-platform ChatGPT web UI, with GPT3, GPT4 [Deploy on Zeabur](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FChatGPTNextWeb%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=nextchat&repository-name=NextChat) [Deploy on Zeabur](https://zeabur.com/templates/ZBUEFA) [Open in Gitpod](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web) +[](https://monica.im/?utm=nxcrp) + ## Enterprise Edition diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 7d180f0b739..4011858f67d 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1619,7 +1619,7 @@ function _Chat() { message.content.length === 0 && !isUser } - onContextMenu={(e) => onRightClick(e, message)} + // onContextMenu={(e) => onRightClick(e, message)} // hard to use onDoubleClickCapture={() => { if (!isMobileScreen) return; setUserInput(getMessageTextContent(message)); diff --git a/app/store/chat.ts b/app/store/chat.ts index c2d1995194b..9e7aa043ff1 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -27,6 +27,7 @@ import { createPersistStore } from "../utils/store"; import { collectModelsWithDefaultModel } from "../utils/model"; import { useAccessStore } from "./access"; import { isDalle3 } from "../utils"; +import { indexedDBStorage } from "@/app/utils/indexedDB-storage"; export type ChatMessageTool = { id: string; @@ -695,7 +696,8 @@ export const useChatStore = createPersistStore( set(() => ({ sessions })); }, - clearAllData() { + async clearAllData() { + await indexedDBStorage.clear(); localStorage.clear(); location.reload(); }, diff --git a/app/utils/indexedDB-storage.ts b/app/utils/indexedDB-storage.ts new file mode 100644 index 00000000000..51ee92b8185 --- /dev/null +++ b/app/utils/indexedDB-storage.ts @@ -0,0 +1,38 @@ +import { StateStorage } from "zustand/middleware"; +import { get, set, del, clear } from "idb-keyval"; + +class IndexedDBStorage implements StateStorage { + public async getItem(name: string): Promise { + try { + return (await get(name)) || localStorage.getItem(name); + } catch (error) { + return localStorage.getItem(name); + } + } + + public async setItem(name: string, value: string): Promise { + try { + await set(name, value); + } catch (error) { + localStorage.setItem(name, value); + } + } + + public async removeItem(name: string): Promise { + try { + await del(name); + } catch (error) { + localStorage.removeItem(name); + } + } + + public async clear(): Promise { + try { + await clear(); + } catch (error) { + localStorage.clear(); + } + } +} + +export const indexedDBStorage = new IndexedDBStorage(); diff --git a/app/utils/store.ts b/app/utils/store.ts index 684a1911279..13bef6d5dfe 100644 --- a/app/utils/store.ts +++ b/app/utils/store.ts @@ -1,7 +1,8 @@ import { create } from "zustand"; -import { combine, persist } from "zustand/middleware"; +import { combine, persist, createJSONStorage } from "zustand/middleware"; import { Updater } from "../typing"; import { deepClone } from "./clone"; +import { indexedDBStorage } from "@/app/utils/indexedDB-storage"; type SecondParam = T extends ( _f: infer _F, @@ -31,6 +32,7 @@ export function createPersistStore( ) => M, persistOptions: SecondParam>>, ) { + persistOptions.storage = createJSONStorage(() => indexedDBStorage); return create( persist( combine( diff --git a/package.json b/package.json index 82f23a4a0f8..d3f0621851c 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "fuse.js": "^7.0.0", "heic2any": "^0.0.4", "html-to-image": "^1.11.11", + "idb-keyval": "^6.2.1", "lodash-es": "^4.17.21", "mermaid": "^10.6.1", "nanoid": "^5.0.3", diff --git a/yarn.lock b/yarn.lock index f138eb95738..5ca929baf56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3981,6 +3981,11 @@ iconv-lite@0.6: dependencies: safer-buffer ">= 2.1.2 < 3.0.0" +idb-keyval@^6.2.1: + version "6.2.1" + resolved "https://registry.npmmirror.com/idb-keyval/-/idb-keyval-6.2.1.tgz#94516d625346d16f56f3b33855da11bfded2db33" + integrity sha512-8Sb3veuYCyrZL+VBt9LJfZjLUPWVvqn8tG28VqYNFCo43KHcKuq+b4EiXGeuaLAQWL2YmyDgMp2aSpH9JHsEQg== + ignore@^5.2.0: version "5.2.4" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324"