mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 17:33:59 +01:00
import folders / clear folders
This commit is contained in:
parent
cb9f6fb3db
commit
29013bbd76
|
@ -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(
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue