Skip to content

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

fix DnD in s3 and welcome screen

Stanimir916620fad466
diff --git a/src/renderer/components/DirectoryTreeView.tsx b/src/renderer/components/DirectoryTreeView.tsx
index 428a8cd9b..dd1fabf12 100644
--- a/src/renderer/components/DirectoryTreeView.tsx
+++ b/src/renderer/components/DirectoryTreeView.tsx
@@ -80,7 +80,11 @@ const DirectoryTreeView = forwardRef(
if (AppConfig.isElectron || location.type !== locationType.TYPE_CLOUD) {
// DnD to S3 location is not permitted in web browser without <input> element
return (
- <TargetFileBox accepts={[FILE]} directoryPath={props.location.path}>
+ <TargetFileBox
+ accepts={[FILE]}
+ directoryPath={props.location.path}
+ locationId={location.uuid}
+ >
<CustomDragLayer />
<TargetTableMoveFileBox
accepts={[DragItemTypes.FILE]}
diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsx
index b74d0b3cb..06b07be7d 100644
--- a/src/renderer/components/FolderContainer.tsx
+++ b/src/renderer/components/FolderContainer.tsx
@@ -315,11 +315,7 @@ function FolderContainer(props: Props) {
</>
)}
</div>
- <TargetFileBox
- style={{ minHeight: '100%', width: '100%' }}
- accepts={[FILE]}
- >
- <CustomDragLayer />
+ <div style={{ minHeight: '100%', width: '100%' }}>
{/*<LoadingAnimation />*/}
<RenderPerspective openRenameEntryDialog={openRenameEntryDialog} />
{isRenameEntryDialogOpened && (
@@ -328,7 +324,7 @@ function FolderContainer(props: Props) {
onClose={() => setRenameEntryDialogOpened(false)}
/>
)}
- </TargetFileBox>
+ </div>
{isDesktopMode && (
<ToggleButtonGroup
value={perspective}
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsx
index 0a69b408c..6900f30e5 100644
--- a/src/renderer/components/LocationView.tsx
+++ b/src/renderer/components/LocationView.tsx
@@ -171,7 +171,11 @@ function LocationView(props: Props) {
console.log('uploadFiles', error);
});
} else if (targetLocation.type === locationType.TYPE_LOCAL) {
- handleEntryExist(selectedEntries, targetPath).then((exist) => {
+ handleEntryExist(
+ selectedEntries,
+ targetPath,
+ targetLocation.uuid,
+ ).then((exist) => {
if (exist) {
openEntryExistDialog(exist, () => {
moveFiles(arrPath, targetPath, targetLocation.uuid);
@@ -234,7 +238,11 @@ function LocationView(props: Props) {
closeLocationTree={closeLocationTree}
/>
)}*/}
- <TargetFileBox accepts={[FILE]} directoryPath={location.path}>
+ <TargetFileBox
+ accepts={[FILE]}
+ directoryPath={location.path}
+ locationId={location.uuid}
+ >
<CustomDragLayer />
<ListItem
data-tid={'location_' + location.name.replace(/ /g, '_')}
diff --git a/src/renderer/components/RenderPerspective.tsx b/src/renderer/components/RenderPerspective.tsx
index 3fa1a3892..8eb53300d 100644
--- a/src/renderer/components/RenderPerspective.tsx
+++ b/src/renderer/components/RenderPerspective.tsx
@@ -29,6 +29,9 @@ import { PaginationContextProvider } from '-/hooks/PaginationContextProvider';
import { ThumbGenerationContextProvider } from '-/hooks/ThumbGenerationContextProvider';
import { PerspectiveSettingsContextProvider } from '-/hooks/PerspectiveSettingsContextProvider';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
+import CustomDragLayer from '-/components/CustomDragLayer';
+import TargetFileBox from '-/components/TargetFileBox';
+import { NativeTypes } from 'react-dnd-html5-backend';
const GridPerspective = React.lazy(
() =>
@@ -154,42 +157,45 @@ function RenderPerspective(props: Props) {
const { currentLocation } = useCurrentLocationContext();
const { perspective } = useDirectoryContentContext();
- /*const defaultPerspective = useSelector(getDefaultPerspective);
-
- let currentPerspective =
- currentDirectoryPerspective || defaultPerspective || PerspectiveIDs.GRID;
-
- if (currentPerspective === PerspectiveIDs.UNSPECIFIED) {
- currentPerspective = defaultPerspective;
- }*/
-
const showWelcomePanel = !currentLocation;
//!currentDirectoryPath && currentDirectoryEntries.length < 1;
if (showWelcomePanel) {
return AppConfig.showWelcomePanel ? <WelcomePanelAsync /> : null;
}
- if (perspective === PerspectiveIDs.LIST) {
- return (
- <ListPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />
- );
- }
- if (Pro && perspective === PerspectiveIDs.GALLERY) {
- return <GalleryPerspectiveAsync />;
- }
- if (Pro && perspective === PerspectiveIDs.MAPIQUE) {
- return <MapiquePerspectiveAsync />;
- }
- if (Pro && perspective === PerspectiveIDs.KANBAN) {
+
+ function getPerspective() {
+ if (perspective === PerspectiveIDs.LIST) {
+ return (
+ <ListPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />
+ );
+ }
+ if (Pro && perspective === PerspectiveIDs.GALLERY) {
+ return <GalleryPerspectiveAsync />;
+ }
+ if (Pro && perspective === PerspectiveIDs.MAPIQUE) {
+ return <MapiquePerspectiveAsync />;
+ }
+ if (Pro && perspective === PerspectiveIDs.KANBAN) {
+ return (
+ <KanBanPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />
+ );
+ }
+ if (Pro && perspective === PerspectiveIDs.FOLDERVIZ) {
+ return <FolderVizPerspectiveAsync />;
+ }
+
return (
- <KanBanPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />
+ <GridPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />
);
}
- if (Pro && perspective === PerspectiveIDs.FOLDERVIZ) {
- return <FolderVizPerspectiveAsync />;
- }
-
- return <GridPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />;
+ const { FILE } = NativeTypes;
+ return (
+ <TargetFileBox style={{ height: '100%' }} accepts={[FILE]}>
+ <CustomDragLayer />
+ {getPerspective()}
+ </TargetFileBox>
+ );
}
export default RenderPerspective;
diff --git a/src/renderer/components/TargetFileBox.tsx b/src/renderer/components/TargetFileBox.tsx
index b21d3baf6..2e4b45f3c 100644
--- a/src/renderer/components/TargetFileBox.tsx
+++ b/src/renderer/components/TargetFileBox.tsx
@@ -21,7 +21,7 @@ import { DropTargetMonitor, useDrop } from 'react-dnd';
import { alpha, useTheme } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import AppConfig from '-/AppConfig';
-import { useDispatch, useSelector } from 'react-redux';
+import { useDispatch } from 'react-redux';
import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import { Identifier } from 'dnd-core';
@@ -43,6 +43,7 @@ interface Props {
children: ReactNode;
accepts: Array<string>;
directoryPath?: string;
+ locationId?: string;
style?: React.CSSProperties;
}
@@ -51,7 +52,7 @@ function TargetFileBox(props: Props) {
const theme = useTheme();
const dispatch: AppDispatch = useDispatch();
const { openFileUploadDialog } = useFileUploadDialogContext();
- const { currentLocation, readOnlyMode, findLocalLocation } =
+ const { readOnlyMode, findLocalLocation, findLocation } =
useCurrentLocationContext();
const { uploadFilesAPI } = useIOActionsContext();
const { showNotification } = useNotificationContext();
@@ -59,7 +60,7 @@ function TargetFileBox(props: Props) {
const { currentDirectoryPath } = useDirectoryContentContext();
const { openMoveOrCopyFilesDialog } = useMoveOrCopyFilesDialogContext();
//const ref = useRef<HTMLDivElement>(null);
- const { children, accepts, directoryPath, style } = props;
+ const { children, accepts, directoryPath, style, locationId } = props;
const dirPath = directoryPath ? directoryPath : currentDirectoryPath;
const onUploadProgress = (progress, abort, fileName) => {
@@ -123,8 +124,13 @@ function TargetFileBox(props: Props) {
}
if (files && files.length) {
- if (AppConfig.isElectron) {
- return openMoveOrCopyFilesDialog(files, dirPath);
+ const location = findLocation(locationId);
+ if (
+ AppConfig.isElectron &&
+ !location.haveObjectStoreSupport() &&
+ !location.haveWebDavSupport()
+ ) {
+ return openMoveOrCopyFilesDialog(files, dirPath, location.uuid);
} else {
return handleCopyFiles(files);
}
diff --git a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
index 79b1a8aee..e77d47d7d 100644
--- a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
@@ -115,7 +115,12 @@ function MoveCopyFilesDialog(props: Props) {
dispatch(AppActions.resetProgress());
openFileUploadDialog(undefined, 'copyEntriesTitle');
if (selectedFiles.length > 0) {
- copyFiles(selectedFiles, targetPath, onUploadProgress);
+ copyFiles(
+ selectedFiles,
+ targetPath,
+ currentLocation.uuid,
+ onUploadProgress,
+ );
setTargetPath('');
}
if (selectedDirs.length > 0) {
diff --git a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
index 035b2e744..72270cf92 100644
--- a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
@@ -52,10 +52,11 @@ interface Props {
onClose: (clearSelection?: boolean) => void;
selectedFiles: Array<TS.FileSystemEntry>;
targetDir?: string;
+ targetLocationId?: string;
}
function MoveOrCopyFilesDialog(props: Props) {
- const { open, onClose, selectedFiles } = props;
+ const { open, onClose, selectedFiles, targetLocationId } = props;
const { t } = useTranslation();
const theme = useTheme();
@@ -63,15 +64,16 @@ function MoveOrCopyFilesDialog(props: Props) {
const { handleEntryExist, openEntryExistDialog } =
useEntryExistDialogContext();
const { setReflectMetaActions } = useEditedEntryMetaContext();
- const { currentLocation } = useCurrentLocationContext();
+ const { findLocation } = useCurrentLocationContext();
const { moveFiles, copyFiles } = useIOActionsContext();
const { currentDirectoryPath } = useDirectoryContentContext();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
const targetDir = props.targetDir ? props.targetDir : currentDirectoryPath;
+ const targetLocation = findLocation(targetLocationId);
function generateThumbs(filePaths: string[]) {
const promises: Promise<TS.EditMetaAction>[] = filePaths.map((filePath) =>
- currentLocation.getPropertiesPromise(filePath).then((entry) => ({
+ targetLocation.getPropertiesPromise(filePath).then((entry) => ({
action: 'thumbGenerate',
entry: entry,
})),
@@ -82,14 +84,14 @@ function MoveOrCopyFilesDialog(props: Props) {
}
function handleMove(filePaths: string[]) {
- moveFiles(filePaths, targetDir, currentLocation.uuid).then((success) => {
+ moveFiles(filePaths, targetDir, targetLocation.uuid).then((success) => {
if (success) {
generateThumbs(
filePaths.map((targetPath) =>
joinPaths(
- currentLocation?.getDirSeparator(),
+ targetLocation?.getDirSeparator(),
targetDir,
- extractFileName(targetPath, currentLocation?.getDirSeparator()),
+ extractFileName(targetPath, targetLocation?.getDirSeparator()),
),
),
);
@@ -99,14 +101,14 @@ function MoveOrCopyFilesDialog(props: Props) {
}
function handleCopy(filePaths: string[]) {
- copyFiles(filePaths, targetDir).then((success) => {
+ copyFiles(filePaths, targetDir, targetLocation.uuid).then((success) => {
if (success) {
generateThumbs(
filePaths.map((targetPath) =>
joinPaths(
- currentLocation?.getDirSeparator(),
+ targetLocation?.getDirSeparator(),
targetDir,
- extractFileName(targetPath, currentLocation?.getDirSeparator()),
+ extractFileName(targetPath, targetLocation?.getDirSeparator()),
),
),
);
@@ -166,15 +168,17 @@ function MoveOrCopyFilesDialog(props: Props) {
<Button
onClick={() => {
if (selectedFiles) {
- handleEntryExist(selectedFiles, targetDir).then((exist) => {
- if (exist) {
- openEntryExistDialog(exist, () => {
+ handleEntryExist(selectedFiles, targetDir, targetLocationId).then(
+ (exist) => {
+ if (exist) {
+ openEntryExistDialog(exist, () => {
+ handleMove(selectedFiles.map((file) => file.path));
+ });
+ } else {
handleMove(selectedFiles.map((file) => file.path));
- });
- } else {
- handleMove(selectedFiles.map((file) => file.path));
- }
- });
+ }
+ },
+ );
}
onClose();
}}
@@ -187,15 +191,17 @@ function MoveOrCopyFilesDialog(props: Props) {
<Button
onClick={() => {
if (selectedFiles) {
- handleEntryExist(selectedFiles, targetDir).then((exist) => {
- if (exist) {
- openEntryExistDialog(exist, () => {
+ handleEntryExist(selectedFiles, targetDir, targetLocationId).then(
+ (exist) => {
+ if (exist) {
+ openEntryExistDialog(exist, () => {
+ handleCopy(selectedFiles.map((file) => file.path));
+ });
+ } else {
handleCopy(selectedFiles.map((file) => file.path));
- });
- } else {
- handleCopy(selectedFiles.map((file) => file.path));
- }
- });
+ }
+ },
+ );
}
onClose();
}}
diff --git a/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx
index 1715ce1bb..1218b39e3 100644
--- a/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/EntryExistDialogContextProvider.tsx
@@ -26,6 +26,7 @@ type EntryExistDialogContextData = {
handleEntryExist: (
entries: TS.FileSystemEntry[],
targetPath: string,
+ targetLocationId?: string,
) => Promise<string[]>;
openEntryExistDialog: (
existPath: string[],
@@ -47,7 +48,7 @@ export const EntryExistDialogContextProvider = ({
children,
}: EntryExistDialogContextProviderProps) => {
const { t } = useTranslation();
- const { currentLocation } = useCurrentLocationContext();
+ const { findLocation } = useCurrentLocationContext();
const confirmOverride = useRef<() => void>(undefined);
const entriesExistPath = useRef<string[]>([]);
@@ -56,14 +57,16 @@ export const EntryExistDialogContextProvider = ({
async function handleEntryExist(
entries: TS.FileSystemEntry[],
targetPath: string,
+ targetLocationId?: string,
): Promise<string[]> {
if (entries) {
let arrExist = [];
+ const location = findLocation(targetLocationId);
const selectedFiles = entries
.filter((fsEntry) => fsEntry.isFile)
.map((fsentry) => fsentry.path);
if (selectedFiles.length > 0) {
- const exist = await currentLocation.checkFilesExistPromise(
+ const exist = await location.checkFilesExistPromise(
selectedFiles,
targetPath,
);
@@ -76,7 +79,7 @@ export const EntryExistDialogContextProvider = ({
.map((fsentry) => fsentry.path);
if (selectedDirs.length > 0) {
- const exist = await currentLocation.checkDirsExistPromise(
+ const exist = await location.checkDirsExistPromise(
selectedDirs,
targetPath,
);
@@ -115,7 +118,7 @@ export const EntryExistDialogContextProvider = ({
openEntryExistDialog: openDialog,
closeEntryExistDialog: closeDialog,
};
- }, [currentLocation]);
+ }, []);
return (
<EntryExistDialogContext.Provider value={context}>
diff --git a/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx
index 637418913..1025998bc 100644
--- a/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/MoveOrCopyFilesDialogContextProvider.tsx
@@ -27,6 +27,7 @@ type MoveOrCopyFilesDialogContextData = {
openMoveOrCopyFilesDialog: (
files: Array<File>,
targetDirectory?: string,
+ targetLocationId?: string,
) => void;
closeMoveOrCopyFilesDialog: () => void;
};
@@ -54,12 +55,18 @@ export const MoveOrCopyFilesDialogContextProvider = ({
const open = useRef<boolean>(false);
const files = useRef<TS.FileSystemEntry[]>(undefined);
const targetDir = useRef<string>(undefined);
+ const targetLocationId = useRef<string>(undefined);
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
- function openDialog(selectedFiles: Array<File>, targetDirectory?: string) {
+ function openDialog(
+ selectedFiles: Array<File>,
+ targetDirectory?: string,
+ targetLocationID?: string,
+ ) {
open.current = true;
targetDir.current = targetDirectory;
+ targetLocationId.current = targetLocationID;
isDirs(selectedFiles).then((isDirsArray) => {
files.current = selectedFiles.map((file, index) => ({
uuid: getUuid(),
@@ -112,6 +119,7 @@ export const MoveOrCopyFilesDialogContextProvider = ({
onClose={closeDialog}
selectedFiles={files.current?.filter((file) => file.isFile)} // todo enable for dir
targetDir={targetDir.current}
+ targetLocationId={targetLocationId.current}
/>
{children}
</MoveOrCopyFilesDialogContext.Provider>
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index a88eba52f..e6af017f6 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -103,6 +103,7 @@ type IOActionsContextData = {
copyFiles: (
paths: Array<string>,
targetPath: string,
+ locationID: string,
onProgress?,
) => Promise<boolean>;
downloadFile: (
@@ -702,12 +703,13 @@ export const IOActionsContextProvider = ({
function copyFiles(
paths: Array<string>,
targetPath: string,
+ locationID: string,
onProgress,
): Promise<boolean> {
return copyFilesWithProgress(
paths,
targetPath,
- undefined,
+ locationID,
paths.length > 10 ? undefined : onProgress,
)
.then((success) => {
@@ -728,7 +730,7 @@ export const IOActionsContextProvider = ({
return copyFilesWithProgress(
metaPaths,
getMetaDirectoryPath(targetPath),
- undefined, //metaPaths.length > 10 ? undefined : onProgress,
+ locationID, //metaPaths.length > 10 ? undefined : onProgress,
false,
)
.then(() => {
@@ -743,7 +745,7 @@ export const IOActionsContextProvider = ({
return false;
})
.catch((err) => {
- console.log('Moving files failed with ' + err);
+ console.log('Copy files failed', err);
showNotification(t('core:copyingFilesFailed'));
return false;
});
diff --git a/src/renderer/hooks/PlatformFacadeContextProvider.tsx b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
index 9c32b3cfe..321ccf034 100644
--- a/src/renderer/hooks/PlatformFacadeContextProvider.tsx
+++ b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
@@ -277,14 +277,13 @@ export const PlatformFacadeContextProvider = ({
): Promise<boolean> {
const controller = new AbortController();
const signal = controller.signal;
+ const location = findLocation(locationID);
const ioJobPromises = paths.map((path) => {
const targetFile =
normalizePath(targetPath) +
- (currentLocation
- ? currentLocation.getDirSeparator()
- : AppConfig.dirSeparator) +
- extractFileName(path, currentLocation?.getDirSeparator());
+ (location ? location.getDirSeparator() : AppConfig.dirSeparator) +
+ extractFileName(path, location?.getDirSeparator());
return {
promise: copyFilePromiseOverwrite(path, targetFile, locationID, false),
path: path,
@@ -311,10 +310,9 @@ export const PlatformFacadeContextProvider = ({
const targetPaths = paths.map((path) =>
getAllPropertiesPromise(
normalizePath(targetPath) +
- (currentLocation
- ? currentLocation.getDirSeparator()
- : AppConfig.dirSeparator) +
- extractFileName(path, currentLocation?.getDirSeparator()),
+ (location ? location.getDirSeparator() : AppConfig.dirSeparator) +
+ extractFileName(path, location?.getDirSeparator()),
+ locationID,
),
);
return reflectAddEntryPath(...targetPaths);