Skip to content

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

DnD files from local to s3 transfers directly the sidecar files (#2339)

Stanimir2bd8b82004c4
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsx
index 90f3d8e92..0d509e092 100644
--- a/src/renderer/components/LocationView.tsx
+++ b/src/renderer/components/LocationView.tsx
@@ -56,6 +56,7 @@ import { actions as AppActions, AppDispatch } from '../reducers/app';
import DragItemTypes from './DragItemTypes';
import TargetMoveFileBox from './TargetMoveFileBox';
import { useFileUploadContext } from '-/hooks/useFileUploadContext';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
interface Props {
location: SubFolder;
@@ -66,8 +67,10 @@ interface Props {
function LocationView(props: Props) {
const { t } = useTranslation();
- const { uploadFiles } = useIOActionsContext();
+ const { uploadFilesAPI, uploadMeta } = useIOActionsContext();
+ const { setMetaUpload } = useFileUploadContext();
const { openFileUploadDialog } = useFileUploadDialogContext();
+ const { setReflectMetaActions } = useEditedEntryMetaContext();
const {
findLocation,
openLocation,
@@ -135,15 +138,15 @@ function LocationView(props: Props) {
const handleFileMoveDrop = (item, monitor) => {
if (item) {
const { entry } = item;
- let arrPath = [];
+ let arrFiles: TS.FileSystemEntry[] = [];
if (
selectedEntries &&
selectedEntries.length > 0 &&
selectedEntries.some((e) => e.path === entry.path)
) {
- arrPath = selectedEntries.map((i) => i.path);
+ arrFiles = selectedEntries; //.map((i) => i.path);
} else if (entry) {
- arrPath.push(entry.path);
+ arrFiles.push(entry);
}
if (currentLocation?.isReadOnly) {
@@ -159,36 +162,42 @@ function LocationView(props: Props) {
if (targetPath !== undefined && targetLocation !== undefined) {
// TODO handle monitor -> isOver and change folder icon
- console.log('Dropped files: ' + JSON.stringify(arrPath));
+ console.log('Dropped files in: ' + targetPath);
if (targetLocation.type !== currentLocation.type) {
//locationType.TYPE_CLOUD) {
dispatch(AppActions.resetProgress());
- openFileUploadDialog(targetPath, undefined, false);
- return (
- uploadFiles(
- arrPath,
- targetPath,
- onUploadProgress,
- true,
- false,
- targetLocation.uuid,
- )
- /* todo show meta upload button
- .then((fsEntries: Array<TS.FileSystemEntry>) => {
+ openFileUploadDialog(targetPath, undefined);
+ return uploadFilesAPI(
+ arrFiles,
+ targetPath,
+ onUploadProgress,
+ false,
+ false,
+ targetLocation.uuid,
+ currentLocation.uuid,
+ )
+ .then((fsEntries: Array<TS.FileSystemEntry>) => {
setMetaUpload(() =>
uploadMeta(
- arrPath,
+ arrFiles.map((f) => f.path),
targetPath,
onUploadProgress,
false,
targetLocation.uuid,
+ currentLocation.uuid,
),
- )
- }*/
- .catch((error) => {
- console.log('uploadFiles', error);
- })
- );
+ );
+ const actions: TS.EditMetaAction[] = fsEntries.map((entry) => ({
+ action: 'thumbGenerate',
+ entry: entry,
+ }));
+ setReflectMetaActions(...actions);
+ return true;
+ })
+ .catch((error) => {
+ console.log('uploadFiles', error);
+ setMetaUpload(undefined);
+ });
} else if (targetLocation.type === locationType.TYPE_LOCAL) {
const entries =
selectedEntries.length > 0 ? selectedEntries : [entry];
diff --git a/src/renderer/components/TargetFileBox.tsx b/src/renderer/components/TargetFileBox.tsx
index 37351dc6b..b21b99a16 100644
--- a/src/renderer/components/TargetFileBox.tsx
+++ b/src/renderer/components/TargetFileBox.tsx
@@ -92,7 +92,7 @@ function TargetFileBox(props: Props) {
);
}
dispatch(AppActions.resetProgress());
- openFileUploadDialog(undefined, undefined, true);
+ openFileUploadDialog(undefined, undefined);
const localLocation = findLocalLocation();
const sourceLocationId = localLocation ? localLocation.uuid : undefined;
return uploadFilesAPI(
diff --git a/src/renderer/components/dialogs/FileUploadDialog.tsx b/src/renderer/components/dialogs/FileUploadDialog.tsx
index e8c798423..e412bd1f8 100644
--- a/src/renderer/components/dialogs/FileUploadDialog.tsx
+++ b/src/renderer/components/dialogs/FileUploadDialog.tsx
@@ -52,19 +52,19 @@ interface Props {
open: boolean;
title: string;
targetPath?: string;
- transferMeta?: boolean;
+ //transferMeta?: boolean;
onClose: () => void;
}
function FileUploadDialog(props: Props) {
- const { open = false, transferMeta = false, title, onClose } = props;
+ const { open = false, title, onClose } = props;
const { t } = useTranslation();
const dispatch: AppDispatch = useDispatch();
const theme = useTheme();
const smallScreen = useMediaQuery(theme.breakpoints.down('md'));
const { currentDirectoryPath } = useDirectoryContentContext();
const { findLocation } = useCurrentLocationContext();
- const { uploadMeta } = useFileUploadContext();
+ const { uploadMeta, transferMeta } = useFileUploadContext();
const progress = useSelector(getProgress);
const targetPath = React.useRef<string>(getTargetPath()); // todo ContextProvider
diff --git a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
index 08d1e493f..feb61282a 100644
--- a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
@@ -104,7 +104,7 @@ function MoveCopyFilesDialog(props: Props) {
function handleCopy() {
dispatch(AppActions.resetProgress());
- openFileUploadDialog(targetDir, 'copyEntriesTitle', false); //selectedFiles.length > 0);
+ openFileUploadDialog(targetDir, 'copyEntriesTitle'); //selectedFiles.length > 0);
if (selectedFiles.length > 0) {
//todo use uploadFilesAPI && transferMeta = true
copyFiles(
@@ -144,7 +144,7 @@ function MoveCopyFilesDialog(props: Props) {
}
if (selectedDirs.length > 0) {
dispatch(AppActions.resetProgress());
- openFileUploadDialog(undefined, 'moveEntriesTitle', false);
+ openFileUploadDialog(undefined, 'moveEntriesTitle');
moveDirs(
getEntriesCount(selectedDirs),
targetPath,
diff --git a/src/renderer/components/dialogs/hooks/FileUploadDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/FileUploadDialogContextProvider.tsx
index d4f720369..61c8a4507 100644
--- a/src/renderer/components/dialogs/hooks/FileUploadDialogContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/FileUploadDialogContextProvider.tsx
@@ -32,7 +32,7 @@ type FileUploadDialogContextData = {
openFileUploadDialog: (
targetPath?: string,
dialogTitle?: string,
- transferMeta?: boolean,
+ //transferMeta?: boolean,
) => void;
closeFileUploadDialog: () => void;
};
@@ -52,7 +52,7 @@ export const FileUploadDialogContextProvider = ({
}: FileUploadDialogContextProviderProps) => {
const open = useRef<boolean>(false);
const targetPath = useRef<string>(undefined);
- const transferMeta = useRef<boolean>(undefined);
+ //const transferMeta = useRef<boolean>(undefined);
const dialogTitle = useRef<string>('importDialogTitle');
const progress = useSelector(getProgress);
const firstRender = useFirstRender();
@@ -70,10 +70,11 @@ export const FileUploadDialogContextProvider = ({
}
}, [progress]);
- function openDialog(tPath?: string, dTitle?: string, tMeta?: boolean) {
+ function openDialog(tPath?: string, dTitle?: string) {
+ //, tMeta?: boolean) {
open.current = true;
targetPath.current = tPath;
- transferMeta.current = tMeta;
+ //transferMeta.current = tMeta;
if (dTitle) {
dialogTitle.current = dTitle;
}
@@ -83,7 +84,7 @@ export const FileUploadDialogContextProvider = ({
function closeDialog() {
open.current = false;
targetPath.current = undefined;
- transferMeta.current = undefined;
+ //transferMeta.current = undefined;
dialogTitle.current = 'importDialogTitle';
forceUpdate();
}
@@ -102,7 +103,6 @@ export const FileUploadDialogContextProvider = ({
onClose={() => closeDialog()}
title={dialogTitle.current}
targetPath={targetPath.current}
- transferMeta={transferMeta.current}
/>
</FileUploadDialogContext.Provider>
);
diff --git a/src/renderer/hooks/FileUploadContextProvider.tsx b/src/renderer/hooks/FileUploadContextProvider.tsx
index 7ebc01d2a..493c44c1d 100644
--- a/src/renderer/hooks/FileUploadContextProvider.tsx
+++ b/src/renderer/hooks/FileUploadContextProvider.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { createContext, useMemo, useRef } from 'react';
+import React, { createContext, useMemo, useRef, useState } from 'react';
import FileUploadContainer, {
FileUploadContainerRef,
} from '-/components/FileUploadContainer';
@@ -25,12 +25,14 @@ type FileUploadContextData = {
openFileUpload: (dPath: string) => void;
uploadMeta: () => void;
setMetaUpload: (mUpload: () => void) => void;
+ transferMeta: boolean;
};
export const FileUploadContext = createContext<FileUploadContextData>({
openFileUpload: undefined,
uploadMeta: undefined,
setMetaUpload: undefined,
+ transferMeta: false,
});
export type FileUploadContextProviderProps = {
@@ -41,6 +43,7 @@ export const FileUploadContextProvider = ({
children,
}: FileUploadContextProviderProps) => {
const fileUploadContainerRef = useRef<FileUploadContainerRef>(null);
+ const [transferMeta, setTransferMeta] = useState<boolean>(false);
function openFileUpload(dPath: string) {
fileUploadContainerRef.current?.onFileUpload(dPath);
@@ -48,9 +51,11 @@ export const FileUploadContextProvider = ({
function uploadMeta() {
fileUploadContainerRef.current?.onMetaUpload();
+ setTransferMeta(false);
}
function setMetaUpload(mUpload: () => void) {
+ setTransferMeta(mUpload !== undefined);
fileUploadContainerRef.current?.setMetaUpload(mUpload);
}
@@ -59,8 +64,9 @@ export const FileUploadContextProvider = ({
openFileUpload: openFileUpload,
uploadMeta: uploadMeta,
setMetaUpload: setMetaUpload,
+ transferMeta,
};
- }, []);
+ }, [transferMeta]);
return (
<FileUploadContext.Provider value={context}>
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index 2935af2be..30130d2a6 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -131,7 +131,7 @@ type IOActionsContextData = {
sourceLocationId?: string,
) => Promise<TS.FileSystemEntry[]>;
uploadMeta: (
- files: Array<any>,
+ files: string[],
targetPath: string,
onUploadProgress?: (progress, abort, fileName?) => void,
open?: boolean,
@@ -1535,6 +1535,8 @@ export const IOActionsContextProvider = ({
Promise.all(entriesEnhanced).then((entries) => {
resolve(entries);
});
+ } else {
+ reject(undefined);
}
return true;
})
diff --git a/src/renderer/reducers/app.ts b/src/renderer/reducers/app.ts
index d34e2a5ca..dc2c56297 100644
--- a/src/renderer/reducers/app.ts
+++ b/src/renderer/reducers/app.ts
@@ -17,6 +17,7 @@
*/
import AppConfig from '-/AppConfig';
+import { cleanFrontDirSeparator } from '@tagspaces/tagspaces-common/paths';
import {
actions as SettingsActions,
getCheckForUpdateOnStartup,
@@ -116,9 +117,10 @@ export default (state: any = initialState, action: any) => {
return { ...state, isOnline: false, error: null };
}
case types.PROGRESS: {
+ const path = cleanFrontDirSeparator(action.path);
const arrProgress = [
{
- path: action.path,
+ path: path,
filePath: action.filePath,
progress: action.progress,
abort: action.abort,
@@ -126,7 +128,7 @@ export default (state: any = initialState, action: any) => {
},
];
state.progress.map((fileProgress) => {
- if (fileProgress && fileProgress.path !== action.path) {
+ if (fileProgress && fileProgress.path !== path) {
arrProgress.push(fileProgress);
}
return true;