mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 21:43: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 ImportChat = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const setChats = useStore.getState().setChats;
|
const setChats = useStore.getState().setChats;
|
||||||
|
const setFoldersName = useStore.getState().setFoldersName;
|
||||||
|
const setFoldersExpanded = useStore.getState().setFoldersExpanded;
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const [alert, setAlert] = useState<{
|
const [alert, setAlert] = useState<{
|
||||||
message: string;
|
message: string;
|
||||||
|
@ -62,6 +64,20 @@ const ImportChat = () => {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(data);
|
const parsedData = JSON.parse(data);
|
||||||
if (validateAndFixChats(parsedData)) {
|
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;
|
const prevChats = useStore.getState().chats;
|
||||||
if (prevChats) {
|
if (prevChats) {
|
||||||
const updatedChats: ChatInterface[] = JSON.parse(
|
const updatedChats: ChatInterface[] = JSON.parse(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import useStore from '@store/store';
|
||||||
|
|
||||||
import PopupModal from '@components/PopupModal';
|
import PopupModal from '@components/PopupModal';
|
||||||
import DeleteIcon from '@icon/DeleteIcon';
|
import DeleteIcon from '@icon/DeleteIcon';
|
||||||
|
@ -9,10 +10,14 @@ const ClearConversation = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const initialiseNewChat = useInitialiseNewChat();
|
const initialiseNewChat = useInitialiseNewChat();
|
||||||
|
const setFoldersName = useStore((state) => state.setFoldersName);
|
||||||
|
const setFoldersExpanded = useStore((state) => state.setFoldersExpanded);
|
||||||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
const handleConfirm = () => {
|
const handleConfirm = () => {
|
||||||
setIsModalOpen(false);
|
setIsModalOpen(false);
|
||||||
|
setFoldersName([]);
|
||||||
|
setFoldersExpanded([]);
|
||||||
initialiseNewChat();
|
initialiseNewChat();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue