Skip to content

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

fix issues with entry properties (#2047)

Stanimir654803d4506c
diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsx
index 0a50946f0..4734b70ab 100644
--- a/src/renderer/components/EntryContainer.tsx
+++ b/src/renderer/components/EntryContainer.tsx
@@ -573,7 +573,7 @@ function EntryContainer() {
PlatformIO.getDirSeparator(),
);
try {
- await copyFilePromiseOverwrite(fileOpen.path, targetPath); // todo test what happened if remove await?
+ await copyFilePromiseOverwrite(fileOpen.path, targetPath, false); // todo test what happened if remove await?
} catch (error) {
console.log('copyFilePromiseOverwrite', error);
}
@@ -595,14 +595,14 @@ function EntryContainer() {
fileEditHistoryKey,
);
}
-
- return updateOpenedFile(fileOpen.path, {
+ return true;
+ /*return updateOpenedFile(fileOpen.path, {
id: '',
...fileOpen,
editMode: true,
//changed: false,
shouldReload: undefined,
- }).then(() => true);
+ }).then(() => true);*/
})
.catch((error) => {
setConflictDialogOpen(true);
diff --git a/src/renderer/components/TargetFileBox.tsx b/src/renderer/components/TargetFileBox.tsx
index 4adfd50e7..c0c4d8867 100644
--- a/src/renderer/components/TargetFileBox.tsx
+++ b/src/renderer/components/TargetFileBox.tsx
@@ -75,7 +75,13 @@ function TargetFileBox(props: Props) {
}
dispatch(AppActions.resetProgress());
dispatch(AppActions.toggleUploadDialog());
- return uploadFilesAPI(files, currentDirectoryPath, onUploadProgress)
+ return uploadFilesAPI(
+ files,
+ currentDirectoryPath,
+ onUploadProgress,
+ true,
+ false,
+ )
.then((fsEntries: Array<TS.FileSystemEntry>) => {
/*addDirectoryEntries(fsEntries);
dispatch(AppActions.reflectCreateEntries(fsEntries));
diff --git a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
index 7910b8fab..863fb1e17 100644
--- a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
@@ -37,10 +37,9 @@ import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import DraggablePaper from '-/components/DraggablePaper';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
-import AppConfig from '-/AppConfig';
import { useTranslation } from 'react-i18next';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
-import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';
+import { useIOActionsContext } from '-/hooks/useIOActionsContext';
interface Props {
open: boolean;
@@ -54,11 +53,11 @@ function MoveOrCopyFilesDialog(props: Props) {
const theme = useTheme();
- const { copyFilePromise, renameFilePromise } = usePlatformFacadeContext();
- const { openDirectory, currentDirectoryPath } = useDirectoryContentContext();
- // const dispatch: AppDispatch = useDispatch();
+ const { moveFiles, copyFiles } = useIOActionsContext();
+ const { currentDirectoryPath } = useDirectoryContentContext();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
+ /*
const handleMoveCopyFiles = (files: Array<any>, move = false) => {
const promises = [];
for (const file of files) {
@@ -66,7 +65,9 @@ function MoveOrCopyFilesDialog(props: Props) {
promises.push(
renameFilePromise(
file.path,
- currentDirectoryPath + AppConfig.dirSeparator + file.name,
+ cleanTrailingDirSeparator(currentDirectoryPath) +
+ AppConfig.dirSeparator +
+ file.name,
)
.then(() => true)
.catch((error) => {
@@ -77,7 +78,9 @@ function MoveOrCopyFilesDialog(props: Props) {
promises.push(
copyFilePromise(
file.path,
- currentDirectoryPath + AppConfig.dirSeparator + file.name,
+ cleanTrailingDirSeparator(currentDirectoryPath) +
+ AppConfig.dirSeparator +
+ file.name,
)
.then(() => true)
.catch((error) => {
@@ -91,7 +94,7 @@ function MoveOrCopyFilesDialog(props: Props) {
.catch((error) => {
console.log('promises', error);
});
- };
+ }; */
return (
<Dialog
@@ -143,7 +146,12 @@ function MoveOrCopyFilesDialog(props: Props) {
</Button>
<Button
onClick={() => {
- handleMoveCopyFiles(props.selectedFiles, true);
+ if (props.selectedFiles) {
+ moveFiles(
+ props.selectedFiles.map((file) => file.path),
+ currentDirectoryPath,
+ );
+ }
props.onClose();
}}
data-tid="confirmMoveFilesTID"
@@ -154,7 +162,12 @@ function MoveOrCopyFilesDialog(props: Props) {
</Button>
<Button
onClick={() => {
- handleMoveCopyFiles(props.selectedFiles);
+ if (props.selectedFiles) {
+ copyFiles(
+ props.selectedFiles.map((file) => file.path),
+ currentDirectoryPath,
+ );
+ }
props.onClose();
}}
data-tid="confirmCopyFilesTID"
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 62beddcae..cf4a15e66 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -30,10 +30,9 @@ import { TS } from '-/tagspaces.namespace';
import { useTranslation } from 'react-i18next';
import {
cleanTrailingDirSeparator,
+ cleanFrontDirSeparator,
extractContainingDirectoryPath,
extractFileName,
- extractFileExtension,
- extractTagsAsObjects,
extractParentDirectoryPath,
getMetaFileLocationForDir,
getMetaDirectoryPath,
@@ -57,7 +56,6 @@ import {
import { enhanceEntry, getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useNotificationContext } from '-/hooks/useNotificationContext';
-import { loadCurrentDirMeta } from '-/services/meta-loader';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { getSearches } from '-/reducers/searches';
import { getTagColors } from '-/services/taglibrary-utils';
@@ -67,6 +65,7 @@ import { defaultSettings as defaultGridSettings } from '-/perspectives/grid';
import { defaultSettings as defaultListSettings } from '-/perspectives/list';
import { savePerspective } from '-/utils/metaoperations';
import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';
+import { loadCurrentDirMeta } from '-/services/meta-loader';
type DirectoryContentContextData = {
currentLocationPath: string;
@@ -266,7 +265,10 @@ export const DirectoryContentContextProvider = ({
(e) => e.path === action.oldEntryPath,
);
if (index !== -1) {
- currentDirectoryEntries.current[index] = action.entry;
+ currentDirectoryEntries.current[index] = {
+ ...currentDirectoryEntries.current[index],
+ ...action.entry,
+ };
}
// update ordered entries (KanBan)
if (Pro && Pro.MetaOperations) {
@@ -275,8 +277,9 @@ export const DirectoryContentContextProvider = ({
PlatformIO.getDirSeparator(),
);
if (
- cleanTrailingDirSeparator(currentDirectoryPath.current) ===
- cleanTrailingDirSeparator(dirPath)
+ cleanTrailingDirSeparator(
+ cleanFrontDirSeparator(currentDirectoryPath.current),
+ ) === cleanTrailingDirSeparator(cleanFrontDirSeparator(dirPath))
) {
const oldName = extractFileName(
action.oldEntryPath,
@@ -332,31 +335,34 @@ export const DirectoryContentContextProvider = ({
PlatformIO.getDirSeparator(),
);
if (
- cleanTrailingDirSeparator(currentDirectoryPath.current) ===
- cleanTrailingDirSeparator(dirPath)
+ cleanTrailingDirSeparator(
+ cleanFrontDirSeparator(currentDirectoryPath.current),
+ ) === cleanTrailingDirSeparator(cleanFrontDirSeparator(dirPath))
) {
currentDirectoryEntries.current.push(entry);
// reflect add KanBan folders visibility
- await toggleDirVisibility(
- { name: entry.name, uuid: entry.uuid },
- dirPath,
- false,
- );
+ if (!entry.isFile) {
+ await toggleDirVisibility(
+ { name: entry.name, uuid: entry.uuid },
+ dirPath,
+ false,
+ );
+ }
}
}
}
function reflectDeleteAction(entry: TS.FileSystemEntry) {
+ if (!entry.isFile) {
+ if (entry.path === currentDirectoryPath.current) {
+ loadParentDirectoryContent();
+ return;
+ }
+ }
let index = currentDirectoryEntries.current.findIndex(
(e) => e.path === entry.path,
);
if (index !== -1) {
- if (!entry.isFile) {
- if (entry.path === currentDirectoryPath.current) {
- loadParentDirectoryContent();
- return;
- }
- }
currentDirectoryEntries.current.splice(index, 1);
}
}
@@ -622,15 +628,17 @@ export const DirectoryContentContextProvider = ({
showHiddenEntries = undefined,
): Promise<boolean> {
if (dirPath !== undefined) {
+ const reloadMeta = currentDirectoryPath.current === dirPath;
return loadDirectoryContent(dirPath, true, showHiddenEntries).then(
(dirEntries) => {
- if (dirEntries) {
- setCurrentDirectoryEntries(dirEntries, false);
+ if (dirEntries && reloadMeta) {
+ // load meta files (reload of the same directory is not handled from ThumbGenerationContextProvider)
return loadCurrentDirMeta(dirPath, dirEntries).then((entries) => {
updateCurrentDirEntries(entries);
return true;
});
}
+ return true;
},
);
}
diff --git a/src/renderer/hooks/EditedEntryContextProvider.tsx b/src/renderer/hooks/EditedEntryContextProvider.tsx
index 1688b80e8..c476e9e66 100644
--- a/src/renderer/hooks/EditedEntryContextProvider.tsx
+++ b/src/renderer/hooks/EditedEntryContextProvider.tsx
@@ -28,8 +28,8 @@ type EditedEntryContextData = {
reflectUpdateMeta: (...path: string[]) => void;
setReflectActions: (...actionsArray: TS.EditAction[]) => void;
reflectDeleteEntries: (...entries: TS.FileSystemEntry[]) => void;
- reflectAddEntryPath: (path: string) => void;
- reflectAddEntry: (entry: TS.FileSystemEntry) => void;
+ reflectAddEntryPath: (...paths: string[]) => Promise<boolean>;
+ reflectAddEntry: (entry: TS.FileSystemEntry, open?: boolean) => void;
};
export const EditedEntryContext = createContext<EditedEntryContextData>({
@@ -90,17 +90,27 @@ export const EditedEntryContextProvider = ({
});
}
- function reflectAddEntryPath(path: string) {
- getAllPropertiesPromise(path).then((fsEntry: TS.FileSystemEntry) =>
+ function reflectAddEntryPath(...paths: string[]): Promise<boolean> {
+ const entriesPromises = paths.map((path) => getAllPropertiesPromise(path));
+ return Promise.all(entriesPromises).then((entries) => {
+ const actions: TS.EditAction[] = entries.map((entry) => ({
+ action: 'add',
+ entry: entry,
+ }));
+ setReflectActions(...actions);
+ return true;
+ });
+ /*getAllPropertiesPromise(path).then((fsEntry: TS.FileSystemEntry) =>
reflectAddEntry(fsEntry),
- );
+ );*/
}
/**
* warning: no entry.meta will be added in reflectAddEntry. To add meta use reflectAddEntryPath
* @param entry
+ * @param open
*/
- function reflectAddEntry(entry: TS.FileSystemEntry) {
+ function reflectAddEntry(entry: TS.FileSystemEntry, open = true) {
if (!entry.tags || entry.tags.length === 0) {
entry.tags = extractTagsAsObjects(
entry.name,
@@ -111,6 +121,7 @@ export const EditedEntryContextProvider = ({
const currentAction: TS.EditAction = {
action: 'add',
entry: entry,
+ open: open,
};
actions.current = [currentAction];
forceUpdate();
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index 3f2e02d35..eb81a0605 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -52,14 +52,13 @@ import {
enhanceEntry,
loadJSONString,
} from '@tagspaces/tagspaces-common/utils-io';
-import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import {
getPrefixTagContainer,
- getUseTrashCan,
getWarningOpeningFilesExternally,
} from '-/reducers/settings';
import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';
+import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';
type IOActionsContextData = {
createDirectory: (directoryPath: string) => Promise<boolean>;
@@ -96,12 +95,14 @@ type IOActionsContextData = {
targetPath: string,
onUploadProgress?: (progress: Progress, abort, fileName?) => void,
uploadMeta?: boolean,
+ open?: boolean,
) => Promise<TS.FileSystemEntry[]>;
uploadFiles: (
paths: Array<string>,
targetPath: string,
onUploadProgress?: (progress: Progress, abort, fileName?) => void,
uploadMeta?: boolean,
+ open?: boolean,
) => Promise<TS.FileSystemEntry[]>;
renameDirectory: (
directoryPath: string,
@@ -156,6 +157,7 @@ export const IOActionsContextProvider = ({
saveBinaryFilePromise,
deleteEntriesPromise,
} = usePlatformFacadeContext();
+ const { setReflectActions } = useEditedEntryContext();
const { currentDirectoryPath, openDirectory } = useDirectoryContentContext();
const warningOpeningFilesExternally = useSelector(
getWarningOpeningFilesExternally,
@@ -461,31 +463,34 @@ export const IOActionsContextProvider = ({
onProgress,
): Promise<boolean> {
return copyFilesWithProgress(paths, targetPath, onProgress)
- .then(() => {
- // todo return only copied paths
- showNotification(t('core:filesCopiedSuccessful'));
- const metaPaths = paths.flatMap((path) => [
- getMetaFileLocationForFile(path, PlatformIO.getDirSeparator()),
- getThumbFileLocationForFile(
- path,
- PlatformIO.getDirSeparator(),
- false,
- ),
- ]);
+ .then((success) => {
+ if (success) {
+ showNotification(t('core:filesCopiedSuccessful'));
+ const metaPaths = paths.flatMap((path) => [
+ getMetaFileLocationForFile(path, PlatformIO.getDirSeparator()),
+ getThumbFileLocationForFile(
+ path,
+ PlatformIO.getDirSeparator(),
+ false,
+ ),
+ ]);
- return copyFilesWithProgress(
- metaPaths,
- getMetaDirectoryPath(targetPath),
- onProgress,
- )
- .then(() => {
- console.log('Copy meta and thumbs successful');
- return true;
- })
- .catch((err) => {
- console.warn('At least one meta or thumb was not copied ' + err);
- return true;
- });
+ return copyFilesWithProgress(
+ metaPaths,
+ getMetaDirectoryPath(targetPath),
+ onProgress,
+ false,
+ )
+ .then(() => {
+ console.log('Copy meta and thumbs successful');
+ return true;
+ })
+ .catch((err) => {
+ console.warn('At least one meta or thumb was not copied ' + err);
+ return true;
+ });
+ }
+ return false;
})
.catch((err) => {
console.warn('Moving files failed with ' + err);
@@ -555,19 +560,27 @@ export const IOActionsContextProvider = ({
* @param onUploadProgress
* @param uploadMeta - try to upload meta and thumbs if available
* reader.onload not work for multiple files https://stackoverflow.com/questions/56178918/react-upload-multiple-files-using-window-filereader
+ * @param open
*/
function uploadFilesAPI(
files: Array<any>,
targetPath: string,
onUploadProgress?: (progress: Progress, abort, fileName?) => void,
uploadMeta = true,
+ open = true,
): Promise<TS.FileSystemEntry[]> {
if (AppConfig.isElectron || AppConfig.isCordovaiOS) {
const arrFiles = [];
for (let i = 0; i < files.length; i += 1) {
arrFiles.push(files[i].path);
}
- return uploadFiles(arrFiles, targetPath, onUploadProgress, uploadMeta);
+ return uploadFiles(
+ arrFiles,
+ targetPath,
+ onUploadProgress,
+ uploadMeta,
+ open,
+ );
}
return new Promise(async (resolve) => {
@@ -676,75 +689,80 @@ export const IOActionsContextProvider = ({
});
}
+ function uploadFile(
+ filePath: string,
+ fileType: string,
+ fileContent: any,
+ onUploadProgress?: (progress: Progress, response: any) => void,
+ reflect: boolean = true,
+ ) {
+ return PlatformIO.getPropertiesPromise(filePath)
+ .then((entryProps) => {
+ if (entryProps) {
+ showNotification(
+ 'File with the same name already exist, importing skipped!',
+ 'warning',
+ true,
+ );
+ dispatch(AppActions.setProgress(filePath, -1, undefined));
+ } else {
+ // dispatch(AppActions.setProgress(filePath, progress));
+ return saveBinaryFilePromise(
+ { path: filePath },
+ fileContent,
+ true,
+ onUploadProgress,
+ reflect,
+ )
+ .then((fsEntry: TS.FileSystemEntry) => {
+ // handle meta files
+ if (fileType === 'meta') {
+ try {
+ // eslint-disable-next-line no-param-reassign
+ fsEntry.meta = loadJSONString(fileContent.toString());
+ } catch (e) {
+ console.debug('cannot parse entry meta');
+ }
+ } else if (fileType === 'thumb') {
+ // eslint-disable-next-line no-param-reassign
+ fsEntry.thumbPath = fsEntry.path;
+ }
+
+ return fsEntry;
+ })
+ .catch((err) => {
+ console.log('Importing file ' + filePath + ' failed ', err);
+ showNotification(
+ 'Importing file ' + filePath + ' failed.',
+ 'error',
+ true,
+ );
+ return undefined;
+ });
+ }
+ return undefined;
+ })
+ .catch((err) => {
+ console.log('Error getting properties', err);
+ });
+ }
+
/**
* use with Electron only!
* @param paths
* @param targetPath
* @param onUploadProgress
* @param uploadMeta
+ * @param open -> open files after upload
*/
function uploadFiles(
paths: Array<string>,
targetPath: string,
onUploadProgress?: (progress: Progress, response: any) => void,
uploadMeta = true,
+ open = true,
): Promise<TS.FileSystemEntry[]> {
return new Promise((resolve, reject) => {
- function uploadFile(
- filePath: string,
- fileType: string,
- fileContent: any,
- ) {
- return PlatformIO.getPropertiesPromise(filePath)
- .then((entryProps) => {
- if (entryProps) {
- showNotification(
- 'File with the same name already exist, importing skipped!',
- 'warning',
- true,
- );
- dispatch(AppActions.setProgress(filePath, -1, undefined));
- } else {
- // dispatch(AppActions.setProgress(filePath, progress));
- return saveBinaryFilePromise(
- { path: filePath },
- fileContent,
- true,
- onUploadProgress,
- )
- .then((fsEntry: TS.FileSystemEntry) => {
- // handle meta files
- if (fileType === 'meta') {
- try {
- // eslint-disable-next-line no-param-reassign
- fsEntry.meta = loadJSONString(fileContent.toString());
- } catch (e) {
- console.debug('cannot parse entry meta');
- }
- } else if (fileType === 'thumb') {
- // eslint-disable-next-line no-param-reassign
- fsEntry.thumbPath = fsEntry.path;
- }
-
- return fsEntry;
- })
- .catch((err) => {
- console.log('Importing file ' + filePath + ' failed ', err);
- showNotification(
- 'Importing file ' + filePath + ' failed.',
- 'error',
- true,
- );
- return undefined;
- });
- }
- return undefined;
- })
- .catch((err) => {
- console.log('Error getting properties', err);
- });
- }
-
const uploadJobs = [];
paths.map((path) => {
let target =
@@ -785,7 +803,15 @@ export const IOActionsContextProvider = ({
if (AppConfig.isElectron) {
// for AWS location getFileContentPromise cannot load with io-objectore
return PlatformIO.getLocalFileContentPromise(job[0])
- .then((fileContent) => uploadFile(filePath, fileType, fileContent))
+ .then((fileContent) =>
+ uploadFile(
+ filePath,
+ fileType,
+ fileContent,
+ onUploadProgress,
+ false,
+ ),
+ )
.catch((err) => {
// console.log('Error getting file:' + job[0] + ' ' + err);
if (fileType === 'thumb' && job[3]) {
@@ -793,7 +819,13 @@ export const IOActionsContextProvider = ({
if (dataURL && dataURL.length > 6) {
const baseString = dataURL.split(',').pop();
const fileContent = base64ToArrayBuffer(baseString);
- return uploadFile(filePath, fileType, fileContent);
+ return uploadFile(
+ filePath,
+ fileType,
+ fileContent,
+ onUploadProgress,
+ false,
+ );
}
return undefined;
});
@@ -836,52 +868,59 @@ export const IOActionsContextProvider = ({
);
// Enhance entries
- resolve(
- arrFiles.map((file: TS.FileSystemEntry) => {
- const metaFilePath = getMetaFileLocationForFile(
- file.path,
- AppConfig.dirSeparator,
- );
- if (metaFilePath !== undefined) {
- for (let i = 0; i < arrMeta.length; i += 1) {
- const metaFile = arrMeta[i];
- if (
- metaFile.path.replace(/[/\\]/g, '') ===
- metaFilePath.replace(/[/\\]/g, '')
- ) {
- // eslint-disable-next-line no-param-reassign
- file.meta = metaFile.meta;
- }
+ const entriesEnhanced = arrFiles.map((file: TS.FileSystemEntry) => {
+ const metaFilePath = getMetaFileLocationForFile(
+ file.path,
+ AppConfig.dirSeparator,
+ );
+ if (metaFilePath !== undefined) {
+ for (let i = 0; i < arrMeta.length; i += 1) {
+ const metaFile = arrMeta[i];
+ if (
+ metaFile.path.replace(/[/\\]/g, '') ===
+ metaFilePath.replace(/[/\\]/g, '')
+ ) {
+ // eslint-disable-next-line no-param-reassign
+ file.meta = metaFile.meta;
}
}
- const thumbFilePath = getThumbFileLocationForFile(
- file.path,
- AppConfig.dirSeparator,
- );
- if (thumbFilePath !== undefined) {
- for (let i = 0; i < arrThumb.length; i += 1) {
- const thumbFile = arrThumb[i];
- if (
- thumbFile.path.replace(/[/\\]/g, '') ===
- thumbFilePath.replace(/[/\\]/g, '')
- ) {
- // eslint-disable-next-line no-param-reassign
- file.thumbPath = PlatformIO.getURLforPath(
- thumbFile.thumbPath,
- );
- }
+ }
+ const thumbFilePath = getThumbFileLocationForFile(
+ file.path,
+ AppConfig.dirSeparator,
+ );
+ if (thumbFilePath !== undefined) {
+ for (let i = 0; i < arrThumb.length; i += 1) {
+ const thumbFile = arrThumb[i];
+ if (
+ thumbFile.path.replace(/[/\\]/g, '') ===
+ thumbFilePath.replace(/[/\\]/g, '')
+ ) {
+ // eslint-disable-next-line no-param-reassign
+ file.thumbPath = PlatformIO.getURLforPath(
+ thumbFile.thumbPath,
+ );
}
}
- if (file.meta) {
- return enhanceEntry(
- file,
- AppConfig.tagDelimiter,
- PlatformIO.getDirSeparator(),
- );
- }
- return file;
+ }
+ if (file.meta) {
+ return enhanceEntry(
+ file,
+ AppConfig.tagDelimiter,
+ PlatformIO.getDirSeparator(),
+ );
+ }
+ return file;
+ });
+ const reflectActions: TS.EditAction[] = entriesEnhanced.map(
+ (entry) => ({
+ action: 'add',
+ entry: entry,
+ open: open,
}),
);
+ setReflectActions(...reflectActions);
+ resolve(entriesEnhanced);
} else {
// eslint-disable-next-line prefer-promise-reject-errors
reject('Upload failed');
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index 05c9e1b02..c88802e1c 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -137,7 +137,7 @@ export const OpenedEntryContextProvider = ({
openDirectory,
} = useDirectoryContentContext();
- const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();
+ const { selectedEntries } = useSelectedEntriesContext();
const { showNotification } = useNotificationContext();
const { actions } = useEditedEntryContext();
const { saveFilePromise } = usePlatformFacadeContext();
@@ -198,10 +198,10 @@ export const OpenedEntryContextProvider = ({
if (actions && actions.length > 0) {
for (const action of actions) {
if (action.action === 'add') {
- if (action.entry.isFile) {
+ if (action.open) {
+ //action.entry.isFile && action.entry.isNewFile) {
openFsEntry(action.entry, true);
}
- setSelectedEntries([action.entry]);
} else if (action.action === 'delete') {
if (
currentEntry.current &&
@@ -209,7 +209,7 @@ export const OpenedEntryContextProvider = ({
) {
closeAllFiles();
}
- } else if (action.action === 'update') {
+ } else if (action.action === 'update' || action.action === 'move') {
if (
currentEntry.current &&
action.oldEntryPath &&
@@ -518,7 +518,10 @@ export const OpenedEntryContextProvider = ({
if (fsEntry.size) {
entryForOpening.size = fsEntry.size;
}
- if (fsEntry.isNewFile) {
+ if (
+ fsEntry.isNewFile &&
+ AppConfig.editableFiles.includes(fsEntry.extension)
+ ) {
entryForOpening.editMode = true;
}
if (fsEntry.isAutoSaveEnabled !== undefined) {
@@ -817,11 +820,8 @@ export const OpenedEntryContextProvider = ({
} else if (fileType === 'md') {
fileContent = content + ' \n\n' + creationMeta + '\n';
}
- saveFilePromise({ path: filePath }, fileContent, false)
+ saveFilePromise({ path: filePath }, fileContent, false, true)
.then((fsEntry: TS.FileSystemEntry) => {
- //reflectAddEntry(fsEntry);
- // openFsEntry(fsEntry);
- // setSelectedEntries([fsEntry]);
showNotification(`File '${fileNameAndExt}' created.`, 'default', true);
return true;
})
diff --git a/src/renderer/hooks/PlatformFacadeContextProvider.tsx b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
index 51f8aeedf..2a4db9ea3 100644
--- a/src/renderer/hooks/PlatformFacadeContextProvider.tsx
+++ b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
@@ -46,10 +46,12 @@ type PlatformFacadeContextData = {
paths: Array<string>,
targetPath: string,
onProgress?,
- ) => Promise<any>;
+ reflect?: boolean,
+ ) => Promise<boolean>;
copyFilePromiseOverwrite: (
sourceFilePath: string,
targetFilePath: string,
+ reflect?,
) => Promise<any>;
renameFilePromise: (
filePath: string,
@@ -89,6 +91,7 @@ type PlatformFacadeContextData = {
param: any,
content: any,
overwrite: boolean,
+ open?: boolean,
) => Promise<any>;
saveTextFilePromise: (
param: any,
@@ -103,6 +106,7 @@ type PlatformFacadeContextData = {
progress: any, // ManagedUpload.Progress,
response: any, // AWS.Response<AWS.S3.PutObjectOutput, AWS.AWSError>
) => void,
+ reflect?,
) => Promise<TS.FileSystemEntry>;
deleteEntriesPromise: (...paths: TS.FileSystemEntry[]) => Promise<boolean>;
setFolderThumbnailPromise: (filePath: string) => Promise<string>;
@@ -135,8 +139,12 @@ export type PlatformFacadeContextProviderProps = {
export const PlatformFacadeContextProvider = ({
children,
}: PlatformFacadeContextProviderProps) => {
- const { reflectAddEntry, reflectDeleteEntries, setReflectActions } =
- useEditedEntryContext();
+ const {
+ reflectAddEntry,
+ reflectAddEntryPath,
+ reflectDeleteEntries,
+ setReflectActions,
+ } = useEditedEntryContext();
const { ignoreByWatcher, deignoreByWatcher, ignored } = useFSWatcherContext(); //watcher
const { t } = useTranslation();
@@ -213,10 +221,11 @@ export const PlatformFacadeContextProvider = ({
}
function copyFilesWithProgress(
- paths: Array<string>,
+ paths: string[],
targetPath: string,
onProgress = undefined,
- ) {
+ reflect = true,
+ ): Promise<boolean> {
const controller = new AbortController();
const signal = controller.signal;
@@ -226,25 +235,38 @@ export const PlatformFacadeContextProvider = ({
PlatformFacade.getDirSeparator() +
extractFileName(path, PlatformFacade.getDirSeparator());
return {
- promise: copyFilePromiseOverwrite(path, targetFile),
+ promise: copyFilePromiseOverwrite(path, targetFile, false),
path: path,
};
});
const progress = (completed, path) => {
- const progress = {
- loaded: completed, //processedSize,
- total: ioJobPromises.length,
- key: targetPath,
- };
- onProgress(
- progress,
- () => {
- controller.abort();
- },
- path,
- );
+ if (onProgress) {
+ const progress = {
+ loaded: completed, //processedSize,
+ total: ioJobPromises.length,
+ key: targetPath,
+ };
+ onProgress(
+ progress,
+ () => {
+ controller.abort();
+ },
+ path,
+ );
+ }
};
- return trackProgress(ioJobPromises, signal, progress);
+ return trackProgress(ioJobPromises, signal, progress).then(() => {
+ if (reflect) {
+ const targetPaths = paths.map(
+ (path) =>
+ normalizePath(targetPath) +
+ PlatformFacade.getDirSeparator() +
+ extractFileName(path, PlatformFacade.getDirSeparator()),
+ );
+ return reflectAddEntryPath(...targetPaths);
+ }
+ return true;
+ });
}
function trackProgress(promises, abortSignal, progress) {
@@ -289,15 +311,18 @@ export const PlatformFacadeContextProvider = ({
function copyFilePromiseOverwrite(
sourceFilePath: string,
targetFilePath: string,
+ reflect: boolean = true,
): Promise<any> {
ignoreByWatcher(targetFilePath);
return PlatformFacade.copyFilePromiseOverwrite(
sourceFilePath,
targetFilePath,
).then((result) => {
- getAllPropertiesPromise(targetFilePath).then(
- (fsEntry: TS.FileSystemEntry) => reflectAddEntry(fsEntry),
- );
+ if (reflect) {
+ getAllPropertiesPromise(targetFilePath).then(
+ (fsEntry: TS.FileSystemEntry) => reflectAddEntry(fsEntry),
+ );
+ }
deignoreByWatcher(targetFilePath);
return result;
});
@@ -503,11 +528,12 @@ export const PlatformFacadeContextProvider = ({
param: any,
content: any,
overwrite: boolean,
+ open: boolean = false,
): Promise<TS.FileSystemEntry> {
ignoreByWatcher(param.path);
return PlatformFacade.saveFilePromise(param, content, overwrite).then(
(fsEntry) => {
- reflectAddEntry(fsEntry);
+ reflectAddEntry(fsEntry, open);
deignoreByWatcher(param.path);
return fsEntry;
},
@@ -517,12 +543,19 @@ export const PlatformFacadeContextProvider = ({
function saveTextFilePromise(
param: any,
content: string,
- overwrite: boolean,
+ isUpdated: boolean,
): Promise<TS.FileSystemEntry> {
ignoreByWatcher(param.path);
- return PlatformFacade.saveTextFilePromise(param, content, overwrite).then(
+ return PlatformFacade.saveTextFilePromise(param, content, isUpdated).then(
(fsEntry) => {
- reflectAddEntry(fsEntry);
+ if (isUpdated) {
+ setReflectActions({
+ action: 'update',
+ entry: fsEntry,
+ });
+ } else {
+ reflectAddEntry(fsEntry);
+ }
deignoreByWatcher(param.path);
return fsEntry;
},
@@ -537,6 +570,7 @@ export const PlatformFacadeContextProvider = ({
progress: any, // ManagedUpload.Progress,
response: any, // AWS.Response<AWS.S3.PutObjectOutput, AWS.AWSError>
) => void,
+ reflect: boolean = true,
): Promise<TS.FileSystemEntry> {
ignoreByWatcher(param.path);
return PlatformFacade.saveBinaryFilePromise(
@@ -545,7 +579,9 @@ export const PlatformFacadeContextProvider = ({
overwrite,
onUploadProgress,
).then((fsEntry) => {
- reflectAddEntry(fsEntry);
+ if (reflect) {
+ reflectAddEntry(fsEntry);
+ }
deignoreByWatcher(param.path);
return fsEntry;
});
diff --git a/src/renderer/hooks/SelectedEntryContextProvider.tsx b/src/renderer/hooks/SelectedEntryContextProvider.tsx
index e2260aecc..c754b901e 100644
--- a/src/renderer/hooks/SelectedEntryContextProvider.tsx
+++ b/src/renderer/hooks/SelectedEntryContextProvider.tsx
@@ -63,18 +63,22 @@ export const SelectedEntryContextProvider = ({
useEffect(() => {
if (actions && actions.length > 0) {
+ let selected = [...selectedEntries.current];
for (const action of actions) {
if (action.action === 'add') {
- if (selectedEntries.current.length === 0) {
- // don't change selection if copy dialog with selected entry is opened
- selectedEntries.current = [action.entry];
- }
+ if (action.entry.isFile) {
+ selected.push(action.entry);
+ } /*else if (selectedEntries.current.length === 0) {
+ //todo tmp fix don't change selection if copy dialog with selected entry is opened
+ selected.push(action.entry);
+ }*/
} else if (action.action === 'delete') {
let index = selectedEntries.current.findIndex(
(e) => e.path === action.entry.path,
);
if (index !== -1) {
selectedEntries.current.splice(index, 1);
+ selected = [...selectedEntries.current];
}
} else if (action.action === 'update') {
let index = selectedEntries.current.findIndex(
@@ -82,10 +86,11 @@ export const SelectedEntryContextProvider = ({
);
if (index !== -1) {
selectedEntries.current[index] = action.entry;
+ selected = [...selectedEntries.current];
}
}
}
- selectedEntries.current = [...selectedEntries.current];
+ selectedEntries.current = selected;
forceUpdate();
}
}, [actions]);
@@ -118,7 +123,7 @@ export const SelectedEntryContextProvider = ({
};
const lastSelectedEntryPath = useMemo(() => {
- if (selectedEntries.current.length > 0) {
+ if (selectedEntries.current && selectedEntries.current.length > 0) {
return selectedEntries.current[selectedEntries.current.length - 1].path;
}
return undefined;
diff --git a/src/renderer/perspectives/grid/components/GridPagination.tsx b/src/renderer/perspectives/grid/components/GridPagination.tsx
index 132f65573..2093fcbc8 100644
--- a/src/renderer/perspectives/grid/components/GridPagination.tsx
+++ b/src/renderer/perspectives/grid/components/GridPagination.tsx
@@ -53,6 +53,7 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';
import GridCellsContainer from './GridCellsContainer';
+import { useSortedDirContext } from '-/perspectives/grid/hooks/useSortedDirContext';
interface Props {
directories: Array<TS.FileSystemEntry>;
@@ -111,8 +112,8 @@ function GridPagination(props: Props) {
const { moveFiles, openFileNatively } = useIOActionsContext();
const { showNotification } = useNotificationContext();
const { readOnlyMode, currentLocation } = useCurrentLocationContext();
- const { currentDirectoryEntries, openDirectory, directoryMeta } =
- useDirectoryContentContext();
+ const { openDirectory, directoryMeta } = useDirectoryContentContext();
+ const { sortedDirContent } = useSortedDirContext();
const { page, pageFiles, setCurrentPage } = usePaginationContext();
if (!showDirectories) {
directories = [];
@@ -351,7 +352,7 @@ function GridPagination(props: Props) {
selectedEntries,
setSelectedEntries,
lastSelectedEntryPath,
- currentDirectoryEntries,
+ sortedDirContent,
openEntry,
openFileNatively,
openDirectory,
@@ -375,7 +376,7 @@ function GridPagination(props: Props) {
selectedEntries,
setSelectedEntries,
lastSelectedEntryPath,
- currentDirectoryEntries,
+ sortedDirContent,
openEntry,
openFileNatively,
openDirectory,
diff --git a/src/renderer/perspectives/grid/components/MainContainer.tsx b/src/renderer/perspectives/grid/components/MainContainer.tsx
index f942c3616..2249ca5ed 100644
--- a/src/renderer/perspectives/grid/components/MainContainer.tsx
+++ b/src/renderer/perspectives/grid/components/MainContainer.tsx
@@ -16,11 +16,9 @@
*
*/
-import React, { useEffect, useRef, useState } from 'react';
+import React, { useRef, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { GlobalHotKeys } from 'react-hotkeys';
-import { isObj } from '@tagspaces/tagspaces-common/misc';
-import { isVisibleOnScreen } from '-/utils/dom';
import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';
import FileMenu from '-/components/menus/FileMenu';
import DirectoryMenu from '-/components/menus/DirectoryMenu';
@@ -29,10 +27,7 @@ import AddRemoveTagsDialog from '-/components/dialogs/AddRemoveTagsDialog';
import MoveCopyFilesDialog from '-/components/dialogs/MoveCopyFilesDialog';
import TagDropContainer from '-/components/TagDropContainer';
import { actions as AppActions, AppDispatch } from '-/reducers/app';
-import GridCell, {
- calculateEntryHeight,
- calculateEntryWidth,
-} from './GridCell';
+import GridCell from './GridCell';
import MainToolbar from '-/perspectives/grid/components/MainToolbar';
import SortingMenu from '-/perspectives/grid/components/SortingMenu';
import GridOptionsMenu from '-/perspectives/grid/components/GridOptionsMenu';
diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsx
index db67ec395..7e484fb15 100644
--- a/src/renderer/perspectives/list/components/MainContainer.tsx
+++ b/src/renderer/perspectives/list/components/MainContainer.tsx
@@ -16,11 +16,9 @@
*
*/
-import React, { useEffect, useRef, useState } from 'react';
+import React, { useRef, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { GlobalHotKeys } from 'react-hotkeys';
-import { isObj } from '@tagspaces/tagspaces-common/misc';
-import { isVisibleOnScreen } from '-/utils/dom';
import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';
import FileMenu from '-/components/menus/FileMenu';
import DirectoryMenu from '-/components/menus/DirectoryMenu';
diff --git a/src/renderer/perspectives/list/components/RowCell.tsx b/src/renderer/perspectives/list/components/RowCell.tsx
index f6ae35601..d854da1ac 100644
--- a/src/renderer/perspectives/list/components/RowCell.tsx
+++ b/src/renderer/perspectives/list/components/RowCell.tsx
@@ -107,15 +107,15 @@ interface Props {
export function calculateEntryHeight(entrySize: TS.EntrySizes) {
let entryHeight = 200;
if (entrySize === 'tiny') {
- entryHeight = 30;
+ entryHeight = 35;
} else if (entrySize === 'small') {
- entryHeight = 70;
+ entryHeight = 55;
} else if (entrySize === 'normal') {
- entryHeight = 90;
+ entryHeight = 75;
} else if (entrySize === 'big') {
- entryHeight = 120;
+ entryHeight = 95;
} else if (entrySize === 'huge') {
- entryHeight = 150;
+ entryHeight = 115;
}
return entryHeight;
}
diff --git a/src/renderer/services/meta-loader.ts b/src/renderer/services/meta-loader.ts
index 70f264c54..726146093 100644
--- a/src/renderer/services/meta-loader.ts
+++ b/src/renderer/services/meta-loader.ts
@@ -16,9 +16,6 @@ export function loadCurrentDirMeta(
): Promise<TS.FileSystemEntry[]> {
return PlatformIO.listMetaDirectoryPromise(directoryPath)
.then((meta) => {
- //metaLoadedLock.current = false;
- //props.setIsMetaLoaded(true);
- // props.setMetaForCurrentDir(meta);
const dirEntriesPromises = dirEntries
.filter((entry) => !entry.isFile)
.map((entry) => getEnhancedDir(entry));
@@ -72,7 +69,7 @@ function getFileEntriesPromises(
[entry.path]: getMetaForEntry(entry, metaFilePath)
});*/
}
- return Promise.resolve(undefined); //Promise.resolve({ [entry.path]: undefined });
+ return Promise.resolve(entry); //Promise.resolve({ [entry.path]: undefined });
});
}
diff --git a/src/renderer/services/platform-facade.ts b/src/renderer/services/platform-facade.ts
index a0a8daf05..02c8d8c69 100644
--- a/src/renderer/services/platform-facade.ts
+++ b/src/renderer/services/platform-facade.ts
@@ -20,6 +20,7 @@ import * as cordovaIO from '@tagspaces/tagspaces-common-cordova';
import AppConfig from '-/AppConfig';
import { TS } from '-/tagspaces.namespace';
import { Pro } from '-/pro';
+import { openUrlForWeb } from '-/services/utils-io';
let objectStoreAPI, webDavAPI;
@@ -811,7 +812,8 @@ export default class PlatformFacade {
if (AppConfig.isElectron) {
window.electronIO.ipcRenderer.sendMessage('openUrl', url);
} else {
- console.error('Is supported only in Electron');
+ // web or cordova
+ openUrlForWeb(url);
}
};
diff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.ts
index 3ab306cb4..c2f7b19f6 100644
--- a/src/renderer/services/utils-io.ts
+++ b/src/renderer/services/utils-io.ts
@@ -1633,3 +1633,19 @@ export function openURLExternally(url: string, skipConfirmation = false) {
PlatformIO.openUrl(url);
}
}
+
+export function openUrlForWeb(url) {
+ const tmpLink = document.createElement('a');
+ tmpLink.target = '_blank';
+ tmpLink.href = url;
+ tmpLink.rel = 'noopener noreferrer';
+ document.body.appendChild(tmpLink);
+ tmpLink.click();
+ tmpLink.parentNode.removeChild(tmpLink);
+ // window.open(url, '_blank').opener = null;
+ // Object.assign(anchor, {
+ // target: '_blank',
+ // href: url,
+ // rel: 'noopener noreferrer'
+ // }).click();
+}
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 00240c889..867fba37b 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -103,6 +103,7 @@ export namespace TS {
action: 'add' | 'delete' | 'update' | 'move';
entry: TS.FileSystemEntry;
oldEntryPath?: string;
+ open?: boolean;
}
interface Tag {
diff --git a/tests/e2e/markdown-editor.pw.e2e.js b/tests/e2e/markdown-editor.pw.e2e.js
index 975e04d59..bc406373d 100644
--- a/tests/e2e/markdown-editor.pw.e2e.js
+++ b/tests/e2e/markdown-editor.pw.e2e.js
@@ -75,7 +75,7 @@ test.describe('TST69 - Markdown editor', () => {
getGridFileSelector('sample.md'),
'fileMenuOpenFile',
);
-
+ await clickOn('[data-tid=fileContainerEditFile]');
// Access the iframe
const iframeElement = await global.client.waitForSelector('iframe');
const frame = await iframeElement.contentFrame();