import folders / clear folders

This commit is contained in:
Jing Hua 2023-03-28 01:06:58 +08:00
parent cb9f6fb3db
commit 29013bbd76
2 changed files with 21 additions and 0 deletions

View file

@ -43,6 +43,8 @@ const ImportExportChat = () => {
const ImportChat = () => {
const { t } = useTranslation();
const setChats = useStore.getState().setChats;
const setFoldersName = useStore.getState().setFoldersName;
const setFoldersExpanded = useStore.getState().setFoldersExpanded;
const inputRef = useRef<HTMLInputElement>(null);
const [alert, setAlert] = useState<{
message: string;
@ -62,6 +64,20 @@ const ImportChat = () => {
try {
const parsedData = JSON.parse(data);
if (validateAndFixChats(parsedData)) {
const parsedFolders: string[] = [];
parsedData.forEach((data) => {
if (data.folder && !parsedFolders.includes(data.folder))
parsedFolders.push(data.folder);
});
setFoldersName([
...parsedFolders,
...useStore.getState().foldersName,
]);
setFoldersExpanded([
...new Array(parsedFolders.length).fill(false),
...useStore.getState().foldersExpanded,
]);
const prevChats = useStore.getState().chats;
if (prevChats) {
const updatedChats: ChatInterface[] = JSON.parse(

View file

@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import useStore from '@store/store';
import PopupModal from '@components/PopupModal';
import DeleteIcon from '@icon/DeleteIcon';
@ -9,10 +10,14 @@ const ClearConversation = () => {
const { t } = useTranslation();
const initialiseNewChat = useInitialiseNewChat();
const setFoldersName = useStore((state) => state.setFoldersName);
const setFoldersExpanded = useStore((state) => state.setFoldersExpanded);
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const handleConfirm = () => {
setIsModalOpen(false);
setFoldersName([]);
setFoldersExpanded([]);
initialiseNewChat();
};