From 2d4261607061233298a391f4b4d55e5c4542e887 Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Sun, 26 Mar 2023 10:08:28 +0800 Subject: [PATCH] feat: download indicidual chat import chats appends instead of replace existing chats --- src/assets/icons/JsonIcon.tsx | 20 +++++++++++++++++++ .../Chat/ChatContent/DownloadChat.tsx | 16 +++++++++++++++ .../ImportExportChat/ImportExportChat.tsx | 11 +++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/assets/icons/JsonIcon.tsx diff --git a/src/assets/icons/JsonIcon.tsx b/src/assets/icons/JsonIcon.tsx new file mode 100644 index 0000000..af8e6b5 --- /dev/null +++ b/src/assets/icons/JsonIcon.tsx @@ -0,0 +1,20 @@ +import React from 'react'; + +const JsonIcon = (props: React.SVGProps) => { + return ( + + + + ); +}; + +export default JsonIcon; diff --git a/src/components/Chat/ChatContent/DownloadChat.tsx b/src/components/Chat/ChatContent/DownloadChat.tsx index 64fb4c5..e7da03a 100644 --- a/src/components/Chat/ChatContent/DownloadChat.tsx +++ b/src/components/Chat/ChatContent/DownloadChat.tsx @@ -12,6 +12,9 @@ import { import ImageIcon from '@icon/ImageIcon'; import PdfIcon from '@icon/PdfIcon'; import MarkdownIcon from '@icon/MarkdownIcon'; +import JsonIcon from '@icon/JsonIcon'; + +import downloadFile from '@utils/downloadFile'; const DownloadChat = React.memo( ({ saveRef }: { saveRef: React.RefObject }) => { @@ -101,6 +104,19 @@ const DownloadChat = React.memo( Markdown + )} diff --git a/src/components/ImportExportChat/ImportExportChat.tsx b/src/components/ImportExportChat/ImportExportChat.tsx index cb19cc3..b191822 100644 --- a/src/components/ImportExportChat/ImportExportChat.tsx +++ b/src/components/ImportExportChat/ImportExportChat.tsx @@ -7,6 +7,7 @@ import downloadFile from '@utils/downloadFile'; import { getToday } from '@utils/date'; import PopupModal from '@components/PopupModal'; import { validateAndFixChats } from '@utils/chat'; +import { ChatInterface } from '@type/chat'; const ImportExportChat = () => { const { t } = useTranslation(); @@ -61,7 +62,15 @@ const ImportChat = () => { try { const parsedData = JSON.parse(data); if (validateAndFixChats(parsedData)) { - setChats(parsedData); + const prevChats = useStore.getState().chats; + if (prevChats) { + const updatedChats: ChatInterface[] = JSON.parse( + JSON.stringify(prevChats) + ); + setChats(parsedData.concat(updatedChats)); + } else { + setChats(parsedData); + } setAlert({ message: 'Succesfully imported!', success: true }); } else { setAlert({ message: 'Invalid chats data format', success: false });