Skip to content

TagSpaces is an offline, open source, document manager with tagging support

move ConfirmDialog in NotificationsContextProvider or separated (#2355)

Stanimirbfe1da080d66
diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsx
index 9c11e3436..391fcb02b 100644
--- a/src/renderer/components/EntryContainer.tsx
+++ b/src/renderer/components/EntryContainer.tsx
@@ -22,7 +22,6 @@ import EntryContainerTabs from '-/components/EntryContainerTabs';
import EntryContainerTitle from '-/components/EntryContainerTitle';
import FileView from '-/components/FileView';
import Tooltip from '-/components/Tooltip';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { useResolveConflictContext } from '-/components/dialogs/hooks/useResolveConflictContext';
import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
@@ -46,7 +45,6 @@ import { useTheme } from '@mui/material/styles';
import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';
import React, {
MutableRefObject,
- useCallback,
useEffect,
useMemo,
useReducer,
@@ -75,7 +73,7 @@ function EntryContainer() {
const { findLocation } = useCurrentLocationContext();
const { saveFileOpen } = useResolveConflictContext();
- const { showNotification } = useNotificationContext();
+ const { showNotification, openConfirmDialog } = useNotificationContext();
const tabIndex = useSelector(getEntryContainerTab);
const entryPropertiesHeight = useSelector(getEntryPropertiesHeight);
const keyBindings = useSelector(getKeyBindingObject);
@@ -95,14 +93,6 @@ function EntryContainer() {
// eslint-disable-next-line no-unused-vars
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
- const [
- isSaveBeforeCloseConfirmDialogOpened,
- setSaveBeforeCloseConfirmDialogOpened,
- ] = useState<boolean>(false);
- const [
- isSaveBeforeReloadConfirmDialogOpened,
- setSaveBeforeReloadConfirmDialogOpened,
- ] = useState<boolean>(false);
const isSavingInProgress = useRef<boolean>(false);
const fileViewer: MutableRefObject<HTMLIFrameElement> =
useRef<HTMLIFrameElement>(null);
@@ -359,8 +349,20 @@ function EntryContainer() {
const reloadDocument = () => {
if (openedEntry) {
if (isEditMode && fileChanged) {
- // openedEntry.changed) {
- setSaveBeforeReloadConfirmDialogOpened(true);
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:fileModified'),
+ (result) => {
+ if (result) {
+ startSavingFile();
+ } else {
+ setFileChanged(false);
+ }
+ },
+ 'cancelSaveBeforeCloseDialog',
+ 'confirmSaveBeforeCloseDialog',
+ 'confirmDialogContent',
+ );
} else {
setEditMode(false);
reloadOpenedFile();
@@ -374,7 +376,22 @@ function EntryContainer() {
event.stopPropagation();
}
if (openedEntry && fileChanged && isEditMode) {
- setSaveBeforeCloseConfirmDialogOpened(true);
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:saveFileBeforeClosingFile'),
+ (result) => {
+ if (result) {
+ startSavingFile();
+ } else {
+ closeFile();
+ isSavingInProgress.current = false;
+ setFileChanged(false);
+ }
+ },
+ 'cancelSaveBeforeCloseDialog',
+ 'confirmSaveBeforeCloseDialog',
+ 'confirmDialogContent',
+ );
} else {
closeFile();
}
@@ -591,51 +608,6 @@ function EntryContainer() {
/>
)}
</div>
- {isSaveBeforeCloseConfirmDialogOpened && (
- <ConfirmDialog
- open={isSaveBeforeCloseConfirmDialogOpened}
- onClose={() => {
- setSaveBeforeCloseConfirmDialogOpened(false);
- }}
- title={t('core:confirm')}
- content={t('core:saveFileBeforeClosingFile')}
- confirmCallback={(result) => {
- if (result) {
- startSavingFile();
- } else {
- closeFile();
- setSaveBeforeCloseConfirmDialogOpened(false);
- isSavingInProgress.current = false;
- setFileChanged(false);
- }
- }}
- cancelDialogTID="cancelSaveBeforeCloseDialog"
- confirmDialogTID="confirmSaveBeforeCloseDialog"
- confirmDialogContentTID="confirmDialogContent"
- />
- )}
- {isSaveBeforeReloadConfirmDialogOpened && (
- <ConfirmDialog
- open={isSaveBeforeReloadConfirmDialogOpened}
- onClose={() => {
- setSaveBeforeReloadConfirmDialogOpened(false);
- }}
- title={t('core:confirm')}
- content="File was modified, do you want to save the changes?"
- confirmCallback={(result) => {
- if (result) {
- setSaveBeforeReloadConfirmDialogOpened(false);
- startSavingFile();
- } else {
- setSaveBeforeReloadConfirmDialogOpened(false);
- setFileChanged(false);
- }
- }}
- cancelDialogTID="cancelSaveBeforeCloseDialog"
- confirmDialogTID="confirmSaveBeforeCloseDialog"
- confirmDialogContentTID="confirmDialogContent"
- />
- )}
</GlobalHotKeys>
);
}
diff --git a/src/renderer/components/EntryContainerMenu.tsx b/src/renderer/components/EntryContainerMenu.tsx
index 47a37f841..7df76c2ea 100644
--- a/src/renderer/components/EntryContainerMenu.tsx
+++ b/src/renderer/components/EntryContainerMenu.tsx
@@ -13,7 +13,6 @@ import {
ReloadIcon,
} from '-/components/CommonIcons';
import TsMenuList from '-/components/TsMenuList';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import MenuKeyBinding from '-/components/menus/MenuKeyBinding';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useFullScreenContext } from '-/hooks/useFullScreenContext';
@@ -37,9 +36,9 @@ import {
MenuItem,
} from '@mui/material';
import { extractDirectoryName } from '@tagspaces/tagspaces-common/paths';
-import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
interface Props {
anchorEl: null | HTMLElement;
@@ -71,13 +70,36 @@ function EntryContainerMenu(props: Props) {
const keyBindings = useSelector(getKeyBindingObject);
const { currentLocation } = useCurrentLocationContext();
const { deleteFile, downloadFsEntry } = useIOActionsContext();
- //const { showNotification } = useNotificationContext();
+ const { openConfirmDialog } = useNotificationContext();
const desktopMode = useSelector(isDesktopMode);
const warningOpeningFilesExternally = useSelector(
getWarningOpeningFilesExternally,
);
- const [isDeleteEntryModalOpened, setDeleteEntryModalOpened] =
- useState<boolean>(false);
+
+ function setDeleteEntryModalOpened() {
+ const title = openedEntry.isFile
+ ? t('core:deleteConfirmationTitle')
+ : t('core:deleteDirectory');
+ const content = openedEntry.isFile
+ ? t('core:doYouWantToDeleteFile')
+ : t('core:deleteDirectoryContentConfirm', {
+ dirPath: entryName,
+ });
+
+ openConfirmDialog(
+ title,
+ content,
+ (result) => {
+ if (result) {
+ return deleteFile(openedEntry.path, openedEntry.uuid);
+ }
+ },
+ 'cancelDeleteTID',
+ 'confirmDeleteTID',
+ 'confirmDialogContentTID',
+ openedEntry.isFile && [entryName],
+ );
+ }
const navigateToFolder = () => {
if (openedEntry.isFile) {
@@ -216,7 +238,7 @@ function EntryContainerMenu(props: Props) {
data-tid="deleteEntryTID"
aria-label={t('core:deleteEntry')}
onClick={() => {
- setDeleteEntryModalOpened(true);
+ setDeleteEntryModalOpened();
handleClose();
}}
>
@@ -395,7 +417,7 @@ function EntryContainerMenu(props: Props) {
data-tid="deleteFolderTID"
aria-label={t('core:deleteDirectory')}
onClick={() => {
- setDeleteEntryModalOpened(true);
+ setDeleteEntryModalOpened();
handleClose();
}}
>
@@ -447,35 +469,6 @@ function EntryContainerMenu(props: Props) {
>
<TsMenuList sx={{ minWidth: 300 }}>{menuItems}</TsMenuList>
</Menu>
- {isDeleteEntryModalOpened && (
- <ConfirmDialog
- open={isDeleteEntryModalOpened}
- onClose={() => {
- setDeleteEntryModalOpened(false);
- }}
- title={
- openedEntry.isFile
- ? t('core:deleteConfirmationTitle')
- : t('core:deleteDirectory')
- }
- content={
- openedEntry.isFile
- ? t('core:doYouWantToDeleteFile')
- : t('core:deleteDirectoryContentConfirm', {
- dirPath: entryName,
- })
- }
- list={openedEntry.isFile && [entryName]}
- confirmCallback={(result) => {
- if (result) {
- return deleteFile(openedEntry.path, openedEntry.uuid);
- }
- }}
- cancelDialogTID="cancelSaveBeforeCloseDialog"
- confirmDialogTID="confirmSaveBeforeCloseDialog"
- confirmDialogContentTID="confirmDialogContent"
- />
- )}
</>
);
}
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsx
index 4ef8564c2..7c0aaab4e 100644
--- a/src/renderer/components/EntryProperties.tsx
+++ b/src/renderer/components/EntryProperties.tsx
@@ -171,7 +171,7 @@ function EntryProperties(props: Props) {
const { metaActions } = useEditedEntryMetaContext();
const { addTagsToFsEntry, removeTagsFromEntry } = useTaggingActionsContext();
const { findLocation } = useCurrentLocationContext();
- const { showNotification } = useNotificationContext();
+ const { showNotification, openConfirmDialog } = useNotificationContext();
const thumbDialogContext = Pro?.contextProviders?.ThumbDialogContext
? useContext<TS.ThumbDialogContextData>(
Pro.contextProviders.ThumbDialogContext,
@@ -197,14 +197,8 @@ function EntryProperties(props: Props) {
: '';
const [editName, setEditName] = useState<string>(undefined);
- const [isConfirmResetColorDialogOpened, setConfirmResetColorDialogOpened] =
- useState<boolean>(false);
- /* const [isFileThumbChooseDialogOpened, setFileThumbChooseDialogOpened] =
- useState<boolean>(false);*/
const [showSharingLinkDialog, setShowSharingLinkDialog] =
useState<boolean>(false);
- /* const [isBgndImgChooseDialogOpened, setBgndImgChooseDialogOpened] =
- useState<boolean>(false);*/
const [displayColorPicker, setDisplayColorPicker] = useState<boolean>(false);
const backgroundImage = useRef<string>('none');
@@ -978,7 +972,18 @@ function EntryProperties(props: Props) {
disabled={!Pro}
aria-label="clear"
onClick={() =>
- setConfirmResetColorDialogOpened(true)
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:confirmResetColor'),
+ (result) => {
+ if (result) {
+ handleChangeColor('transparent');
+ }
+ },
+ 'cancelConfirmResetColorDialog',
+ 'confirmConfirmResetColorDialog',
+ 'confirmResetColorDialogContent',
+ )
}
>
<ClearColorIcon />
@@ -1152,26 +1157,6 @@ function EntryProperties(props: Props) {
/>
</Grid>
</Grid>
- {isConfirmResetColorDialogOpened && (
- <ConfirmDialog
- open={isConfirmResetColorDialogOpened}
- onClose={() => {
- setConfirmResetColorDialogOpened(false);
- }}
- title={t('core:confirm')}
- content={t('core:confirmResetColor')}
- confirmCallback={(result) => {
- if (result) {
- handleChangeColor('transparent');
- } else {
- setConfirmResetColorDialogOpened(false);
- }
- }}
- cancelDialogTID="cancelConfirmResetColorDialog"
- confirmDialogTID="confirmConfirmResetColorDialog"
- confirmDialogContentTID="confirmResetColorDialogContent"
- />
- )}
{showSharingLinkDialog && (
<LinkGeneratorDialog
open={showSharingLinkDialog}
diff --git a/src/renderer/components/LocationManager.tsx b/src/renderer/components/LocationManager.tsx
index c1d4b4891..021b609f0 100644
--- a/src/renderer/components/LocationManager.tsx
+++ b/src/renderer/components/LocationManager.tsx
@@ -17,7 +17,6 @@
*/
import LocationView from '-/components/LocationView';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { useCreateEditLocationDialogContext } from '-/components/dialogs/hooks/useCreateEditLocationDialogContext';
import LocationContextMenu from '-/components/menus/LocationContextMenu';
import LocationManagerMenu from '-/components/menus/LocationManagerMenu';
@@ -28,7 +27,6 @@ import { TS } from '-/tagspaces.namespace';
import { Box, List } from '@mui/material';
import { useRef, useState } from 'react';
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
-import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
interface Props {
@@ -38,12 +36,9 @@ interface Props {
}
function LocationManager(props: Props) {
- const { t } = useTranslation();
const {
findLocation,
moveLocation,
- deleteLocation,
- selectedLocation,
setSelectedLocation,
locationDirectoryContextMenuAnchorEl,
} = useCurrentLocationContext();
@@ -51,8 +46,6 @@ function LocationManager(props: Props) {
const locations: TS.Location[] = useSelector(getLocations);
const fileInputRef = useRef<HTMLInputElement>(null);
- const [isDeleteLocationDialogOpened, setDeleteLocationDialogOpened] =
- useState<boolean>(false);
const [isExportLocationsDialogOpened, setExportLocationsDialogOpened] =
useState<boolean>(false);
const [importFile, setImportFile] = useState<File>(undefined);
@@ -126,11 +119,7 @@ function LocationManager(props: Props) {
openCreateEditLocationDialog();
}}
/>
- {locationDirectoryContextMenuAnchorEl && (
- <LocationContextMenu
- setDeleteLocationDialogOpened={setDeleteLocationDialogOpened}
- />
- )}
+ {locationDirectoryContextMenuAnchorEl && <LocationContextMenu />}
<List
data-tid="locationList"
style={{
@@ -169,9 +158,6 @@ function LocationManager(props: Props) {
locationID: location.uuid,
children: [],
}}
- setDeleteLocationDialogOpened={
- setDeleteLocationDialogOpened
- }
/>
</div>
)}
@@ -190,23 +176,6 @@ function LocationManager(props: Props) {
type="file"
onChange={handleFileInputChange}
/>
- {isDeleteLocationDialogOpened && (
- <ConfirmDialog
- open={isDeleteLocationDialogOpened}
- onClose={() => setDeleteLocationDialogOpened(false)}
- title={t('core:deleteLocationTitleAlert')}
- content={t('core:deleteLocationContentAlert', {
- locationName: selectedLocation ? selectedLocation.name : '',
- })}
- confirmCallback={(result) => {
- if (result && selectedLocation) {
- deleteLocation(selectedLocation.uuid);
- }
- }}
- cancelDialogTID="cancelDeleteLocationDialog"
- confirmDialogTID="confirmDeleteLocationDialog"
- />
- )}
{ExportLocationsDialog && isExportLocationsDialogOpened && (
<ExportLocationsDialog
open={isExportLocationsDialogOpened}
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsx
index 0d509e092..ad086d354 100644
--- a/src/renderer/components/LocationView.tsx
+++ b/src/renderer/components/LocationView.tsx
@@ -61,7 +61,6 @@ import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
interface Props {
location: SubFolder;
hideDrawer?: () => void;
- setDeleteLocationDialogOpened: (open: boolean) => void;
}
function LocationView(props: Props) {
diff --git a/src/renderer/components/TagLibrary.tsx b/src/renderer/components/TagLibrary.tsx
index 4fbe5d809..61a929170 100644
--- a/src/renderer/components/TagLibrary.tsx
+++ b/src/renderer/components/TagLibrary.tsx
@@ -23,7 +23,6 @@ import TagContainerDnd from '-/components/TagContainerDnd';
import TagGroupContainer from '-/components/TagGroupContainer';
import TagGroupTitleDnD from '-/components/TagGroupTitleDnD';
import TsIconButton from '-/components/TsIconButton';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import CreateTagGroupDialog from '-/components/dialogs/CreateTagGroupDialog';
import CreateTagsDialog from '-/components/dialogs/CreateTagsDialog';
import EditTagDialog from '-/components/dialogs/EditTagDialog';
@@ -53,6 +52,7 @@ import React, { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import CustomDragLayer from '-/components/CustomDragLayer';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
interface Props {
style?: any;
@@ -64,7 +64,6 @@ function TagLibrary(props: Props) {
const {
createTagGroup,
removeTagGroup,
- deleteTag,
changeTagOrder,
moveTag,
moveTagGroup,
@@ -72,6 +71,7 @@ function TagLibrary(props: Props) {
const { selectedEntries } = useSelectedEntriesContext();
const { findLocation } = useCurrentLocationContext();
const { tagGroups } = useEditedTagLibraryContext();
+ const { openConfirmDialog } = useNotificationContext();
const dispatch: AppDispatch = useDispatch();
const tagBackgroundColor = useSelector(getTagColor);
const tagTextColor = useSelector(getTagTextColor);
@@ -93,14 +93,10 @@ function TagLibrary(props: Props) {
useState<boolean>(false);
const [isEditTagGroupDialogOpened, setIsEditTagGroupDialogOpened] =
useState<boolean>(false);
- const [isDeleteTagGroupDialogOpened, setIsDeleteTagGroupDialogOpened] =
- useState<boolean>(false);
const [isCreateTagDialogOpened, setIsCreateTagDialogOpened] =
useState<boolean>(false);
const [isEditTagDialogOpened, setIsEditTagDialogOpened] =
useState<boolean>(false);
- const [isDeleteTagDialogOpened, setIsDeleteTagDialogOpened] =
- useState<boolean>(false);
const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);
/*const firstRender = useFirstRender();
@@ -196,7 +192,19 @@ function TagLibrary(props: Props) {
};
const showDeleteTagGroupDialog = () => {
- setIsDeleteTagGroupDialogOpened(true);
+ openConfirmDialog(
+ t('core:deleteTagGroup'),
+ t('core:deleteTagGroupContentConfirm', {
+ tagGroup: selectedTagGroupEntry ? selectedTagGroupEntry.title : '',
+ }),
+ (result) => {
+ if (result && selectedTagGroupEntry) {
+ removeTagGroup(selectedTagGroupEntry.uuid);
+ }
+ },
+ 'cancelDeleteTagGroupDialog',
+ 'confirmDeleteTagGroupDialog',
+ );
setTagGroupMenuAnchorEl(null);
};
@@ -258,12 +266,6 @@ function TagLibrary(props: Props) {
);
};
- function confirmDeleteTag() {
- if (selectedTag && selectedTagGroupEntry) {
- deleteTag(selectedTag.title, selectedTagGroupEntry.uuid);
- }
- }
-
const { reduceHeightBy } = props;
const allTags = getAllTags(tagGroups);
@@ -298,23 +300,6 @@ function TagLibrary(props: Props) {
)
}
/>
- {isDeleteTagGroupDialogOpened && (
- <ConfirmDialog
- open={isDeleteTagGroupDialogOpened}
- onClose={() => setIsDeleteTagGroupDialogOpened(false)}
- title={t('core:deleteTagGroup')}
- content={t('core:deleteTagGroupContentConfirm', {
- tagGroup: selectedTagGroupEntry ? selectedTagGroupEntry.title : '',
- })}
- confirmCallback={(result) => {
- if (result && selectedTagGroupEntry) {
- removeTagGroup(selectedTagGroupEntry.uuid);
- }
- }}
- cancelDialogTID="cancelDeleteTagGroupDialog"
- confirmDialogTID="confirmDeleteTagGroupDialog"
- />
- )}
{isCreateTagGroupDialogOpened && (
<CreateTagGroupDialog
open={isCreateTagGroupDialogOpened}
@@ -370,7 +355,6 @@ function TagLibrary(props: Props) {
open={Boolean(tagMenuAnchorEl)}
onClose={() => setTagMenuAnchorEl(null)}
showEditTagDialog={() => setIsEditTagDialogOpened(true)}
- showDeleteTagDialog={() => setIsDeleteTagDialogOpened(true)}
selectedTag={selectedTag}
selectedTagGroupEntry={selectedTagGroupEntry}
/>
@@ -383,23 +367,6 @@ function TagLibrary(props: Props) {
selectedTag={selectedTag}
/>
)}
- {isDeleteTagDialogOpened && (
- <ConfirmDialog
- open={isDeleteTagDialogOpened}
- onClose={() => setIsDeleteTagDialogOpened(false)}
- title={t('core:deleteTagFromTagGroup')}
- content={t('core:deleteTagFromTagGroupContentConfirm', {
- tagName: selectedTag ? selectedTag.title : '',
- })}
- confirmCallback={(result) => {
- if (result) {
- confirmDeleteTag();
- }
- }}
- cancelDialogTID="cancelDeleteTagDialogTagMenu"
- confirmDialogTID="confirmDeleteTagDialogTagMenu"
- />
- )}
<div
style={{
paddingTop: 0,
diff --git a/src/renderer/components/chat/ChatMenu.tsx b/src/renderer/components/chat/ChatMenu.tsx
index 93f84ca71..39a69602f 100644
--- a/src/renderer/components/chat/ChatMenu.tsx
+++ b/src/renderer/components/chat/ChatMenu.tsx
@@ -24,13 +24,15 @@ import CopyIcon from '@mui/icons-material/FileCopy';
import HtmlIcon from '@mui/icons-material/Html';
import RttIcon from '@mui/icons-material/Rtt';
import { DeleteIcon } from '-/components/CommonIcons';
+import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
+import { useChatContext } from '-/hooks/useChatContext';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
interface ChatMenuProps {
anchorEl: null | HTMLElement;
handleClose: () => void;
handleSelectAll: () => void;
handleCopy: () => void;
- clearHistory: () => void;
saveAsHtml: () => void;
saveAsMarkdown: () => void;
}
@@ -42,11 +44,28 @@ function ChatMenu(props: ChatMenuProps) {
handleClose,
handleSelectAll,
handleCopy,
- clearHistory,
saveAsHtml,
saveAsMarkdown,
} = props;
+ const { deleteHistory } = useChatContext();
+ const { openConfirmDialog } = useNotificationContext();
+
+ const clearHistory = () => {
+ handleClose();
+ openConfirmDialog(
+ t('core:titleConfirm'),
+ t('core:confirmHistoryDeletion'),
+ (result) => {
+ if (result) {
+ deleteHistory();
+ }
+ },
+ 'cancelDeleteHistoryDialog',
+ 'confirmDeleteHistoryDialog',
+ 'confirmDeleteHistoryDialogContent',
+ );
+ };
return (
<Menu
anchorEl={anchorEl}
diff --git a/src/renderer/components/chat/ChatView.tsx b/src/renderer/components/chat/ChatView.tsx
index dce01952c..f1c5426a4 100644
--- a/src/renderer/components/chat/ChatView.tsx
+++ b/src/renderer/components/chat/ChatView.tsx
@@ -25,7 +25,6 @@ import ChatDndTargetFile from '-/components/chat/ChatDndTargetFile';
import ChatMenu from '-/components/chat/ChatMenu';
import { AIProvider, ChatMode } from '-/components/chat/ChatTypes';
import SelectChatModel from '-/components/chat/SelectChatModel';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { OllamaIcon } from '-/components/dialogs/components/Ollama';
import ChatMdEditor from '-/components/md/ChatMdEditor';
import { CrepeRef } from '-/components/md/useCrepeHandler';
@@ -60,7 +59,6 @@ function ChatView() {
changeCurrentModel,
setModel,
currentModel,
- deleteHistory,
isTyping,
cancelMessage,
} = useChatContext();
@@ -75,8 +73,6 @@ 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);
@@ -148,12 +144,12 @@ function ChatView() {
});
};
- const handleChangeMode = (event: ChangeEvent<HTMLInputElement>) => {
+ /*const handleChangeMode = (event: ChangeEvent<HTMLInputElement>) => {
currentMode.current = event.target.value
? (event.target.value as ChatMode)
: undefined;
forceUpdate();
- };
+ };*/
const handleChatMessage = () => {
//isTyping.current = true;
@@ -216,11 +212,6 @@ function ChatView() {
}
};
- const clearHistory = () => {
- setAnchorEl(null);
- deleteHistory();
- };
-
const saveAsHtml = () => {
setAnchorEl(null);
if (milkdownDivRef.current) {
@@ -296,26 +287,9 @@ function ChatView() {
handleClose={handleClose}
handleSelectAll={handleSelectAll}
handleCopy={handleCopy}
- 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"
- />
</Grid>
</Grid>
<Grid size="grow" sx={{ padding: 0, overflowY: 'auto' }}>
diff --git a/src/renderer/components/chat/SelectChatModel.tsx b/src/renderer/components/chat/SelectChatModel.tsx
index c976975e4..5eb08807e 100644
--- a/src/renderer/components/chat/SelectChatModel.tsx
+++ b/src/renderer/components/chat/SelectChatModel.tsx
@@ -21,7 +21,6 @@ import TsIconButton from '-/components/TsIconButton';
import TsSelect from '-/components/TsSelect';
import { AIProvider } from '-/components/chat/ChatTypes';
import { getOllamaModels } from '-/components/chat/OllamaClient';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { useChatContext } from '-/hooks/useChatContext';
import { getDefaultAIProvider } from '-/reducers/settings';
import DownloadIcon from '@mui/icons-material/Download';
@@ -32,6 +31,7 @@ import { ModelResponse } from 'ollama';
import { ChangeEvent, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
interface Props {
id?: string;
@@ -47,10 +47,9 @@ function SelectChatModel(props: Props) {
const { id, label, aiProvider, chosenModel, handleChangeModel, disabled } =
props;
const { removeModel, getOllamaClient, models } = useChatContext();
+ const { openConfirmDialog } = useNotificationContext();
const defaultAiProvider: AIProvider = useSelector(getDefaultAIProvider);
- const [isCustomModelPromptDialogOpened, setCustomModelPromptDialogOpened] =
- useState(false);
const [installedModels, setModels] = useState(
aiProvider?.id === defaultAiProvider?.id ? models : [],
);
@@ -196,7 +195,23 @@ function SelectChatModel(props: Props) {
const changeModel = (event: ChangeEvent<HTMLInputElement>) => {
if (event.target.value === 'customModel') {
- setCustomModelPromptDialogOpened(true);
+ openConfirmDialog(
+ t('core:downloadChatModel'),
+ undefined,
+ (result) => {
+ if (result && typeof result === 'string') {
+ handleChangeModel(result);
+ }
+ },
+ 'cancelInstallCustomModel',
+ 'confirmInstallCustomModel',
+ 'confirmCustomModelContent',
+ undefined,
+ t('core:model'),
+ 'E.g.: llama3.2:1b, further models available on ollama.com/search',
+ t('core:startDownload'),
+ t('core:cancel'),
+ );
} else {
handleChangeModel(event.target.value);
}
@@ -283,30 +298,6 @@ function SelectChatModel(props: Props) {
{t('core:installCustomModel')}
</MenuItem>
</TsSelect>
- <ConfirmDialog
- prompt={t('core:model')}
- open={isCustomModelPromptDialogOpened}
- onClose={() => {
- setCustomModelPromptDialogOpened(false);
- }}
- title={t('core:downloadChatModel')}
- helpText={
- 'E.g.: llama3.2:1b, further models available on ollama.com/search'
- }
- // content={t('core:chooseModel')}
- confirmCallback={(result) => {
- if (result && typeof result === 'string') {
- handleChangeModel(result);
- } else {
- setCustomModelPromptDialogOpened(false);
- }
- }}
- cancelDialogTID="cancelInstallCustomModel"
- confirmDialogTID="confirmInstallCustomModel"
- confirmDialogContentTID="confirmCustomModelContent"
- customConfirmText={t('core:startDownload')}
- customCancelText={t('core:cancel')}
- />
</>
);
}
diff --git a/src/renderer/components/dialogs/ConfirmDialog.tsx b/src/renderer/components/dialogs/ConfirmDialog.tsx
index 1293624a1..657032a1b 100644
--- a/src/renderer/components/dialogs/ConfirmDialog.tsx
+++ b/src/renderer/components/dialogs/ConfirmDialog.tsx
@@ -44,7 +44,7 @@ interface Props {
confirmDialogContentTID?: string;
prompt?: string;
helpText?: string;
- list: Array<string>;
+ list: string[];
confirmCallback: (result: boolean | string) => void;
onClose: () => void;
}
@@ -53,11 +53,17 @@ function ConfirmDialog(props: Props) {
const {
open,
onClose,
+ title,
+ content,
confirmCallback,
prompt,
helpText,
customCancelText,
customConfirmText,
+ list,
+ confirmDialogContentTID,
+ cancelDialogTID,
+ confirmDialogTID,
} = props;
const { t } = useTranslation();
const [promptValue, setPromptValue] = useState<string>('');
@@ -78,15 +84,12 @@ function ConfirmDialog(props: Props) {
style={{ zIndex: 1301 }}
>
<DialogTitle style={{ cursor: 'move' }} id="draggable-dialog-title">
- {props.title}
+ {title}
<DialogCloseButton testId="closeConfirmTID" onClose={onClose} />
</DialogTitle>
<DialogContent>
- <DialogContentText
- data-tid={props.confirmDialogContentTID}
- component="span"
- >
- {props.content}
+ <DialogContentText data-tid={confirmDialogContentTID} component="span">
+ {content}
{prompt && (
<TsTextField
fullWidth
@@ -96,9 +99,9 @@ function ConfirmDialog(props: Props) {
placeholder={prompt}
/>
)}
- {props.list && (
+ {list && (
<List dense>
- {props.list.map((listItem) => (
+ {list.map((listItem) => (
<ListItem key={listItem.toString()}>
<ListItemIcon>
<BulletIcon />
@@ -111,16 +114,10 @@ function ConfirmDialog(props: Props) {
</DialogContentText>
</DialogContent>
<TsDialogActions>
- <TsButton
- onClick={() => onConfirm(false)}
- data-tid={props.cancelDialogTID}
- >
+ <TsButton onClick={() => onConfirm(false)} data-tid={cancelDialogTID}>
{customCancelText ? customCancelText : t('core:no')}
</TsButton>
- <TsButton
- data-tid={props.confirmDialogTID}
- onClick={() => onConfirm(true)}
- >
+ <TsButton data-tid={confirmDialogTID} onClick={() => onConfirm(true)}>
{customConfirmText ? customConfirmText : t('core:yes')}
</TsButton>
</TsDialogActions>
diff --git a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx b/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
index 55094c05d..97c129e36 100644
--- a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
+++ b/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
@@ -25,7 +25,6 @@ import TsButton from '-/components/TsButton';
import TsIconButton from '-/components/TsIconButton';
import TsSelect from '-/components/TsSelect';
import TsTextField from '-/components/TsTextField';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import MaxLoopsSelect from '-/components/dialogs/MaxLoopsSelect';
import ObjectStoreForm from '-/components/dialogs/components/ObjectStoreForm';
import TsDialogActions from '-/components/dialogs/components/TsDialogActions';
@@ -85,7 +84,7 @@ interface Props {
function CreateEditLocationDialog(props: Props) {
const { t } = useTranslation();
- const { showNotification } = useNotificationContext();
+ const { showNotification, openConfirmDialog } = useNotificationContext();
const { createLocationIndex } = useLocationIndexContext();
const { loadLocationDataPromise } = useTagGroupsLocationContext();
const { addLocation, editLocation, selectedLocation, findLocation } =
@@ -99,8 +98,6 @@ function CreateEditLocationDialog(props: Props) {
const [showSecretAccessKey, setShowSecretAccessKey] =
useState<boolean>(false);
const [showEncryptionKey, setShowEncryptionKey] = useState<boolean>(false);
- const [isConfirmEncryptionChanged, setConfirmEncryptionChanged] =
- useState<boolean>(false);
const [showPassword, setShowPassword] = useState<boolean>(false);
const [errorTextPath, setErrorTextPath] = useState<boolean>(false);
const [errorTextName, setErrorTextName] = useState<boolean>(false);
@@ -236,11 +233,6 @@ function CreateEditLocationDialog(props: Props) {
const [isIgnorePatternDialogOpen, setIgnorePatternDialogOpen] =
useState<boolean>(false);
- const [
- isFullTextIndexConfirmDialogOpened,
- setFullTextIndexConfirmDialogOpened,
- ] = useState<boolean>(false);
-
const firstRender = useFirstRender();
function changeMaxIndexAge(ageInMinutes) {
@@ -390,7 +382,18 @@ function CreateEditLocationDialog(props: Props) {
selectedLocation &&
encryptionKey !== selectedLocation.encryptionKey
) {
- setConfirmEncryptionChanged(true);
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:confirmEncryptionChanged'),
+ (result) => {
+ if (result) {
+ onConfirm();
+ }
+ },
+ 'cancelConfirmEncryptionChanged',
+ 'confirmConfirmEncryptionChanged',
+ 'confirmConfirmEncryptionChangedContent',
+ );
} else {
onConfirm();
}
@@ -630,24 +633,6 @@ function CreateEditLocationDialog(props: Props) {
padding: 8,
}}
>
- <ConfirmDialog
- open={isConfirmEncryptionChanged}
- onClose={() => {
- setConfirmEncryptionChanged(false);
- }}
- title={t('core:confirm')}
- content={t('core:confirmEncryptionChanged')}
- confirmCallback={(result) => {
- if (result) {
- onConfirm();
- } else {
- setConfirmEncryptionChanged(false);
- }
- }}
- cancelDialogTID="cancelConfirmEncryptionChanged"
- confirmDialogTID="confirmConfirmEncryptionChanged"
- confirmDialogContentTID="confirmConfirmEncryptionChangedContent"
- />
{selectedLocation && (
<>
<Typography
@@ -727,7 +712,20 @@ function CreateEditLocationDialog(props: Props) {
onChange={(event: ChangeEvent<HTMLInputElement>) => {
setFullTextIndex(event.target.checked);
if (event.target.checked) {
- setFullTextIndexConfirmDialogOpened(true);
+ if (selectedLocation) {
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:fullTextIndexRegenerate'),
+ (result) => {
+ if (result) {
+ createLocationIndex(selectedLocation);
+ }
+ },
+ 'cancelReIndexDialogTID',
+ 'confirmReIndexDialogTID',
+ 'confirmDialogContentTID',
+ );
+ }
}
}}
/>
@@ -762,26 +760,6 @@ function CreateEditLocationDialog(props: Props) {
}
/>
)}
- {isFullTextIndexConfirmDialogOpened && selectedLocation && (
- <ConfirmDialog
- open={isFullTextIndexConfirmDialogOpened}
- onClose={() => {
- setFullTextIndexConfirmDialogOpened(false);
- }}
- title={t('core:confirm')}
- content={t('core:fullTextIndexRegenerate')}
- confirmCallback={(result) => {
- if (result) {
- createLocationIndex(selectedLocation);
- } else {
- setFullTextIndexConfirmDialogOpened(false);
- }
- }}
- cancelDialogTID="cancelSaveBeforeCloseDialog"
- confirmDialogTID="confirmSaveBeforeCloseDialog"
- confirmDialogContentTID="confirmDialogContent"
- />
- )}
<FormControlLabel
disabled={
!Pro ||
diff --git a/src/renderer/components/dialogs/SettingsDialog.tsx b/src/renderer/components/dialogs/SettingsDialog.tsx
index 6982ca642..4d7f54961 100644
--- a/src/renderer/components/dialogs/SettingsDialog.tsx
+++ b/src/renderer/components/dialogs/SettingsDialog.tsx
@@ -16,7 +16,6 @@
*
*/
-import AppConfig from '-/AppConfig';
import {
AIIcon,
AdvancedSettingsIcon,
@@ -28,7 +27,6 @@ import {
import DraggablePaper from '-/components/DraggablePaper';
import { BetaLabel } from '-/components/HelperComponents';
import TsButton from '-/components/TsButton';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import SettingsAI from '-/components/dialogs/components/SettingsAI';
import SettingsAdvanced from '-/components/dialogs/components/SettingsAdvanced';
import SettingsExtensions from '-/components/dialogs/components/SettingsExtensions';
@@ -37,9 +35,7 @@ import SettingsGeneral from '-/components/dialogs/components/SettingsGeneral';
import SettingsKeyBindings from '-/components/dialogs/components/SettingsKeyBindings';
import TsDialogActions from '-/components/dialogs/components/TsDialogActions';
import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';
-import { isDesktopMode } from '-/reducers/settings';
import { openURLExternally } from '-/services/utils-io';
-import { clearAllURLParams } from '-/utils/dom';
import Dialog from '@mui/material/Dialog';
import DialogContent from '@mui/material/DialogContent';
import Paper from '@mui/material/Paper';
@@ -50,7 +46,6 @@ import useMediaQuery from '@mui/material/useMediaQuery';
import Links from 'assets/links';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { useSelector } from 'react-redux';
interface Props {
open: boolean;
@@ -61,9 +56,7 @@ interface Props {
function SettingsDialog(props: Props) {
const { t } = useTranslation();
const [currentTab, setCurrentTab] = useState<number>(0);
- const desktopMode = useSelector(isDesktopMode);
- const [isResetSettingsDialogOpened, setIsResetSettingsDialogOpened] =
- useState<boolean>(false);
+ // const desktopMode = useSelector(isDesktopMode);
const { open, onClose } = props;
const theme = useTheme();
const smallScreen = useMediaQuery(theme.breakpoints.down('md'));
@@ -182,38 +175,9 @@ function SettingsDialog(props: Props) {
{currentTab === 1 && <SettingsFileTypes />}
{currentTab === 2 && <SettingsKeyBindings />}
{currentTab === 3 && <SettingsExtensions />}
- {currentTab === 4 && (
- <SettingsAdvanced
- showResetSettings={setIsResetSettingsDialogOpened}
- />
- )}
+ {currentTab === 4 && <SettingsAdvanced />}
{currentTab === 5 && <SettingsAI closeSettings={onClose} />}
</div>
- {isResetSettingsDialogOpened && (
- <ConfirmDialog
- open={isResetSettingsDialogOpened}
- onClose={() => {
- setIsResetSettingsDialogOpened(false);
- }}
- title="Confirm"
- content={t('core:confirmResetSettings')}
- confirmCallback={(result) => {
- if (result) {
- clearAllURLParams();
- localStorage.clear();
- // eslint-disable-next-line no-restricted-globals
- if (AppConfig.isElectron) {
- window.electronIO.ipcRenderer.sendMessage('reloadWindow');
- } else {
- window.location.reload();
- }
- }
- }}
- cancelDialogTID="cancelResetSettingsDialogTID"
- confirmDialogTID="confirmResetSettingsDialogTID"
- confirmDialogContentTID="confirmResetSettingsDialogContentTID"
- />
- )}
</DialogContent>
);
diff --git a/src/renderer/components/dialogs/components/SettingsAdvanced.tsx b/src/renderer/components/dialogs/components/SettingsAdvanced.tsx
index a80f42aa6..8980ca844 100644
--- a/src/renderer/components/dialogs/components/SettingsAdvanced.tsx
+++ b/src/renderer/components/dialogs/components/SettingsAdvanced.tsx
@@ -25,7 +25,6 @@ import TsButton from '-/components/TsButton';
import TsIconButton from '-/components/TsIconButton';
import TsSelect from '-/components/TsSelect';
import TsTextField from '-/components/TsTextField';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import MapTileServerDialog from '-/components/dialogs/MapTileServerDialog';
import { historyKeys } from '-/hooks/HistoryContextProvider';
import { useHistoryContext } from '-/hooks/useHistoryContext';
@@ -52,22 +51,21 @@ import Switch from '@mui/material/Switch';
import React, { useEffect, useReducer, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
+import { clearAllURLParams } from '-/utils/dom';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
-interface Props {
- showResetSettings: (showDialog: boolean) => void;
-}
+interface Props {}
function SettingsAdvanced(props: Props) {
- const { showResetSettings } = props;
const { t } = useTranslation();
const { delAllHistory } = useHistoryContext();
+ const { openConfirmDialog } = useNotificationContext();
const dispatch: AppDispatch = useDispatch();
const settings = useSelector(getSettings);
const maxCollectedTag = useSelector(getMaxCollectedTag);
const tileServers: Array<TS.MapTileServer> = useSelector(getMapTileServers);
const devMode = useSelector(isDevMode);
const [tileServerDialog, setTileServerDialog] = useState<any>(undefined);
- const [confirmDialogKey, setConfirmDialogKey] = useState<null | string>(null);
const wsAlive = useRef<boolean>(null);
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
@@ -80,6 +78,23 @@ function SettingsAdvanced(props: Props) {
}
}, [settings.enableWS]);
+ function setConfirmDialogKey(key: string) {
+ if (key) {
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:confirm' + key + 'Deletion'),
+ (result) => {
+ if (result) {
+ delAllHistory(key);
+ }
+ },
+ 'cancelDelete' + key + 'Dialog',
+ 'confirmDelete' + key + 'Dialog',
+ 'confirmDelete' + key + 'DialogContent',
+ );
+ }
+ }
+
const handleEditTileServerClick = (event, tileServer, isDefault: boolean) => {
event.preventDefault();
event.stopPropagation();
@@ -123,7 +138,27 @@ function SettingsAdvanced(props: Props) {
<ListItem>
<TsButton
data-tid="resetSettingsTID"
- onClick={() => showResetSettings(true)}
+ onClick={() =>
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:confirmResetSettings'),
+ (result) => {
+ if (result) {
+ clearAllURLParams();
+ localStorage.clear();
+ // eslint-disable-next-line no-restricted-globals
+ if (AppConfig.isElectron) {
+ window.electronIO.ipcRenderer.sendMessage('reloadWindow');
+ } else {
+ window.location.reload();
+ }
+ }
+ },
+ 'cancelResetSettingsDialogTID',
+ 'confirmResetSettingsDialogTID',
+ 'confirmResetSettingsDialogContentTID',
+ )
+ }
color="secondary"
style={{ marginLeft: -7 }}
>
@@ -342,24 +377,6 @@ function SettingsAdvanced(props: Props) {
<MenuItem value={100}>100</MenuItem>
</TsSelect>
</ListItem>
- <ConfirmDialog
- open={confirmDialogKey !== null}
- onClose={() => {
- setConfirmDialogKey(null);
- }}
- title="Confirm"
- content={t('core:confirm' + confirmDialogKey + 'Deletion')}
- confirmCallback={(result) => {
- if (result) {
- delAllHistory(confirmDialogKey);
- }
- }}
- cancelDialogTID={'cancelDelete' + confirmDialogKey + 'Dialog'}
- confirmDialogTID={'confirmDelete' + confirmDialogKey + 'Dialog'}
- confirmDialogContentTID={
- 'confirmDelete' + confirmDialogKey + 'DialogContent'
- }
- />
<ListItem>
<ListItemText
primary={
diff --git a/src/renderer/components/dialogs/components/SettingsExtensions.tsx b/src/renderer/components/dialogs/components/SettingsExtensions.tsx
index 5a94282b3..973348bd6 100644
--- a/src/renderer/components/dialogs/components/SettingsExtensions.tsx
+++ b/src/renderer/components/dialogs/components/SettingsExtensions.tsx
@@ -20,7 +20,6 @@ import AppConfig from '-/AppConfig';
import InfoIcon from '-/components/InfoIcon';
import TsButton from '-/components/TsButton';
import TsIconButton from '-/components/TsIconButton';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUploadDialogContext';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useExtensionsContext } from '-/hooks/useExtensionsContext';
@@ -40,20 +39,40 @@ import Typography from '@mui/material/Typography';
import { ChangeEvent, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
function SettingsExtensions() {
const { t } = useTranslation();
const { extensions, removeExtension, enableExtension } =
useExtensionsContext();
+ const { openConfirmDialog } = useNotificationContext();
const { findLocalLocation } = useCurrentLocationContext();
const { uploadFilesAPI } = useIOActionsContext();
const { openFileUploadDialog } = useFileUploadDialogContext();
const fileInputRef = useRef<HTMLInputElement>(null);
- const [removeExtDialogOpened, setRemoveExtDialogOpened] =
- useState<TS.Extension>(undefined);
const devMode = useSelector(isDevMode);
const dispatch: AppDispatch = useDispatch();
+ function setRemoveExtDialogOpened(ext: TS.Extension) {
+ if (ext) {
+ openConfirmDialog(
+ t('core:removeExtension'),
+ t('core:removeExtensionTooltip', {
+ extensionName: ext.extensionName,
+ }),
+ (result) => {
+ if (result) {
+ dispatch(SettingsActions.removeSupportedFileTypes(ext.extensionId));
+ removeExtension(ext.extensionId);
+ }
+ },
+ 'cancelRemoveExtDialogTID',
+ 'confirmRemoveExtDialogTID',
+ 'confirmRemoveExtDialogContentTID',
+ );
+ }
+ }
+
const onUploadProgress = (progress, abort, fileName) => {
dispatch(AppActions.onUploadProgress(progress, abort, fileName));
};
@@ -192,29 +211,6 @@ function SettingsExtensions() {
</ListItem>
))}
</List>
- <ConfirmDialog
- open={removeExtDialogOpened !== undefined}
- onClose={() => setRemoveExtDialogOpened(undefined)}
- title={t('core:removeExtension')}
- content={t('core:removeExtensionTooltip', {
- extensionName: removeExtDialogOpened
- ? removeExtDialogOpened.extensionName
- : '',
- })}
- confirmCallback={(result) => {
- if (result) {
- dispatch(
- SettingsActions.removeSupportedFileTypes(
- removeExtDialogOpened.extensionId,
- ),
- );
- removeExtension(removeExtDialogOpened.extensionId);
- }
- }}
- cancelDialogTID="cancelRemoveExtDialogTID"
- confirmDialogTID="confirmRemoveExtDialogTID"
- confirmDialogContentTID="confirmRemoveExtDialogContentTID"
- />
{extensions &&
extensions.filter((ext) => ext.extensionExternal).length < 1 && (
<Typography variant="subtitle1">No extensions found</Typography>
diff --git a/src/renderer/components/dialogs/components/SettingsFileTypes.tsx b/src/renderer/components/dialogs/components/SettingsFileTypes.tsx
index c5a39cc29..301f18fa6 100644
--- a/src/renderer/components/dialogs/components/SettingsFileTypes.tsx
+++ b/src/renderer/components/dialogs/components/SettingsFileTypes.tsx
@@ -24,7 +24,6 @@ import TsIconButton from '-/components/TsIconButton';
import TsSelect from '-/components/TsSelect';
import TsTextField from '-/components/TsTextField';
import ColorPickerDialog from '-/components/dialogs/ColorPickerDialog';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { useExtensionsContext } from '-/hooks/useExtensionsContext';
import { AppDispatch } from '-/reducers/app';
import {
@@ -55,16 +54,16 @@ import {
TableVirtuoso,
TableVirtuosoHandle,
} from 'react-virtuoso';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
function SettingsFileTypes() {
const { t } = useTranslation();
const { extensions } = useExtensionsContext();
+ const { openConfirmDialog } = useNotificationContext();
const supportedFileTypes = useSelector(getSupportedFileTypes);
const items = useRef<Array<TS.FileTypes>>(supportedFileTypes);
const selectedItem = useRef<TS.FileTypes>(undefined);
const isValidationInProgress = useRef<boolean>(false);
- const [isConfirmDialogOpened, setIsConfirmDialogOpened] =
- useState<boolean>(false);
const [isColorPickerVisible, setColorPickerVisible] =
useState<boolean>(false);
const settingsFileTypeRef = useRef<TableVirtuosoHandle>(null);
@@ -267,7 +266,18 @@ function SettingsFileTypes() {
const onRemoveItem = (item) => {
selectedItem.current = item;
- setIsConfirmDialogOpened(true);
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:confirmFileTypeDeletion'),
+ (result) => {
+ if (result) {
+ removeItem(selectedItem.current);
+ }
+ },
+ 'cancelDeleteFileTypeDialog',
+ 'confirmDeleteFileTypeDialog',
+ 'confirmDeleteFileTypeDialogContent',
+ );
};
const removeItem = (itemForRemoval: any) => {
@@ -493,24 +503,6 @@ function SettingsFileTypes() {
{t('core:resetFileType')}
</TsButton>
)}
- {isConfirmDialogOpened && (
- <ConfirmDialog
- open={isConfirmDialogOpened}
- onClose={() => {
- setIsConfirmDialogOpened(false);
- }}
- title="Confirm"
- content={t('core:confirmFileTypeDeletion')}
- confirmCallback={(result) => {
- if (result) {
- removeItem(selectedItem.current);
- }
- }}
- cancelDialogTID="cancelDeleteFileTypeDialog"
- confirmDialogTID="confirmDeleteFileTypeDialog"
- confirmDialogContentTID="confirmDeleteFileTypeDialogContent"
- />
- )}
<TableVirtuoso
style={{
overflowX: 'auto',
diff --git a/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx
index 864bf4833..f37e2ceb8 100644
--- a/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx
@@ -16,11 +16,11 @@
*
*/
-import React, { createContext, useMemo, useReducer, useRef } from 'react';
+import React, { createContext, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { TS } from '-/tagspaces.namespace';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
type EntryExistDialogContextData = {
handleEntryExist: (
@@ -50,10 +50,7 @@ export const EntryExistDialogContextProvider = ({
}: EntryExistDialogContextProviderProps) => {
const { t } = useTranslation();
const { findLocation } = useCurrentLocationContext();
- const confirmOverride = useRef<() => void>(undefined);
- const entriesExistPath = useRef<string[]>([]);
-
- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
+ const { openConfirmDialog } = useNotificationContext();
async function handleEntryExist(
entries: TS.FileSystemEntry[],
@@ -104,14 +101,20 @@ export const EntryExistDialogContextProvider = ({
}
function openDialog(existPath: string[], confirmCallback: () => void) {
- confirmOverride.current = confirmCallback;
- entriesExistPath.current = existPath;
- forceUpdate();
- }
-
- function closeDialog() {
- entriesExistPath.current = [];
- forceUpdate();
+ if (existPath && existPath.length > 0) {
+ openConfirmDialog(
+ t('core:confirm'),
+ formatFileExist(existPath) + ' exist do you want to override it?',
+ (result) => {
+ if (result) {
+ confirmCallback();
+ }
+ },
+ 'cancelOverwriteByCopyMoveDialog',
+ 'confirmOverwriteByCopyMoveDialog',
+ 'confirmDialogContent',
+ );
+ }
}
function formatFileExist(entries) {
@@ -125,33 +128,11 @@ export const EntryExistDialogContextProvider = ({
return {
handleEntryExist: handleEntryExist,
openEntryExistDialog: openDialog,
- closeEntryExistDialog: closeDialog,
};
}, []);
return (
<EntryExistDialogContext.Provider value={context}>
- {entriesExistPath.current.length > 0 && (
- <ConfirmDialog
- open={true}
- onClose={() => {
- closeDialog();
- }}
- title={t('core:confirm')}
- content={
- formatFileExist(entriesExistPath.current) +
- ' exist do you want to override it?'
- }
- confirmCallback={(result) => {
- if (result) {
- confirmOverride.current();
- }
- }}
- cancelDialogTID="cancelOverwriteByCopyMoveDialog"
- confirmDialogTID="confirmOverwriteByCopyMoveDialog"
- confirmDialogContentTID="confirmDialogContent"
- />
- )}
{children}
</EntryExistDialogContext.Provider>
);
diff --git a/src/renderer/components/menus/EntryTagMenu.tsx b/src/renderer/components/menus/EntryTagMenu.tsx
index fa9808030..ae95700d7 100644
--- a/src/renderer/components/menus/EntryTagMenu.tsx
+++ b/src/renderer/components/menus/EntryTagMenu.tsx
@@ -151,20 +151,6 @@ function EntryTagMenu(props: Props) {
<Menu anchorEl={anchorEl} open={open} onClose={onClose}>
<TsMenuList>{menuItems}</TsMenuList>
</Menu>
- {/* <ConfirmDialog
- open={isDeleteTagDialogOpened}
- onClose={handleCloseDialogs}
- title={t('core:removeTag')}
- content={t('core:removeTagTooltip')}
- confirmCallback={(result) => {
- if (result) {
- confirmRemoveTag();
- }
- }}
- cancelDialogTID="cancelDeleteTagDialogTagMenu"
- confirmDialogTID="confirmRemoveTagFromFile"
- confirmDialogContentTID="confirmDialogContent"
- /> */}
</div>
);
}
diff --git a/src/renderer/components/menus/LocationContextMenu.tsx b/src/renderer/components/menus/LocationContextMenu.tsx
index 1b92dac28..0617218ce 100644
--- a/src/renderer/components/menus/LocationContextMenu.tsx
+++ b/src/renderer/components/menus/LocationContextMenu.tsx
@@ -42,18 +42,11 @@ import { locationType } from '@tagspaces/tagspaces-common/misc';
import { generateSharingLink } from '@tagspaces/tagspaces-common/paths';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { useTranslation } from 'react-i18next';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
-interface Props {
- //setEditLocationDialogOpened: (open: boolean) => void;
- setDeleteLocationDialogOpened: (open: boolean) => void;
- //closeLocationTree: () => void;
-}
+interface Props {}
function LocationContextMenu(props: Props) {
- const {
- setDeleteLocationDialogOpened,
- //closeLocationTree
- } = props;
const { t } = useTranslation();
const {
@@ -66,7 +59,9 @@ function LocationContextMenu(props: Props) {
locationDirectoryContextMenuAnchorEl,
setLocationDirectoryContextMenuAnchorEl,
getLocationPath,
+ deleteLocation,
} = useCurrentLocationContext();
+ const { openConfirmDialog } = useNotificationContext();
const { createLocationIndex } = useLocationIndexContext();
const { openCreateEditLocationDialog } = useCreateEditLocationDialogContext();
//const dispatch: AppDispatch = useDispatch();
@@ -120,7 +115,19 @@ function LocationContextMenu(props: Props) {
const showDeleteLocationDialog = () => {
setLocationDirectoryContextMenuAnchorEl(null);
- setDeleteLocationDialogOpened(true);
+ openConfirmDialog(
+ t('core:deleteLocationTitleAlert'),
+ t('core:deleteLocationContentAlert', {
+ locationName: selectedLocation ? selectedLocation.name : '',
+ }),
+ (result) => {
+ if (result && selectedLocation) {
+ deleteLocation(selectedLocation.uuid);
+ }
+ },
+ 'cancelDeleteLocationDialog',
+ 'confirmDeleteLocationDialog',
+ );
};
const showInFileManagerInt = () => {
diff --git a/src/renderer/components/menus/TagMenu.tsx b/src/renderer/components/menus/TagMenu.tsx
index 79c8c1c13..db72bb381 100644
--- a/src/renderer/components/menus/TagMenu.tsx
+++ b/src/renderer/components/menus/TagMenu.tsx
@@ -33,6 +33,8 @@ import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
+import React from 'react';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
interface Props {
anchorEl?: Element;
@@ -41,7 +43,6 @@ interface Props {
selectedTag?: TS.Tag;
selectedTagGroupEntry?: TS.TagGroup;
showEditTagDialog: () => void;
- showDeleteTagDialog: () => void;
}
function TagMenu(props: Props) {
@@ -50,16 +51,16 @@ function TagMenu(props: Props) {
selectedTagGroupEntry,
onClose,
showEditTagDialog,
- showDeleteTagDialog,
anchorEl,
open,
} = props;
const { t } = useTranslation();
const { selectedEntries } = useSelectedEntriesContext();
- const { addTags } = useTaggingActionsContext();
+ const { addTags, deleteTag } = useTaggingActionsContext();
const { currentLocation } = useCurrentLocationContext();
const { setSearchQuery } = useDirectoryContentContext();
+ const { openConfirmDialog } = useNotificationContext();
const maxSearchResults: number = useSelector(getMaxSearchResults);
const tagGroupReadOnly = selectedTagGroupEntry?.readOnly;
@@ -82,7 +83,21 @@ function TagMenu(props: Props) {
function openDeleteTagDialog() {
onClose();
- showDeleteTagDialog();
+ openConfirmDialog(
+ t('core:deleteTagFromTagGroup'),
+ t('core:deleteTagFromTagGroupContentConfirm', {
+ tagName: selectedTag ? selectedTag.title : '',
+ }),
+ (result) => {
+ if (result) {
+ if (selectedTag && selectedTagGroupEntry) {
+ deleteTag(selectedTag.title, selectedTagGroupEntry.uuid);
+ }
+ }
+ },
+ 'cancelDeleteTagDialogTagMenu',
+ 'confirmDeleteTagDialogTagMenu',
+ );
}
function applyTag() {
diff --git a/src/renderer/hooks/FilePropertiesContextProvider.tsx b/src/renderer/hooks/FilePropertiesContextProvider.tsx
index 58d22a9b7..ac257a12e 100644
--- a/src/renderer/hooks/FilePropertiesContextProvider.tsx
+++ b/src/renderer/hooks/FilePropertiesContextProvider.tsx
@@ -32,12 +32,10 @@ import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { TS } from '-/tagspaces.namespace';
import { useIOActionsContext } from '-/hooks/useIOActionsContext';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
type FilePropertiesContextData = {
description: string;
isDescriptionChanged: boolean;
- isSaveDescriptionConfirmOpened: boolean;
isEditMode: boolean;
setEditMode: (editMode: boolean) => void;
isEditDescriptionMode: boolean;
@@ -51,7 +49,6 @@ type FilePropertiesContextData = {
export const FilePropertiesContext = createContext<FilePropertiesContextData>({
description: undefined,
isDescriptionChanged: false,
- isSaveDescriptionConfirmOpened: false,
isEditMode: false,
setEditMode: () => {},
isEditDescriptionMode: undefined,
@@ -73,12 +70,11 @@ export const FilePropertiesContextProvider = ({
const { openedEntry, actuallyCloseFiles, openFsEntry } =
useOpenedEntryContext();
const { findLocation } = useCurrentLocationContext();
- const { showNotification } = useNotificationContext();
+ const { showNotification, openConfirmDialog } = useNotificationContext();
const { setDescriptionChange } = useIOActionsContext();
const lastOpenedFile = useRef<TS.OpenedEntry>({ ...openedEntry });
const isDescriptionChanged = useRef<boolean>(false);
- const isSaveDescriptionConfirmOpened = useRef<boolean>(false);
const [isEditMode, setIsEditMode] = useState<boolean>(false);
const [isEditDescriptionMode, setIsEditDescriptionMode] =
@@ -107,7 +103,7 @@ export const FilePropertiesContextProvider = ({
if (isDescriptionChanged.current) {
isDescriptionChanged.current = false;
// handle not saved changes
- isSaveDescriptionConfirmOpened.current = true;
+ setSaveDescriptionConfirmOpened(true);
} else {
lastOpenedFile.current = { ...openedEntry };
setIsEditMode(false);
@@ -126,8 +122,8 @@ export const FilePropertiesContextProvider = ({
if (isDescriptionChanged.current) {
isDescriptionChanged.current = false;
// handle not saved changes
- isSaveDescriptionConfirmOpened.current = true;
- forceUpdate();
+ setSaveDescriptionConfirmOpened(true);
+ //forceUpdate();
} else {
actuallyCloseFiles();
}
@@ -211,18 +207,63 @@ export const FilePropertiesContextProvider = ({
function setSaveDescriptionConfirmOpened(isOpened: boolean) {
if (!isOpened) {
isDescriptionChanged.current = false;
+ lastOpenedFile.current = { ...openedEntry };
setIsEditDescriptionMode(false);
+ return;
}
- lastOpenedFile.current = { ...openedEntry };
- isSaveDescriptionConfirmOpened.current = isOpened;
- forceUpdate();
+
+ // take a snapshot of the edited file so the confirm callback uses the current edited value
+ const fileSnapshot = {
+ ...lastOpenedFile.current,
+ meta: { ...lastOpenedFile.current?.meta },
+ };
+
+ openConfirmDialog(
+ t('core:confirm'),
+ t('core:saveDescriptionOnClosing'),
+ (result) => {
+ if (result) {
+ const location = findLocation(fileSnapshot.locationID);
+ if (!location || location.isReadOnly) {
+ showNotification(t('core:readonlyModeSave'));
+ return;
+ }
+ if (!Pro) {
+ showNotification(t('core:thisFunctionalityIsAvailableInPro'));
+ return;
+ }
+
+ setDescriptionChange(
+ fileSnapshot,
+ fileSnapshot.meta?.description,
+ ).then(() => {
+ // after saving, update refs and UI
+ // make lastOpenedFile correspond to currently opened entry (it may have changed)
+ lastOpenedFile.current = openedEntry
+ ? { ...openedEntry }
+ : fileSnapshot;
+ isDescriptionChanged.current = false;
+ setIsEditMode(false);
+ openFsEntry(fileSnapshot);
+ });
+ } else {
+ // user cancelled: discard changes and re-open the original entry
+ isDescriptionChanged.current = false;
+ lastOpenedFile.current = { ...openedEntry };
+ setIsEditDescriptionMode(false);
+ openFsEntry(openedEntry);
+ }
+ },
+ 'cancelSaveDescCloseDialog',
+ 'confirmSaveDescCloseDialog',
+ 'confirmDescDialogContent',
+ );
}
const context = useMemo(
() => ({
description: lastOpenedFile.current?.meta?.description,
isDescriptionChanged: isDescriptionChanged.current,
- isSaveDescriptionConfirmOpened: isSaveDescriptionConfirmOpened.current,
setSaveDescriptionConfirmOpened,
setDescription,
saveDescription,
@@ -238,32 +279,12 @@ export const FilePropertiesContextProvider = ({
lastOpenedFile.current,
isEditMode,
isEditDescriptionMode,
- isSaveDescriptionConfirmOpened.current,
],
);
return (
<FilePropertiesContext.Provider value={context}>
{children}
- <ConfirmDialog
- open={isSaveDescriptionConfirmOpened.current}
- onClose={() => setSaveDescriptionConfirmOpened(false)}
- title={t('core:confirm')}
- content={t('core:saveDescriptionOnClosing')}
- confirmCallback={(result) => {
- if (result) {
- saveDescription().then(() => {
- openFsEntry(openedEntry);
- });
- } else {
- setSaveDescriptionConfirmOpened(false);
- openFsEntry(openedEntry);
- }
- }}
- cancelDialogTID="cancelSaveDescCloseDialog"
- confirmDialogTID="confirmSaveDescCloseDialog"
- confirmDialogContentTID="confirmDescDialogContent"
- />
</FilePropertiesContext.Provider>
);
};
diff --git a/src/renderer/hooks/NotificationContextProvider.tsx b/src/renderer/hooks/NotificationContextProvider.tsx
index d22902436..6eaaddd10 100644
--- a/src/renderer/hooks/NotificationContextProvider.tsx
+++ b/src/renderer/hooks/NotificationContextProvider.tsx
@@ -16,7 +16,8 @@
*
*/
-import React, { createContext, useMemo, useState } from 'react';
+import React, { createContext, useMemo, useRef, useState } from 'react';
+import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
type NotificationStatus = {
visible: boolean;
@@ -27,6 +28,20 @@ type NotificationStatus = {
};
type NotificationContextData = {
+ openConfirmDialog: (
+ title: string,
+ description: string,
+ callback?: (result: boolean | string) => void,
+ cancelTID?: string,
+ confirmTID?: string,
+ confirmContentTID?: string,
+ list?: string[],
+ prompt?: string,
+ help?: string,
+ customConfirmText?: string,
+ customCancelText?: string,
+ ) => void;
+ closeConfirmDialog: () => void;
notificationStatus: NotificationStatus;
showNotification: (
text: string,
@@ -41,6 +56,8 @@ type NotificationContextData = {
};
export const NotificationContext = createContext<NotificationContextData>({
+ openConfirmDialog: undefined,
+ closeConfirmDialog: undefined,
notificationStatus: undefined,
showNotification: () => {},
hideNotifications: () => {},
@@ -56,6 +73,19 @@ export type NotificationContextProviderProps = {
export const NotificationContextProvider = ({
children,
}: NotificationContextProviderProps) => {
+ const [isConfirmDialogOpened, setConfirmDialogOpened] =
+ useState<boolean>(false);
+ const confirmTitle = useRef<string>('Confirm Dialog');
+ const confirmDescription = useRef<string>('');
+ const confirmCallback = useRef<(result: boolean | string) => void>(undefined);
+ const cancelDialogTID = useRef<string>('cancelDialogTID');
+ const confirmDialogTID = useRef<string>('confirmDialogTID');
+ const confirmDialogContentTID = useRef<string>('confirmDialogContentTID');
+ const listItems = useRef<string[]>(undefined);
+ const prompt = useRef<string>(undefined);
+ const help = useRef<string>(undefined);
+ const customConfirmText = useRef<string>(undefined);
+ const customCancelText = useRef<string>(undefined);
const [notificationStatus, setNotificationStatus] = useState<any>({
visible: false,
text: null,
@@ -64,6 +94,37 @@ export const NotificationContextProvider = ({
});
const [isGeneratingThumbs, setGeneratingThumbs] = useState<boolean>(false);
+ function openConfirmDialog(
+ title: string,
+ description: string,
+ callback = undefined,
+ cancelTID = 'cancelDialogTID',
+ confirmTID = 'confirmDialogTID',
+ confirmContentTID = 'confirmDialogContentTID',
+ list: string[] = undefined,
+ promptTxt: string = undefined,
+ helpTxt: string = undefined,
+ confirmText: string = undefined,
+ cancelText: string = undefined,
+ ) {
+ confirmTitle.current = title;
+ confirmDescription.current = description;
+ confirmCallback.current = callback;
+ cancelDialogTID.current = cancelTID;
+ confirmDialogTID.current = confirmTID;
+ confirmDialogContentTID.current = confirmContentTID;
+ listItems.current = list;
+ prompt.current = promptTxt;
+ customConfirmText.current = confirmText;
+ customCancelText.current = cancelText;
+ help.current = helpTxt;
+ setConfirmDialogOpened(true);
+ }
+
+ function closeConfirmDialog() {
+ setConfirmDialogOpened(false);
+ }
+
function showNotification(
text: string,
notificationType = 'default',
@@ -103,12 +164,29 @@ export const NotificationContextProvider = ({
setGeneratingThumbs,
showNotification,
hideNotifications,
+ openConfirmDialog,
+ closeConfirmDialog,
};
}, [notificationStatus, isGeneratingThumbs]);
return (
<NotificationContext.Provider value={context}>
{children}
+ <ConfirmDialog
+ open={isConfirmDialogOpened}
+ onClose={() => setConfirmDialogOpened(false)}
+ title={confirmTitle.current}
+ content={confirmDescription.current}
+ confirmCallback={confirmCallback.current}
+ cancelDialogTID={cancelDialogTID.current}
+ confirmDialogTID={confirmDialogTID.current}
+ confirmDialogContentTID={confirmDialogContentTID.current}
+ list={listItems.current}
+ prompt={prompt.current}
+ helpText={help.current}
+ customConfirmText={customConfirmText.current}
+ customCancelText={customCancelText.current}
+ />
</NotificationContext.Provider>
);
};
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index e1e0870e6..d87a4b927 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -17,7 +17,6 @@
*/
import AppConfig from '-/AppConfig';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
@@ -68,7 +67,6 @@ import React, {
useMemo,
useReducer,
useRef,
- useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
@@ -168,7 +166,7 @@ export const OpenedEntryContextProvider = ({
} = useDirectoryContentContext();
const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();
- const { showNotification } = useNotificationContext();
+ const { showNotification, openConfirmDialog } = useNotificationContext();
const { actions } = useEditedEntryContext();
const { metaActions } = useEditedEntryMetaContext();
const { saveFilePromise } = usePlatformFacadeContext();
@@ -182,8 +180,6 @@ export const OpenedEntryContextProvider = ({
const isEntryInFullWidth = useRef<boolean>(false);
const sharingLink = useRef<string>(undefined);
const sharingParentFolderLink = useRef<string>(undefined);
- const [isLinkFromSearchDialogOpened, setLinkFromSearchConfirmDialogOpened] =
- useState<string>(undefined);
const firstRender = useFirstRender();
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const currentLocation = findLocation();
@@ -288,6 +284,30 @@ export const OpenedEntryContextProvider = ({
}
}, [currentDirectoryPath]);
+ function setLinkFromSearchConfirmDialogOpened(query: string) {
+ if (query) {
+ openConfirmDialog(
+ t('core:invalidSharingLink'),
+ t('core:confirmSearchById'),
+ (result) => {
+ if (result) {
+ setSearchQuery({
+ textQuery: query,
+ searchBoxing: 'location',
+ searchType: 'strict',
+ maxSearchResults: 1,
+ forceIndexing: true,
+ executeSearch: true,
+ });
+ }
+ },
+ 'linkFromSearchDialogCancel',
+ 'linkFromSearchDialogConfirm',
+ 'linkFromSearchDialogContent',
+ );
+ }
+ }
+
function openNextFile(
entries: TS.FileSystemEntry[],
): Promise<TS.FileSystemEntry> {
@@ -1103,29 +1123,6 @@ export const OpenedEntryContextProvider = ({
return (
<OpenedEntryContext.Provider value={context}>
{children}
- <ConfirmDialog
- open={isLinkFromSearchDialogOpened !== undefined}
- onClose={() => {
- setLinkFromSearchConfirmDialogOpened(undefined);
- }}
- title={t('core:invalidSharingLink')}
- content={t('core:confirmSearchById')}
- confirmCallback={(result) => {
- if (result) {
- setSearchQuery({
- textQuery: isLinkFromSearchDialogOpened,
- searchBoxing: 'location',
- searchType: 'strict',
- maxSearchResults: 1,
- forceIndexing: true,
- executeSearch: true,
- });
- }
- }}
- cancelDialogTID="linkFromSearchDialogCancel"
- confirmDialogTID="linkFromSearchDialogConfirm"
- confirmDialogContentTID="linkFromSearchDialogContent"
- />
</OpenedEntryContext.Provider>
);
};
diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsx
index b71cd72b7..f1c680d66 100644
--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx
+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx
@@ -27,7 +27,7 @@ import {
immutablySwapItems,
formatDateTime4Tag,
} from '@tagspaces/tagspaces-common/misc';
-import { getTagLibrary, setTagLibrary } from '-/services/taglibrary-utils';
+import { setTagLibrary } from '-/services/taglibrary-utils';
import { isGeoTag } from '-/utils/geo';
import {
getAddTagsToLibrary,
@@ -60,7 +60,6 @@ import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';
import { CommonLocation } from '-/utils/CommonLocation';
import LoadingLazy from '-/components/LoadingLazy';
import { getAllTags } from '-/services/utils-io';
-import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
type TaggingActionsContextData = {
addTagsToFsEntries: (
@@ -206,7 +205,7 @@ export const TaggingActionsContextProvider = ({
const { renameFile, saveMetaDataPromise, saveCurrentLocationMetaData } =
useIOActionsContext();
const { reflectUpdateMeta, setReflectActions } = useEditedEntryContext();
- const { showNotification } = useNotificationContext();
+ const { showNotification, openConfirmDialog } = useNotificationContext();
const [dialogState, setDialogState] = useState<{
open: boolean;
@@ -214,8 +213,6 @@ export const TaggingActionsContextProvider = ({
entries?: TS.FileSystemEntry[];
}>({ open: false });
- const [isConfirmReindexDialogOpened, setConfirmReindexDialogOpened] =
- useState<TS.TagGroup>(undefined);
const geoTaggingFormat = useSelector(getGeoTaggingFormat);
const maxCollectedTag = useSelector(getMaxCollectedTag);
const addTagsToLibrary = useSelector(getAddTagsToLibrary);
@@ -229,6 +226,25 @@ export const TaggingActionsContextProvider = ({
//const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const currentLocation = findLocation();
+ function setConfirmReindexDialogOpened(tg: TS.TagGroup) {
+ if (tg) {
+ openConfirmDialog(
+ t('core:confirmReindex'),
+ t('core:confirmReindexContent'),
+ (result) => {
+ if (result) {
+ createLocationIndex(currentLocation).then(() =>
+ collectTagsFromLocation(tg),
+ );
+ }
+ },
+ 'cancelConfirmReindexDialog',
+ 'confirmConfirmReindexDialog',
+ 'confirmReindexDialogContentTID',
+ );
+ }
+ }
+
function addTagsToFilePath(path: string, tags: string[]) {
if (tags && tags.length > 0) {
const dirSeparator = currentLocation
@@ -1545,29 +1561,6 @@ export const TaggingActionsContextProvider = ({
entries={dialogState.entries}
/>
)}
- {isConfirmReindexDialogOpened && (
- <ConfirmDialog
- open={Boolean(isConfirmReindexDialogOpened)}
- onClose={() => {
- setConfirmReindexDialogOpened(undefined);
- }}
- title={t('core:confirmReindex')}
- content={t('core:confirmReindexContent')}
- confirmCallback={(result) => {
- if (result) {
- createLocationIndex(currentLocation).then(() =>
- collectTagsFromLocation(isConfirmReindexDialogOpened),
- );
- } else {
- setConfirmReindexDialogOpened(undefined);
- }
- }}
- cancelDialogTID="cancelConfirmReindexDialog"
- confirmDialogTID="confirmConfirmReindexDialog"
- confirmDialogContentTID="confirConfirmReindexDialogContent"
- />
- )}
-
{children}
</TaggingActionsContext.Provider>
);
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index ec9fb4d48..c1d026ef5 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -977,5 +977,6 @@
"importingMacTags": "Importing MacOS tags...",
"importTagsRecursive": "Importing tags recursive",
"noModelsLoaded": "Error: No AI-models are loaded, please check if the AI-service is running.",
+ "fileModified": "File was modified, do you want to save the changes?",
"-": "-"
}
diff --git a/src/renderer/perspectives/common/CellView.tsx b/src/renderer/perspectives/common/CellView.tsx
index e8ab3fe9c..689a13cee 100644
--- a/src/renderer/perspectives/common/CellView.tsx
+++ b/src/renderer/perspectives/common/CellView.tsx
@@ -25,7 +25,6 @@ import CustomDragLayer from '-/components/CustomDragLayer';
import DragItemTypes from '-/components/DragItemTypes';
import TargetFileBox from '-/components/TargetFileBox';
import TargetMoveFileBox from '-/components/TargetMoveFileBox';
-import { useEntryExistDialogContext } from '-/components/dialogs/hooks/useEntryExistDialogContext';
import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';
import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
@@ -40,7 +39,7 @@ import {
folderOperationsEnabled,
} from '-/perspectives/common/main-container';
import { useSortedDirContext } from '-/perspectives/grid/hooks/useSortedDirContext';
-import { getDesktopMode, getEntryContainerTab } from '-/reducers/settings';
+import { getEntryContainerTab } from '-/reducers/settings';
import i18n from '-/services/i18n';
import { TS } from '-/tagspaces.namespace';
import DragHandleIcon from '@mui/icons-material/DragHandleOutlined';
@@ -77,7 +76,7 @@ function CellView(props: Props) {
useMenuContext();
const { openEntryInternal, openedEntry } = useOpenedEntryContext();
const { openDirectory } = useDirectoryContentContext();
- const { moveFiles, openFileNatively } = useIOActionsContext();
+ const { openFileNatively } = useIOActionsContext();
const { currentLocationId, currentLocation } = useCurrentLocationContext();
const {
selectedEntries,
@@ -85,12 +84,10 @@ function CellView(props: Props) {
addToSelection,
lastSelectedEntry,
} = useSelectedEntriesContext();
- const { handleEntryExist, openEntryExistDialog } =
- useEntryExistDialogContext();
const { sortedDirContent, nativeDragModeEnabled } = useSortedDirContext();
const { showNotification } = useNotificationContext();
- const desktopMode = useSelector(getDesktopMode);
+ //const desktopMode = useSelector(getDesktopMode);
const selectedTabName = useSelector(getEntryContainerTab);
// const fileSourceRef = useRef<HTMLDivElement | null>(null);
diff --git a/tests/e2e/fileopener.pw.e2e.js b/tests/e2e/fileopener.pw.e2e.js
index 6f17d7f13..0bab0e3c8 100644
--- a/tests/e2e/fileopener.pw.e2e.js
+++ b/tests/e2e/fileopener.pw.e2e.js
@@ -396,7 +396,7 @@ test.describe('TST08 - File folder properties', () => {
await clickOn('[data-tid=propsActionsMenuTID]');
await clickOn('[data-tid=deleteEntryTID]');
- await clickOn('[data-tid=confirmSaveBeforeCloseDialog]');
+ await clickOn('[data-tid=confirmDeleteTID]');
await expectElementExist(getGridFileSelector(fileName), false, 5000);
await expectMetaFilesExist(arrayMeta, false);
@@ -414,7 +414,7 @@ test.describe('TST08 - File folder properties', () => {
await clickOn('[data-tid=propsActionsMenuTID]');
await clickOn('[data-tid=deleteEntryTID]');
- await clickOn('[data-tid=confirmSaveBeforeCloseDialog]');
+ await clickOn('[data-tid=confirmDeleteTID]');
await expectElementExist(getGridFileSelector(fileName), false, 5000);
await expectMetaFilesExist([revision.file], false, revision.id);
diff --git a/tests/e2e/folderprops.pw.e2e.js b/tests/e2e/folderprops.pw.e2e.js
index 27757b9d3..7b1d25991 100644
--- a/tests/e2e/folderprops.pw.e2e.js
+++ b/tests/e2e/folderprops.pw.e2e.js
@@ -165,7 +165,7 @@ test.describe('TST02 - Folder properties', () => {
}) => {
await clickOn('[data-tid=propsActionsMenuTID]');
await clickOn('[data-tid=deleteFolderTID]');
- await clickOn('[data-tid=confirmSaveBeforeCloseDialog]');
+ await clickOn('[data-tid=confirmDeleteTID]');
await expectElementExist('OpenedTIDempty_folder', false, 5000);
await expectElementExist(getGridFileSelector('empty_folder'), false, 5000);
await testDataRefresh(isS3, testDataDir);