TagSpaces is an offline, open source, document manager with tagging support
Clear history should delete ai folder (#2217)
Stanimirec290f7b1b35
diff --git a/src/renderer/AppConfig.ts b/src/renderer/AppConfig.tsindex d784a59ae..42689551b 100644--- a/src/renderer/AppConfig.ts+++ b/src/renderer/AppConfig.ts@@ -36,5 +36,6 @@ AppConfig.maxLoops = 2;AppConfig.defaultFolderColor = 'gray';AppConfig.defaultCSSRadius = 10;AppConfig.defaultSpaceBetweenButtons = 10;+AppConfig.aiFolder = 'ai';export default AppConfig;diff --git a/src/renderer/components/chat/ChatView.tsx b/src/renderer/components/chat/ChatView.tsxindex 986aa15e7..1f2403238 100644--- a/src/renderer/components/chat/ChatView.tsx+++ b/src/renderer/components/chat/ChatView.tsx@@ -55,6 +55,7 @@ import React, {import { NativeTypes } from 'react-dnd-html5-backend';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';+import ConfirmDialog from '-/components/dialogs/ConfirmDialog';function ChatView() {const { t } = useTranslation();@@ -83,6 +84,8 @@ function ChatView() {//const txtInputRef = useRef<HTMLInputElement>(null);const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);+ const [isConfirmDialogOpened, setIsConfirmDialogOpened] =+ React.useState<boolean>(false);/*const getAddedText = (oldText, newText) => {if (newText.startsWith(oldText)) {return newText.slice(oldText.length);@@ -333,10 +336,26 @@ function ChatView() {handleClose={handleClose}handleSelectAll={handleSelectAll}handleCopy={handleCopy}- clearHistory={clearHistory}+ clearHistory={() => setIsConfirmDialogOpened(true)}saveAsHtml={saveAsHtml}saveAsMarkdown={saveAsMarkdown}/>+ <ConfirmDialog+ open={isConfirmDialogOpened}+ onClose={() => {+ setIsConfirmDialogOpened(false);+ }}+ title={t('core:titleConfirm')}+ content={t('core:confirmHistoryDeletion')}+ confirmCallback={(result) => {+ if (result) {+ clearHistory();+ }+ }}+ cancelDialogTID="cancelDeleteHistoryDialog"+ confirmDialogTID="confirmDeleteHistoryDialog"+ confirmDialogContentTID="confirmDeleteHistoryDialogContent"+ /></Grid2></Grid2><Grid2 size="grow" sx={{ padding: 0, overflowY: 'auto' }}>diff --git a/src/renderer/hooks/ChatProvider.tsx b/src/renderer/hooks/ChatProvider.tsxindex 0e00bbd9a..5f316d7e9 100644--- a/src/renderer/hooks/ChatProvider.tsx+++ b/src/renderer/hooks/ChatProvider.tsx@@ -242,10 +242,10 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {}function deleteHistory(): Promise<boolean> {- const historyFilePath = getHistoryFilePath();+ const historyFilePath = getHistoryMetaDir();if (currentLocation) {return currentLocation- .deleteFilePromise(historyFilePath, false)+ .deleteDirectoryPromise(historyFilePath, false).then(() => {chatHistoryItems.current = [];forceUpdate();@@ -492,7 +492,17 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {: AppConfig.dirSeparator;const metaFolder = getMetaDirectoryPath(openedEntry.path, dirSeparator);const fileName = name ? name : 'tsc.json';- return metaFolder + dirSeparator + 'ai' + dirSeparator + fileName;+ return (+ metaFolder + dirSeparator + AppConfig.aiFolder + dirSeparator + fileName+ );+ }++ function getHistoryMetaDir() {+ const dirSeparator = currentLocation+ ? currentLocation.getDirSeparator()+ : AppConfig.dirSeparator;+ const metaFolder = getMetaDirectoryPath(openedEntry.path, dirSeparator);+ return metaFolder + dirSeparator + AppConfig.aiFolder;}function saveHistoryItems(items?: ChatItem[]) {diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.jsonindex 0ba71d503..9a8cc873a 100644--- a/src/renderer/locales/en/core.json+++ b/src/renderer/locales/en/core.json@@ -910,5 +910,6 @@"generateInbound": "Find Inbound Links","reGenerateInbound": "Refresh Inbound Links","startDownload": "Start download",+ "confirmHistoryDeletion": "Do you want to delete chat History?","-": "-"}