TagSpaces is an offline, open source, document manager with tagging support
DnD with copy move dialog (#2266)
Stanimire495d1b647ae
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsxindex 7425f4102..c7c924f57 100644--- a/src/renderer/components/LocationView.tsx+++ b/src/renderer/components/LocationView.tsx@@ -54,6 +54,7 @@ import { useDispatch } from 'react-redux';import { actions as AppActions, AppDispatch } from '../reducers/app';import DragItemTypes from './DragItemTypes';import TargetMoveFileBox from './TargetMoveFileBox';+import { useMoveOrCopyFilesDialogContext } from '-/components/dialogs/hooks/useMoveOrCopyFilesDialogContext';interface Props {location: CommonLocation;@@ -64,7 +65,7 @@ interface Props {function LocationView(props: Props) {const { t } = useTranslation();- const { moveFiles, uploadFiles } = useIOActionsContext();+ const { uploadFiles } = useIOActionsContext();const { openFileUploadDialog } = useFileUploadDialogContext();const {openLocation,@@ -73,8 +74,7 @@ function LocationView(props: Props) {setSelectedLocation,setLocationDirectoryContextMenuAnchorEl,} = useCurrentLocationContext();- const { handleEntryExist, openEntryExistDialog } =- useEntryExistDialogContext();+ const { openMoveOrCopyFilesDialog } = useMoveOrCopyFilesDialogContext();const { setActions } = usePerspectiveActionsContext();const { setSelectedEntries, selectedEntries } = useSelectedEntriesContext();const { currentLocationPath, openDirectory } = useDirectoryContentContext();@@ -170,19 +170,10 @@ function LocationView(props: Props) {console.log('uploadFiles', error);});} else if (targetLocation.type === locationType.TYPE_LOCAL) {- handleEntryExist(- selectedEntries,- targetPath,- targetLocation.uuid,- ).then((exist) => {- if (exist) {- openEntryExistDialog(exist, () => {- moveFiles(arrPath, targetPath, targetLocation.uuid);- });- } else {- moveFiles(arrPath, targetPath, targetLocation.uuid);- }- });+ const entries =+ selectedEntries.length > 0 ? selectedEntries : [entry];+ openMoveOrCopyFilesDialog(entries, targetPath, targetLocation.uuid);+ //moveFiles(arrPath, targetPath, targetLocation.uuid);} else {showNotification(t('Moving file not possible'), 'error', true);return;diff --git a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsxindex c94c57e84..5658da2f1 100644--- a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx+++ b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx@@ -59,8 +59,7 @@ function MoveOrCopyFilesDialog(props: Props) {const theme = useTheme();- const { handleEntryExist, openEntryExistDialog } =- useEntryExistDialogContext();+ const { handleEntryExist } = useEntryExistDialogContext();const { setReflectMetaActions } = useEditedEntryMetaContext();const { findLocation } = useCurrentLocationContext();const { moveFiles, copyFiles } = useIOActionsContext();@@ -82,7 +81,14 @@ function MoveOrCopyFilesDialog(props: Props) {}function handleMove(filePaths: string[]) {- moveFiles(filePaths, targetDir, targetLocation.uuid).then((success) => {+ moveFiles(+ filePaths,+ targetDir,+ targetLocation.uuid,+ undefined,+ true,+ true,+ ).then((success) => {if (success) {sendDirMessage('moveFiles', filePaths);generateThumbs(@@ -163,16 +169,14 @@ function MoveOrCopyFilesDialog(props: Props) {<TsButtononClick={() => {if (selectedFiles) {- handleEntryExist(selectedFiles, targetDir, targetLocationId).then(- (exist) => {- if (exist) {- openEntryExistDialog(exist, () => {- handleMove(selectedFiles.map((file) => file.path));- });- } else {- handleMove(selectedFiles.map((file) => file.path));- }- },+ const confirmOverride = () => {+ handleMove(selectedFiles.map((file) => file.path));+ };+ handleEntryExist(+ selectedFiles,+ targetDir,+ targetLocationId,+ confirmOverride,);}onClose();@@ -185,16 +189,14 @@ function MoveOrCopyFilesDialog(props: Props) {<TsButtononClick={() => {if (selectedFiles) {- handleEntryExist(selectedFiles, targetDir, targetLocationId).then(- (exist) => {- if (exist) {- openEntryExistDialog(exist, () => {- handleCopy(selectedFiles.map((file) => file.path));- });- } else {- handleCopy(selectedFiles.map((file) => file.path));- }- },+ const confirmOverride = () => {+ handleCopy(selectedFiles.map((file) => file.path));+ };+ handleEntryExist(+ selectedFiles,+ targetDir,+ targetLocationId,+ confirmOverride,);}onClose();diff --git a/src/renderer/components/dialogs/hooks/DeleteMultipleEntriesDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/DeleteMultipleEntriesDialogContextProvider.tsxindex 10b2034bf..c81fa42bf 100644--- a/src/renderer/components/dialogs/hooks/DeleteMultipleEntriesDialogContextProvider.tsx+++ b/src/renderer/components/dialogs/hooks/DeleteMultipleEntriesDialogContextProvider.tsx@@ -50,7 +50,7 @@ export const DeleteMultipleEntriesDialogContextProvider = ({}: DeleteMultipleEntriesDialogContextProviderProps) => {const { t } = useTranslation();const { deleteEntries } = useIOActionsContext();- const { selectedEntries } = useSelectedEntriesContext();+ const { selectedEntries } = useSelectedEntriesContext(); // todo don't use context provider here pass it like props in openDialogconst { showNotification } = useNotificationContext();const open = useRef<boolean>(false);diff --git a/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsxindex 4dd05dbd6..864bf4833 100644--- a/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx+++ b/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx@@ -27,6 +27,7 @@ type EntryExistDialogContextData = {entries: TS.FileSystemEntry[],targetPath: string,targetLocationId?: string,+ confirmCallback?: () => void,) => Promise<string[]>;openEntryExistDialog: (existPath: string[],@@ -58,6 +59,7 @@ export const EntryExistDialogContextProvider = ({entries: TS.FileSystemEntry[],targetPath: string,targetLocationId?: string,+ confirmCallback?: () => void,): Promise<string[]> {if (entries) {let arrExist = [];@@ -88,9 +90,16 @@ export const EntryExistDialogContextProvider = ({}}if (arrExist.length > 0) {+ if (confirmCallback) {+ openDialog(arrExist, confirmCallback);+ }return arrExist;}}++ if (confirmCallback) {+ confirmCallback();+ }return Promise.resolve(undefined);}@@ -122,27 +131,27 @@ export const EntryExistDialogContextProvider = ({return (<EntryExistDialogContext.Provider value={context}>- <ConfirmDialog- open={entriesExistPath.current.length > 0}- onClose={() => {- closeDialog();- }}- title={t('core:confirm')}- content={- formatFileExist(entriesExistPath.current) +- ' exist do you want to override it?'- }- confirmCallback={(result) => {- if (result) {- confirmOverride.current();- } else {- entriesExistPath.current = [];+ {entriesExistPath.current.length > 0 && (+ <ConfirmDialog+ open={true}+ onClose={() => {+ closeDialog();+ }}+ title={t('core:confirm')}+ content={+ formatFileExist(entriesExistPath.current) ++ ' exist do you want to override it?'}- }}- cancelDialogTID="cancelOverwriteByCopyMoveDialog"- confirmDialogTID="confirmOverwriteByCopyMoveDialog"- confirmDialogContentTID="confirmDialogContent"- />+ confirmCallback={(result) => {+ if (result) {+ confirmOverride.current();+ }+ }}+ cancelDialogTID="cancelOverwriteByCopyMoveDialog"+ confirmDialogTID="confirmOverwriteByCopyMoveDialog"+ confirmDialogContentTID="confirmDialogContent"+ />+ )}{children}</EntryExistDialogContext.Provider>);diff --git a/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsxindex 616fc4aad..7096f676c 100644--- a/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx+++ b/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx@@ -25,7 +25,7 @@ import AppConfig from '-/AppConfig';type MoveOrCopyFilesDialogContextData = {openMoveOrCopyFilesDialog: (- files: Array<File>,+ files: File[] | TS.FileSystemEntry[],targetDirectory?: string,targetLocationId?: string,) => void;@@ -59,8 +59,12 @@ export const MoveOrCopyFilesDialogContextProvider = ({const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ function isFileArray(value: unknown): value is File[] {+ return Array.isArray(value) && value.every((item) => item instanceof File);+ }+function openDialog(- selectedFiles: Array<File>,+ selectedFiles: File[] | TS.FileSystemEntry[],targetDirectory?: string,targetLocationID?: string,) {@@ -70,18 +74,22 @@ export const MoveOrCopyFilesDialogContextProvider = ({open.current = true;targetDir.current = targetDirectory;targetLocationId.current = targetLocationID;- isDirs(selectedFiles).then((isDirsArray) => {- files.current = selectedFiles.map((file, index) => ({- uuid: getUuid(),- name: file.name,- path: file.path,- isFile: !isDirsArray[index],- extension: extractFileExtension(file.path),- size: file.size,- lmdt: file.lastModified,- }));- forceUpdate();- });+ if (isFileArray(selectedFiles)) {+ isDirs(selectedFiles).then((isDirsArray) => {+ files.current = selectedFiles.map((file, index) => ({+ uuid: getUuid(),+ name: file.name,+ path: file.path,+ isFile: !isDirsArray[index],+ extension: extractFileExtension(file.path),+ size: file.size,+ lmdt: file.lastModified,+ }));+ forceUpdate();+ });+ } else {+ files.current = selectedFiles;+ }forceUpdate();}