Skip to content

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

add DnD target in LocationView and MapFolderView

Stanimir8b84bd13e723
diff --git a/src/renderer/components/DirectoryListView.tsx b/src/renderer/components/DirectoryListView.tsx
index e1da8714f..7b56757a8 100644
--- a/src/renderer/components/DirectoryListView.tsx
+++ b/src/renderer/components/DirectoryListView.tsx
@@ -34,7 +34,6 @@ function DirectoryListView(props: Props) {
const { currentLocation, findLocation, locations } =
useCurrentLocationContext();
const { openCreateDirectoryDialog } = useCreateDirectoryDialogContext();
- // const locations: Array<CommonLocation> = useSelector(getLocations);
const showUnixHiddenEntries: boolean = useSelector(getShowUnixHiddenEntries);
const chosenLocationId = useRef<string>(
currentLocation ? currentLocation.uuid : undefined,
diff --git a/src/renderer/components/DirectoryTreeView.tsx b/src/renderer/components/DirectoryTreeView.tsx
index 3d6bc0997..428a8cd9b 100644
--- a/src/renderer/components/DirectoryTreeView.tsx
+++ b/src/renderer/components/DirectoryTreeView.tsx
@@ -28,6 +28,9 @@ import { getShowUnixHiddenEntries } from '-/reducers/settings';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { CommonLocation } from '-/utils/CommonLocation';
+import CustomDragLayer from '-/components/CustomDragLayer';
+import TargetFileBox from '-/components/TargetFileBox';
+import { NativeTypes } from 'react-dnd-html5-backend';
interface Props {
classes: any;
@@ -71,15 +74,20 @@ const DirectoryTreeView = forwardRef(
},
}));
+ const { FILE } = NativeTypes;
+
const renderBodyRow = (props) => {
if (AppConfig.isElectron || location.type !== locationType.TYPE_CLOUD) {
// DnD to S3 location is not permitted in web browser without <input> element
return (
- <TargetTableMoveFileBox
- accepts={[DragItemTypes.FILE]}
- onDrop={handleFileMoveDrop}
- {...props}
- />
+ <TargetFileBox accepts={[FILE]} directoryPath={props.location.path}>
+ <CustomDragLayer />
+ <TargetTableMoveFileBox
+ accepts={[DragItemTypes.FILE]}
+ onDrop={handleFileMoveDrop}
+ {...props}
+ />
+ </TargetFileBox>
);
}
return <tr {...props} />;
diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsx
index 0ac16e5f6..b74d0b3cb 100644
--- a/src/renderer/components/FolderContainer.tsx
+++ b/src/renderer/components/FolderContainer.tsx
@@ -315,7 +315,10 @@ function FolderContainer(props: Props) {
</>
)}
</div>
- <TargetFileBox accepts={[FILE]}>
+ <TargetFileBox
+ style={{ minHeight: '100%', width: '100%' }}
+ accepts={[FILE]}
+ >
<CustomDragLayer />
{/*<LoadingAnimation />*/}
<RenderPerspective openRenameEntryDialog={openRenameEntryDialog} />
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsx
index cc39abcab..0a69b408c 100644
--- a/src/renderer/components/LocationView.tsx
+++ b/src/renderer/components/LocationView.tsx
@@ -45,6 +45,9 @@ import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { CommonLocation } from '-/utils/CommonLocation';
import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUploadDialogContext';
import { useEntryExistDialogContext } from '-/components/dialogs/hooks/useEntryExistDialogContext';
+import CustomDragLayer from '-/components/CustomDragLayer';
+import TargetFileBox from '-/components/TargetFileBox';
+import { NativeTypes } from 'react-dnd-html5-backend';
interface Props {
location: CommonLocation;
@@ -220,7 +223,7 @@ function LocationView(props: Props) {
</div>
</Tooltip>
);
-
+ const { FILE } = NativeTypes;
return (
/* <div key={location.uuid}> */
<SidePanel>
@@ -231,80 +234,85 @@ function LocationView(props: Props) {
closeLocationTree={closeLocationTree}
/>
)}*/}
- <ListItem
- data-tid={'location_' + location.name.replace(/ /g, '_')}
- className={
- currentLocation && currentLocation.uuid === location.uuid
- ? classes.listItemSelected
- : classes.listItem
- }
- onClick={handleLocationClick}
- onContextMenu={(event) =>
- handleLocationContextMenuClick(event, location)
- }
- >
- <ListItemIcon
- // onClick={(e) => {
- // e.preventDefault();
- // this.loadSubDirectories(location, 1);
- // }}
- style={{
- minWidth: 'auto',
- cursor: 'pointer',
- }}
- onClick={handleLocationIconClick}
+ <TargetFileBox accepts={[FILE]} directoryPath={location.path}>
+ <CustomDragLayer />
+ <ListItem
+ data-tid={'location_' + location.name.replace(/ /g, '_')}
+ className={
+ currentLocation && currentLocation.uuid === location.uuid
+ ? classes.listItemSelected
+ : classes.listItem
+ }
+ onClick={handleLocationClick}
+ onContextMenu={(event) =>
+ handleLocationContextMenuClick(event, location)
+ }
>
- <Tooltip title={t('clickToExpand')}>
- {isCloudLocation ? (
- <CloudLocationIcon
- style={{
- cursor: 'pointer',
- }}
- className={classes.icon}
- />
- ) : (
- <LocalLocationIcon
- style={{
- cursor: 'pointer',
- }}
- className={classes.icon}
- />
- )}
- </Tooltip>
- </ListItemIcon>
- {isCloudLocation && !AppConfig.isElectron ? (
- <>{LocationTitle}</>
- ) : (
- <TargetMoveFileBox
- accepts={[DragItemTypes.FILE]}
- onDrop={handleFileMoveDrop}
- targetPath={currentLocationPath}
- targetLocation={location}
- >
- {LocationTitle}
- </TargetMoveFileBox>
- )}
- <ListItemSecondaryAction>
- <IconButton
- aria-label={t('core:options')}
- aria-haspopup="true"
- edge="end"
- data-tid={'locationMoreButton_' + location.name}
- onClick={(event) => handleLocationContextMenuClick(event, location)}
- onContextMenu={(event) =>
- handleLocationContextMenuClick(event, location)
- }
- size="large"
+ <ListItemIcon
+ // onClick={(e) => {
+ // e.preventDefault();
+ // this.loadSubDirectories(location, 1);
+ // }}
+ style={{
+ minWidth: 'auto',
+ cursor: 'pointer',
+ }}
+ onClick={handleLocationIconClick}
>
- {location.isDefault && (
- <Tooltip title={t('core:thisIsStartupLocation')}>
- <DefaultLocationIcon data-tid="startupIndication" />
- </Tooltip>
- )}
- <MoreVertIcon />
- </IconButton>
- </ListItemSecondaryAction>
- </ListItem>
+ <Tooltip title={t('clickToExpand')}>
+ {isCloudLocation ? (
+ <CloudLocationIcon
+ style={{
+ cursor: 'pointer',
+ }}
+ className={classes.icon}
+ />
+ ) : (
+ <LocalLocationIcon
+ style={{
+ cursor: 'pointer',
+ }}
+ className={classes.icon}
+ />
+ )}
+ </Tooltip>
+ </ListItemIcon>
+ {isCloudLocation && !AppConfig.isElectron ? (
+ <>{LocationTitle}</>
+ ) : (
+ <TargetMoveFileBox
+ accepts={[DragItemTypes.FILE]}
+ onDrop={handleFileMoveDrop}
+ targetPath={currentLocationPath}
+ targetLocation={location}
+ >
+ {LocationTitle}
+ </TargetMoveFileBox>
+ )}
+ <ListItemSecondaryAction>
+ <IconButton
+ aria-label={t('core:options')}
+ aria-haspopup="true"
+ edge="end"
+ data-tid={'locationMoreButton_' + location.name}
+ onClick={(event) =>
+ handleLocationContextMenuClick(event, location)
+ }
+ onContextMenu={(event) =>
+ handleLocationContextMenuClick(event, location)
+ }
+ size="large"
+ >
+ {location.isDefault && (
+ <Tooltip title={t('core:thisIsStartupLocation')}>
+ <DefaultLocationIcon data-tid="startupIndication" />
+ </Tooltip>
+ )}
+ <MoreVertIcon />
+ </IconButton>
+ </ListItemSecondaryAction>
+ </ListItem>
+ </TargetFileBox>
<DirectoryTreeView
key={'tree_' + location.uuid}
ref={directoryTreeRef}
diff --git a/src/renderer/components/TargetFileBox.tsx b/src/renderer/components/TargetFileBox.tsx
index 5912786b2..81a7a9a22 100644
--- a/src/renderer/components/TargetFileBox.tsx
+++ b/src/renderer/components/TargetFileBox.tsx
@@ -43,6 +43,7 @@ interface Props {
children: ReactNode;
accepts: Array<string>;
directoryPath?: string;
+ style?: React.CSSProperties;
}
function TargetFileBox(props: Props) {
@@ -58,7 +59,7 @@ function TargetFileBox(props: Props) {
const { currentDirectoryPath } = useDirectoryContentContext();
const { openMoveOrCopyFilesDialog } = useMoveOrCopyFilesDialogContext();
//const ref = useRef<HTMLDivElement>(null);
- const { children, accepts, directoryPath } = props;
+ const { children, accepts, directoryPath, style } = props;
const dirPath = directoryPath ? directoryPath : currentDirectoryPath;
const onUploadProgress = (progress, abort, fileName) => {
@@ -147,8 +148,7 @@ function TargetFileBox(props: Props) {
<div
ref={drop}
style={{
- minHeight: '100%',
- width: '100%',
+ ...style,
...(isActive && {
boxShadow: 'inset 0px 0px 0 5px ' + theme.palette.primary.main,
borderRadius: 5,