From 99d6e715341b5a2fdeafcc307d1bd9149414a0fc Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 10 Nov 2023 10:14:41 +0700 Subject: [PATCH 1/7] Chore [Local Language] [+] chore(locales): update language translations for cn, en, and id locales - Add new translations for Description section in cn, en, and id locales - Update translations for Overview section in id locales - Update translation for ImportFailed key in id locales --- app/locales/cn.ts | 11 +++++++++++ app/locales/en.ts | 11 +++++++++++ app/locales/id.ts | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 7378f05fbcf..10cd28565a2 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -287,6 +287,17 @@ const cn = { Overview: (overview: any) => { return `${overview.chat} 次对话,${overview.message} 条消息,${overview.prompt} 条提示词,${overview.mask} 个面具`; }, + Description: { + Chat: (overview: any) => { + return `${overview.chat} 次对话,${overview.message} 条消息`; + }, + Prompt: (overview: any) => { + return `${overview.prompt} 条提示词`; + }, + Masks: (overview: any) => { + return `${overview.mask} 个面具`; + }, + }, ImportFailed: "导入失败", }, Mask: { diff --git a/app/locales/en.ts b/app/locales/en.ts index 8714c5bcb79..d5d95ff3e87 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -292,6 +292,17 @@ const en: LocaleType = { Overview: (overview: any) => { return `${overview.chat} chats,${overview.message} messages,${overview.prompt} prompts,${overview.mask} masks`; }, + Description: { + Chat: (overview: any) => { + return `${overview.chat} chats,${overview.message} messages`; + }, + Prompt: (overview: any) => { + return `${overview.prompt} prompts`; + }, + Masks: (overview: any) => { + return `${overview.mask} masks`; + }, + }, ImportFailed: "Failed to import from file", }, Mask: { diff --git a/app/locales/id.ts b/app/locales/id.ts index ce8fb986aff..350c7e879a1 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -263,6 +263,22 @@ const id: PartialLocaleType = { }, }, }, + LocalState: "Data Lokal", + Overview: (overview: any) => { + return `${overview.chat} percakapan, ${overview.message} pesan, ${overview.prompt} prompt, ${overview.mask} masks`; + }, + Description: { + Chat: (overview: any) => { + return `${overview.chat} percakapan, ${overview.message} pesan`; + }, + Prompt: (overview: any) => { + return `${overview.prompt} prompt`; + }, + Masks: (overview: any) => { + return `${overview.mask} masks`; + }, + }, + ImportFailed: "Gagal mengimpor dari file", }, SendKey: "Kirim", Theme: "Tema", From af390b86c3032949220c8b0d77e98f4944613ce3 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 10 Nov 2023 11:08:00 +0700 Subject: [PATCH 2/7] Refactor [Local Language] [Manage Data] [+] refactor(locales): refactor Chat, Prompt, and Masks descriptions in cn.ts, en.ts, and id.ts [+] feat(locales): add Manage translation in en.ts and id.ts --- app/locales/cn.ts | 13 ++++++++++--- app/locales/en.ts | 13 ++++++++++--- app/locales/id.ts | 13 ++++++++++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 10cd28565a2..19974231b23 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -289,13 +289,19 @@ const cn = { }, Description: { Chat: (overview: any) => { - return `${overview.chat} 次对话,${overview.message} 条消息`; + const title = "次对话"; + const description = `${overview.chat} 次对话,, ${overview.message} 条消息`; + return { title, description }; }, Prompt: (overview: any) => { - return `${overview.prompt} 条提示词`; + const title = "条提示词"; + const description = `${overview.prompt} 条提示词`; + return { title, description }; }, Masks: (overview: any) => { - return `${overview.mask} 个面具`; + const title = "个面具"; + const description = `${overview.mask} 个面具`; + return { title, description }; }, }, ImportFailed: "导入失败", @@ -541,6 +547,7 @@ const cn = { Import: "导入", Sync: "同步", Config: "配置", + Manage: "管理", }, Exporter: { Model: "模型", diff --git a/app/locales/en.ts b/app/locales/en.ts index d5d95ff3e87..1df0dc08c50 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -294,13 +294,19 @@ const en: LocaleType = { }, Description: { Chat: (overview: any) => { - return `${overview.chat} chats,${overview.message} messages`; + const title = "Chats"; + const description = `${overview.chat} chats, ${overview.message} messages`; + return { title, description }; }, Prompt: (overview: any) => { - return `${overview.prompt} prompts`; + const title = "Prompts"; + const description = `${overview.prompt} prompts`; + return { title, description }; }, Masks: (overview: any) => { - return `${overview.mask} masks`; + const title = "Masks"; + const description = `${overview.mask} masks`; + return { title, description }; }, }, ImportFailed: "Failed to import from file", @@ -544,6 +550,7 @@ const en: LocaleType = { Import: "Import", Sync: "Sync", Config: "Config", + Manage: "Manage", }, Exporter: { Model: "Model", diff --git a/app/locales/id.ts b/app/locales/id.ts index 350c7e879a1..9352294dcee 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -269,13 +269,19 @@ const id: PartialLocaleType = { }, Description: { Chat: (overview: any) => { - return `${overview.chat} percakapan, ${overview.message} pesan`; + const title = "Percakapan"; + const description = `${overview.chat} percakapan, ${overview.message} pesan`; + return { title, description }; }, Prompt: (overview: any) => { - return `${overview.prompt} prompt`; + const title = "Prompts"; + const description = `${overview.prompt} Prompts`; + return { title, description }; }, Masks: (overview: any) => { - return `${overview.mask} masks`; + const title = "Masks"; + const description = `${overview.mask} masks`; + return { title, description }; }, }, ImportFailed: "Gagal mengimpor dari file", @@ -472,6 +478,7 @@ const id: PartialLocaleType = { Close: "Tutup", Create: "Buat", Edit: "Edit", + Manage: "Kelola", }, Exporter: { Model: "Model", From 94d1e50a45d9f90f3f9d3bab668c1eab814d502a Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 10 Nov 2023 11:24:51 +0700 Subject: [PATCH 3/7] Feat UI/UX Page [Settings] Managing local data [+] feat(settings.tsx): add support for managing local data [+] chore(settings.tsx): add WIP comment to LocalDataModal component [+] fix(settings.tsx): fix missing import for LocalDataModal component [+] feat(settings.tsx): add button to show LocalDataModal component [+] feat(settings.tsx): add LocalDataModal component to render function --- app/components/settings.tsx | 124 ++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 367784c5acf..18176fad888 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -569,6 +569,118 @@ function SyncConfigModal(props: { onClose?: () => void }) { ); } +/** + * Manage Local Data + * Author : @H0llyW00dzZ + * WIP + **/ + +function LocalDataModal(props: { onClose?: () => void }) { + const syncStore = useSyncStore(); + const [showLocalData, setShowLocalData] = useState(false); + const chatStore = useChatStore(); + const promptStore = usePromptStore(); + const maskStore = useMaskStore(); + const stateOverview = useMemo(() => { + const sessions = chatStore.sessions; + const messageCount = sessions.reduce((p, c) => p + c.messages.length, 0); + + return { + chat: sessions.length, + message: messageCount, + prompt: Object.keys(promptStore.prompts).length, + mask: Object.keys(maskStore.masks).length, + }; + }, [chatStore.sessions, maskStore.masks, promptStore.prompts]); + + return ( +
+ props.onClose?.()} + actions={[ + , + } + bordered + text={Locale.UI.Confirm} + />, + ]} + > + + +
+ } + text={Locale.UI.Export} + onClick={() => { + showToast(Locale.WIP); + }} + /> + } + text={Locale.UI.Import} + onClick={() => { + showToast(Locale.WIP); + }} + /> +
+
+ +
+ } + text={Locale.UI.Export} + onClick={() => { + showToast(Locale.WIP); + }} + /> + } + text={Locale.UI.Import} + onClick={() => { + showToast(Locale.WIP); + }} + /> +
+
+ +
+ } + text={Locale.UI.Export} + onClick={() => { + showToast(Locale.WIP); + }} + /> + } + text={Locale.UI.Import} + onClick={() => { + showToast(Locale.WIP); + }} + /> +
+
+
+ {showLocalData && ( + setShowLocalData(false)} /> + )} +
+
+ ); +} function SyncItems() { const syncStore = useSyncStore(); @@ -580,6 +692,7 @@ function SyncItems() { }, [syncStore]); const [showSyncConfigModal, setShowSyncConfigModal] = useState(false); + const [showLocalData, setShowLocalData] = useState(false); const stateOverview = useMemo(() => { const sessions = chatStore.sessions; @@ -637,6 +750,13 @@ function SyncItems() { subTitle={Locale.Settings.Sync.Overview(stateOverview)} >
+ } + text={Locale.UI.Manage} + onClick={() => { + setShowLocalData(true); + }} + /> } text={Locale.UI.Export} @@ -658,6 +778,10 @@ function SyncItems() { {showSyncConfigModal && ( setShowSyncConfigModal(false)} /> )} + + {showLocalData && ( + setShowLocalData(false)} /> + )} ); } From 389fdb99feb098bad9bf7039f47613715afa24d2 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 10 Nov 2023 12:22:50 +0700 Subject: [PATCH 4/7] Feat UI/UX Page [Settings] Clear Chat Data [+] feat(settings.tsx): add clear chat data functionality to settings modal [+] feat(chat.ts): add clearChatData function to chat store --- app/components/settings.tsx | 9 +++++++++ app/store/chat.ts | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 18176fad888..9aedb3b7f79 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -629,6 +629,15 @@ function LocalDataModal(props: { onClose?: () => void }) { showToast(Locale.WIP); }} /> + } + text={Locale.Settings.Danger.Clear.Action} + onClick={async () => { + if (await showConfirm(Locale.Settings.Danger.Clear.Confirm)) { + chatStore.clearChatData(); + } + }} + />
({ sessions })); }, + clearChatData() { + set(() => ({ + sessions: [createEmptySession()], + currentSessionIndex: 0, + })); + }, + clearAllData() { localStorage.clear(); location.reload(); From 8a1957d58794acd1f452fcc0e023e9f8fa19c37a Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 10 Nov 2023 13:23:22 +0700 Subject: [PATCH 5/7] Feat UI/UX Page [Settings] Exporting chat data [+] feat(settings.tsx): add support for exporting chat sessions as JSON file --- app/components/settings.tsx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 9aedb3b7f79..e1aa7cf6734 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -48,7 +48,10 @@ import Locale, { changeLang, getLang, } from "../locales"; -import { copyToClipboard } from "../utils"; +import { + copyToClipboard, + downloadAs, +} from "../utils"; import Link from "next/link"; import { Azure, @@ -578,6 +581,7 @@ function SyncConfigModal(props: { onClose?: () => void }) { function LocalDataModal(props: { onClose?: () => void }) { const syncStore = useSyncStore(); const [showLocalData, setShowLocalData] = useState(false); + const [exporting, setExporting] = useState(false); const chatStore = useChatStore(); const promptStore = usePromptStore(); const maskStore = useMaskStore(); @@ -593,6 +597,21 @@ function LocalDataModal(props: { onClose?: () => void }) { }; }, [chatStore.sessions, maskStore.masks, promptStore.prompts]); + const handleExportChat = async () => { + if (exporting) return; + setExporting(true); + const currentDate = new Date(); + const sessions = chatStore.sessions; + const totalMessageCount = sessions.reduce((count, session) => count + session.messages.length, 0); + const datePart = getClientConfig()?.isApp + ? `${currentDate.toLocaleDateString().replace(/\//g, '_')} ${currentDate.toLocaleTimeString().replace(/:/g, '_')}` + : `${currentDate.toLocaleString().replace(/:/g, '_')}`; + const formattedMessageCount = Locale.ChatItem.ChatItemCount(totalMessageCount); + const fileName = `(${formattedMessageCount})-${datePart}.json`; + await downloadAs(sessions, fileName); + setExporting(false); + }; + return (
void }) { } text={Locale.UI.Export} - onClick={() => { - showToast(Locale.WIP); - }} + onClick={handleExportChat} /> } From 9cfe09c6c1f12f6547d33d101df0df4c66750c5c Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 10 Nov 2023 14:57:34 +0700 Subject: [PATCH 6/7] Feat UI/UX Page [Settings] Importing chat data [+] feat(settings.tsx): add functionality to import chat data from a file [+] fix(settings.tsx): remove unused state variable 'showLocalData' [+] refactor(settings.tsx): remove unused code for managing local data --- app/components/settings.tsx | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index e1aa7cf6734..3acd7477708 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -51,6 +51,7 @@ import Locale, { import { copyToClipboard, downloadAs, + readFromFile, } from "../utils"; import Link from "next/link"; import { @@ -611,6 +612,21 @@ function LocalDataModal(props: { onClose?: () => void }) { await downloadAs(sessions, fileName); setExporting(false); }; + const handleImportChat = async () => { + if (exporting) return; + setExporting(true); + try { + const rawContent = await readFromFile(); // Read the file content using the appropriate function + + const importedData = JSON.parse(rawContent); + // Process the imported chat data and update the chat store + chatStore.newSession(importedData.sessions); + } catch (e) { + showToast(Locale.Settings.Sync.ImportFailed); + console.error(e); + } + setExporting(false); + }; return (
@@ -642,9 +658,7 @@ function LocalDataModal(props: { onClose?: () => void }) { } text={Locale.UI.Import} - onClick={() => { - showToast(Locale.WIP); - }} + onClick={handleImportChat} /> } @@ -718,7 +732,6 @@ function SyncItems() { }, [syncStore]); const [showSyncConfigModal, setShowSyncConfigModal] = useState(false); - const [showLocalData, setShowLocalData] = useState(false); const stateOverview = useMemo(() => { const sessions = chatStore.sessions; @@ -776,13 +789,6 @@ function SyncItems() { subTitle={Locale.Settings.Sync.Overview(stateOverview)} >
- } - text={Locale.UI.Manage} - onClick={() => { - setShowLocalData(true); - }} - /> } text={Locale.UI.Export} @@ -804,10 +810,6 @@ function SyncItems() { {showSyncConfigModal && ( setShowSyncConfigModal(false)} /> )} - - {showLocalData && ( - setShowLocalData(false)} /> - )} ); } From fd9de95868474d90caca62870c9222ad684e5316 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 10 Nov 2023 15:10:20 +0700 Subject: [PATCH 7/7] Fix "Feat UI/UX Page [Settings] Importing chat data" This Fix commit 9cfe09c6c1f12f6547d33d101df0df4c66750c5c. --- app/components/settings.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 3acd7477708..d8ef6fab656 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -732,6 +732,7 @@ function SyncItems() { }, [syncStore]); const [showSyncConfigModal, setShowSyncConfigModal] = useState(false); + const [showLocalData, setShowLocalData] = useState(false); const stateOverview = useMemo(() => { const sessions = chatStore.sessions; @@ -789,6 +790,13 @@ function SyncItems() { subTitle={Locale.Settings.Sync.Overview(stateOverview)} >
+ } + text={Locale.UI.Manage} + onClick={() => { + setShowLocalData(true); + }} + /> } text={Locale.UI.Export} @@ -810,6 +818,10 @@ function SyncItems() { {showSyncConfigModal && ( setShowSyncConfigModal(false)} /> )} + + {showLocalData && ( + setShowLocalData(false)} /> + )} ); }