Skip to content

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

Refactor DND from Desktop (#2123)

Stanimir6c7a4f8b34ea
diff --git a/package.json b/package.json
index 8d7b40f99..2b1b1f8da 100644
--- a/package.json
+++ b/package.json
@@ -229,7 +229,7 @@
"uuid": "^9.0.0"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.51-alpha.3"
+ "@tagspacespro/tagspacespro": "5.0.53"
},
"devDependencies": {
"@electron/notarize": "^2.3.2",
diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsx
index 4b165bd2e..0ac16e5f6 100644
--- a/src/renderer/components/FolderContainer.tsx
+++ b/src/renderer/components/FolderContainer.tsx
@@ -51,6 +51,9 @@ import RenderPerspective from '-/components/RenderPerspective';
import { adjustKeyBinding } from '-/components/dialogs/KeyboardDialog';
import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUploadDialogContext';
import { useProTeaserDialogContext } from '-/components/dialogs/hooks/useProTeaserDialogContext';
+import CustomDragLayer from '-/components/CustomDragLayer';
+import TargetFileBox from '-/components/TargetFileBox';
+import { NativeTypes } from 'react-dnd-html5-backend';
interface Props {
toggleDrawer?: () => void;
@@ -188,6 +191,8 @@ function FolderContainer(props: Props) {
: '';
// keyBindings['openSearch'].toUpperCase()
+ const { FILE } = NativeTypes;
+
return (
<div
style={{
@@ -310,12 +315,8 @@ function FolderContainer(props: Props) {
</>
)}
</div>
- <div
- style={{
- minHeight: '100%',
- width: '100%',
- }}
- >
+ <TargetFileBox accepts={[FILE]}>
+ <CustomDragLayer />
{/*<LoadingAnimation />*/}
<RenderPerspective openRenameEntryDialog={openRenameEntryDialog} />
{isRenameEntryDialogOpened && (
@@ -324,7 +325,7 @@ function FolderContainer(props: Props) {
onClose={() => setRenameEntryDialogOpened(false)}
/>
)}
- </div>
+ </TargetFileBox>
{isDesktopMode && (
<ToggleButtonGroup
value={perspective}
diff --git a/src/renderer/components/RenderPerspective.tsx b/src/renderer/components/RenderPerspective.tsx
index ff191f1ed..3fa1a3892 100644
--- a/src/renderer/components/RenderPerspective.tsx
+++ b/src/renderer/components/RenderPerspective.tsx
@@ -34,6 +34,7 @@ const GridPerspective = React.lazy(
() =>
import(/* webpackChunkName: "GridPerspective" */ '../perspectives/grid'),
);
+
function GridPerspectiveAsync(props) {
return (
<React.Suspense fallback={<LoadingLazy />}>
diff --git a/src/renderer/components/TargetFileBox.tsx b/src/renderer/components/TargetFileBox.tsx
index a01b99a6a..10fe50680 100644
--- a/src/renderer/components/TargetFileBox.tsx
+++ b/src/renderer/components/TargetFileBox.tsx
@@ -16,9 +16,9 @@
*
*/
-import React, { ReactNode, useRef } from 'react';
+import React, { ReactNode } from 'react';
import { DropTargetMonitor, useDrop } from 'react-dnd';
-import { classes, DnD } from '-/components/DnD.css';
+import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import AppConfig from '-/AppConfig';
import { useDispatch, useSelector } from 'react-redux';
@@ -34,16 +34,20 @@ import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUp
import { useMoveOrCopyFilesDialogContext } from '-/components/dialogs/hooks/useMoveOrCopyFilesDialogContext';
type DragItem = { files: File[]; items: DataTransferItemList };
-type DragProps = { isActive: boolean; handlerId: Identifier | null };
+type DragProps = {
+ isActive: boolean;
+ handlerId: Identifier | null;
+};
interface Props {
children: ReactNode;
accepts: Array<string>;
- //setMoveCopyDialogOpened: (files: Array<File>) => void;
+ directoryPath?: string;
}
function TargetFileBox(props: Props) {
const { t } = useTranslation();
+ const theme = useTheme();
const dispatch: AppDispatch = useDispatch();
const { openFileUploadDialog } = useFileUploadDialogContext();
const { currentLocation, readOnlyMode, findLocalLocation } =
@@ -53,8 +57,9 @@ function TargetFileBox(props: Props) {
const { setReflectMetaActions } = useEditedEntryMetaContext();
const { currentDirectoryPath } = useDirectoryContentContext();
const { openMoveOrCopyFilesDialog } = useMoveOrCopyFilesDialogContext();
- const ref = useRef<HTMLDivElement>(null);
- //const { setMoveCopyDialogOpened } = props;
+ //const ref = useRef<HTMLDivElement>(null);
+ const { children, accepts, directoryPath } = props;
+ const dirPath = directoryPath ? directoryPath : currentDirectoryPath;
const onUploadProgress = (progress, abort, fileName) => {
dispatch(AppActions.onUploadProgress(progress, abort, fileName));
@@ -67,7 +72,7 @@ function TargetFileBox(props: Props) {
}
if (files) {
console.log('Dropped files: ' + JSON.stringify(files));
- if (currentDirectoryPath === undefined) {
+ if (dirPath === undefined) {
showNotification(
'Importing files failed, because no folder is opened in TagSpaces!',
'error',
@@ -85,7 +90,7 @@ function TargetFileBox(props: Props) {
const sourceLocationId = localLocation ? localLocation.uuid : undefined;
return uploadFilesAPI(
files,
- currentDirectoryPath,
+ dirPath,
onUploadProgress,
true,
false,
@@ -109,15 +114,20 @@ function TargetFileBox(props: Props) {
const [collectedProps, drop] = useDrop<DragItem, unknown, DragProps>(
() => ({
- accept: props.accepts,
- drop: ({ files }) => {
+ accept: accepts,
+ drop: ({ files }, m) => {
+ const didDrop = m.didDrop();
+ if (didDrop) {
+ return;
+ }
+
if (files && files.length) {
if (
AppConfig.isElectron &&
!currentLocation.haveObjectStoreSupport() &&
!currentLocation.haveWebDavSupport()
) {
- return openMoveOrCopyFilesDialog(files);
+ return openMoveOrCopyFilesDialog(files, dirPath);
} else {
return handleCopyFiles(files);
}
@@ -125,24 +135,29 @@ function TargetFileBox(props: Props) {
},
collect: (m: DropTargetMonitor) => ({
handlerId: m.getHandlerId(),
+ /*isOver: m.isOver(),*/
isActive: m.isOver({ shallow: true }) && m.canDrop(),
}),
}),
- [currentDirectoryPath],
+ [dirPath],
);
- drop(ref);
-
- const { isActive } = collectedProps;
- const { children } = props;
- const dragContent = isActive ? (
- <div className={classes.dropzone}>{t('core:releaseToDrop')}</div>
- ) : undefined;
+ const { isActive, handlerId } = collectedProps;
return (
- <DnD ref={ref} style={{ height: '100%' }}>
- {dragContent}
+ <div
+ ref={drop}
+ style={{
+ minHeight: '100%',
+ width: '100%',
+ ...(isActive && {
+ boxShadow: 'inset 0px 2px 0 5px ' + theme.palette.primary.main,
+ borderRadius: 5,
+ backgroundColor: theme.palette.primary.main,
+ }),
+ }}
+ >
{children}
- </DnD>
+ </div>
);
}
diff --git a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
index 7018af436..035b2e744 100644
--- a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
@@ -51,6 +51,7 @@ interface Props {
open: boolean;
onClose: (clearSelection?: boolean) => void;
selectedFiles: Array<TS.FileSystemEntry>;
+ targetDir?: string;
}
function MoveOrCopyFilesDialog(props: Props) {
@@ -66,6 +67,7 @@ function MoveOrCopyFilesDialog(props: Props) {
const { moveFiles, copyFiles } = useIOActionsContext();
const { currentDirectoryPath } = useDirectoryContentContext();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
+ const targetDir = props.targetDir ? props.targetDir : currentDirectoryPath;
function generateThumbs(filePaths: string[]) {
const promises: Promise<TS.EditMetaAction>[] = filePaths.map((filePath) =>
@@ -80,32 +82,30 @@ function MoveOrCopyFilesDialog(props: Props) {
}
function handleMove(filePaths: string[]) {
- moveFiles(filePaths, currentDirectoryPath, currentLocation.uuid).then(
- (success) => {
- if (success) {
- generateThumbs(
- filePaths.map((targetPath) =>
- joinPaths(
- currentLocation?.getDirSeparator(),
- currentDirectoryPath,
- extractFileName(targetPath, currentLocation?.getDirSeparator()),
- ),
+ moveFiles(filePaths, targetDir, currentLocation.uuid).then((success) => {
+ if (success) {
+ generateThumbs(
+ filePaths.map((targetPath) =>
+ joinPaths(
+ currentLocation?.getDirSeparator(),
+ targetDir,
+ extractFileName(targetPath, currentLocation?.getDirSeparator()),
),
- );
- }
- return true;
- },
- );
+ ),
+ );
+ }
+ return true;
+ });
}
function handleCopy(filePaths: string[]) {
- copyFiles(filePaths, currentDirectoryPath).then((success) => {
+ copyFiles(filePaths, targetDir).then((success) => {
if (success) {
generateThumbs(
filePaths.map((targetPath) =>
joinPaths(
currentLocation?.getDirSeparator(),
- currentDirectoryPath,
+ targetDir,
extractFileName(targetPath, currentLocation?.getDirSeparator()),
),
),
@@ -138,6 +138,9 @@ function MoveOrCopyFilesDialog(props: Props) {
overflowY: 'auto',
}}
>
+ <Typography variant="subtitle2">
+ {t('core:moveCopyToPath') + ': ' + targetDir}
+ </Typography>
<Typography variant="subtitle2">{t('selectedFiles')}</Typography>
<List dense style={{ width: 550, marginLeft: -15 }}>
{selectedFiles &&
@@ -163,17 +166,15 @@ function MoveOrCopyFilesDialog(props: Props) {
<Button
onClick={() => {
if (selectedFiles) {
- handleEntryExist(selectedFiles, currentDirectoryPath).then(
- (exist) => {
- if (exist) {
- openEntryExistDialog(exist, () => {
- handleMove(selectedFiles.map((file) => file.path));
- });
- } else {
+ handleEntryExist(selectedFiles, targetDir).then((exist) => {
+ if (exist) {
+ openEntryExistDialog(exist, () => {
handleMove(selectedFiles.map((file) => file.path));
- }
- },
- );
+ });
+ } else {
+ handleMove(selectedFiles.map((file) => file.path));
+ }
+ });
}
onClose();
}}
@@ -186,17 +187,15 @@ function MoveOrCopyFilesDialog(props: Props) {
<Button
onClick={() => {
if (selectedFiles) {
- handleEntryExist(selectedFiles, currentDirectoryPath).then(
- (exist) => {
- if (exist) {
- openEntryExistDialog(exist, () => {
- handleCopy(selectedFiles.map((file) => file.path));
- });
- } else {
+ handleEntryExist(selectedFiles, targetDir).then((exist) => {
+ if (exist) {
+ openEntryExistDialog(exist, () => {
handleCopy(selectedFiles.map((file) => file.path));
- }
- },
- );
+ });
+ } else {
+ handleCopy(selectedFiles.map((file) => file.path));
+ }
+ });
}
onClose();
}}
diff --git a/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx
index 0376dd260..637418913 100644
--- a/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx
@@ -24,7 +24,10 @@ import { TS } from '-/tagspaces.namespace';
import AppConfig from '-/AppConfig';
type MoveOrCopyFilesDialogContextData = {
- openMoveOrCopyFilesDialog: (files: Array<File>) => void;
+ openMoveOrCopyFilesDialog: (
+ files: Array<File>,
+ targetDirectory?: string,
+ ) => void;
closeMoveOrCopyFilesDialog: () => void;
};
@@ -50,11 +53,13 @@ export const MoveOrCopyFilesDialogContextProvider = ({
}: MoveOrCopyFilesDialogContextProviderProps) => {
const open = useRef<boolean>(false);
const files = useRef<TS.FileSystemEntry[]>(undefined);
+ const targetDir = useRef<string>(undefined);
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
- function openDialog(selectedFiles: Array<File>) {
+ function openDialog(selectedFiles: Array<File>, targetDirectory?: string) {
open.current = true;
+ targetDir.current = targetDirectory;
isDirs(selectedFiles).then((isDirsArray) => {
files.current = selectedFiles.map((file, index) => ({
uuid: getUuid(),
@@ -106,6 +111,7 @@ export const MoveOrCopyFilesDialogContextProvider = ({
open={open.current}
onClose={closeDialog}
selectedFiles={files.current?.filter((file) => file.isFile)} // todo enable for dir
+ targetDir={targetDir.current}
/>
{children}
</MoveOrCopyFilesDialogContext.Provider>
diff --git a/src/renderer/containers/MainPage.tsx b/src/renderer/containers/MainPage.tsx
index 33283d913..596de755b 100644
--- a/src/renderer/containers/MainPage.tsx
+++ b/src/renderer/containers/MainPage.tsx
@@ -23,7 +23,6 @@ import { connect, useSelector } from 'react-redux';
import SwipeableDrawer from '@mui/material/SwipeableDrawer';
import Drawer from '@mui/material/Drawer';
import { HotKeys } from 'react-hotkeys';
-import { NativeTypes } from 'react-dnd-html5-backend';
import { Split } from 'ts-react-splitter';
import { buffer } from '@tagspaces/tagspaces-common/misc';
import AppConfig from '-/AppConfig';
@@ -36,8 +35,6 @@ import {
getMainVerticalSplitSize,
actions as SettingsActions,
} from '../reducers/settings';
-import TargetFileBox from '../components/TargetFileBox';
-import CustomDragLayer from '-/components/CustomDragLayer';
import useEventListener from '-/utils/useEventListener';
import PageNotification from '-/containers/PageNotification';
import { styled, useTheme } from '@mui/material/styles';
@@ -227,8 +224,6 @@ function MainPage(props: Props) {
showHelp: keyBindings.showHelp,
};
- const { FILE } = NativeTypes;
-
const setPercent = (p: number | undefined) => {
percent.current = p;
if (p !== undefined) {
@@ -333,8 +328,7 @@ function MainPage(props: Props) {
`}
</style>
{isDesktopMode || (AppConfig.isAmplify && !isLoggedIn()) ? (
- <TargetFileBox accepts={[FILE]}>
- <CustomDragLayer />
+ <>
<Drawer variant="persistent" anchor="left" open={drawerOpened}>
<MobileNavigation width={drawerWidth} />
</Drawer>
@@ -345,7 +339,7 @@ function MainPage(props: Props) {
>
{renderContainers()}
</main>
- </TargetFileBox>
+ </>
) : (
<>
<SwipeableDrawer
diff --git a/src/renderer/perspectives/common/main-container.tsx b/src/renderer/perspectives/common/main-container.tsx
index 0b5b5de47..8448a2eab 100644
--- a/src/renderer/perspectives/common/main-container.tsx
+++ b/src/renderer/perspectives/common/main-container.tsx
@@ -5,7 +5,9 @@ import DragItemTypes from '-/components/DragItemTypes';
import React from 'react';
import AppConfig from '-/AppConfig';
import TagDropContainer from '-/components/TagDropContainer';
-import { useEntryExistDialogContext } from '-/components/dialogs/hooks/useEntryExistDialogContext';
+import CustomDragLayer from '-/components/CustomDragLayer';
+import TargetFileBox from '-/components/TargetFileBox';
+import { NativeTypes } from 'react-dnd-html5-backend';
export const fileOperationsEnabled = (selectedEntries) => {
let selectionContainsDirectories = false;
@@ -281,6 +283,7 @@ export const renderCell = (
</FileSourceDnd>
);
}
+ const { FILE } = NativeTypes;
return (
<div
@@ -289,21 +292,24 @@ export const renderCell = (
}}
key={key}
>
- <TargetMoveFileBox
- accepts={[DragItemTypes.FILE]}
- targetPath={fsEntry.path}
- onDrop={handleFileMoveDrop}
- >
- {cellContent(
- fsEntry,
- selectedEntries,
- index,
- handleGridContextMenu,
- handleGridCellClick,
- handleGridCellDblClick,
- isLast,
- )}
- </TargetMoveFileBox>
+ <TargetFileBox accepts={[FILE]} directoryPath={fsEntry.path}>
+ <CustomDragLayer />
+ <TargetMoveFileBox
+ accepts={[DragItemTypes.FILE]}
+ targetPath={fsEntry.path}
+ onDrop={handleFileMoveDrop}
+ >
+ {cellContent(
+ fsEntry,
+ selectedEntries,
+ index,
+ handleGridContextMenu,
+ handleGridCellClick,
+ handleGridCellDblClick,
+ isLast,
+ )}
+ </TargetMoveFileBox>
+ </TargetFileBox>
</div>
);
};