Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
Feat UI/UX Page [Settings] Importing chat data
Browse files Browse the repository at this point in the history
[+] 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
  • Loading branch information
H0llyW00dzZ committed Nov 10, 2023
1 parent 8a1957d commit 9cfe09c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import Locale, {
import {
copyToClipboard,
downloadAs,
readFromFile,
} from "../utils";
import Link from "next/link";
import {
Expand Down Expand Up @@ -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 (
<div className="modal-mask">
Expand Down Expand Up @@ -642,9 +658,7 @@ function LocalDataModal(props: { onClose?: () => void }) {
<IconButton
icon={<DownloadIcon />}
text={Locale.UI.Import}
onClick={() => {
showToast(Locale.WIP);
}}
onClick={handleImportChat}
/>
<IconButton
icon={<ClearIcon />}
Expand Down Expand Up @@ -718,7 +732,6 @@ function SyncItems() {
}, [syncStore]);

const [showSyncConfigModal, setShowSyncConfigModal] = useState(false);
const [showLocalData, setShowLocalData] = useState(false);

const stateOverview = useMemo(() => {
const sessions = chatStore.sessions;
Expand Down Expand Up @@ -776,13 +789,6 @@ function SyncItems() {
subTitle={Locale.Settings.Sync.Overview(stateOverview)}
>
<div style={{ display: "flex" }}>
<IconButton
icon={<EditIcon />}
text={Locale.UI.Manage}
onClick={() => {
setShowLocalData(true);
}}
/>
<IconButton
icon={<UploadIcon />}
text={Locale.UI.Export}
Expand All @@ -804,10 +810,6 @@ function SyncItems() {
{showSyncConfigModal && (
<SyncConfigModal onClose={() => setShowSyncConfigModal(false)} />
)}

{showLocalData && (
<LocalDataModal onClose={() => setShowLocalData(false)} />
)}
</>
);
}
Expand Down

0 comments on commit 9cfe09c

Please sign in to comment.