Skip to content

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

Choosing folder thumbnail and background image broken in folder prope… (#2062)

Stanimir68b18131b4a1
diff --git a/package.json b/package.json
index e8c5d4a70..7afacd4ae 100644
--- a/package.json
+++ b/package.json
@@ -157,10 +157,10 @@
"@mui/lab": "5.0.0-alpha.160",
"@mui/material": "^5.15.4",
"@mui/x-date-pickers": "^5.0.20",
- "@tagspaces/tagspaces-common": "4.1.7",
+ "@tagspaces/tagspaces-common": "4.1.8",
"@tagspaces/tagspaces-common-aws": "4.1.9",
- "@tagspaces/tagspaces-common-cordova": "4.1.7",
- "@tagspaces/tagspaces-indexer": "4.1.7",
+ "@tagspaces/tagspaces-common-cordova": "4.1.8",
+ "@tagspaces/tagspaces-indexer": "4.1.8",
"@tagspaces/tagspaces-md": "4.0.3",
"aws-amplify": "^4.3.8",
"aws-sdk": "^2.1036.0",
@@ -225,7 +225,7 @@
"uuid": "^9.0.0"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.16"
+ "@tagspacespro/tagspacespro": "5.0.17"
},
"devDependencies": {
"@electron/notarize": "^2.2.0",
diff --git a/release/app/package.json b/release/app/package.json
index 2b3867f7f..8922758a6 100644
--- a/release/app/package.json
+++ b/release/app/package.json
@@ -19,7 +19,7 @@
"dependencies": {
"@elife/pm2": "3.6.1",
"@tagspaces/extensions": "1.0.97",
- "@tagspaces/tagspaces-common-node": "4.1.7",
+ "@tagspaces/tagspaces-common-node": "4.1.8",
"@tagspaces/tagspaces-ws": "4.1.9",
"sharp": "0.32.6",
"ws": "8.16.0"
diff --git a/src/renderer/components/EditDescription.tsx b/src/renderer/components/EditDescription.tsx
index 5ef895b1a..990499b17 100644
--- a/src/renderer/components/EditDescription.tsx
+++ b/src/renderer/components/EditDescription.tsx
@@ -3,7 +3,6 @@ import { styled, useTheme } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import { MilkdownEditor, MilkdownRef } from '@tagspaces/tagspaces-md';
import { useTranslation } from 'react-i18next';
-import { OpenedEntry } from '-/reducers/app';
import { useDescriptionContext } from '-/hooks/useDescriptionContext';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import EditDescriptionButtons from '-/components/EditDescriptionButtons';
diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsx
index 5aee0789b..8feecaebf 100644
--- a/src/renderer/components/EntryContainer.tsx
+++ b/src/renderer/components/EntryContainer.tsx
@@ -49,7 +49,6 @@ import {
isRevisionsEnabled,
getEntryContainerTab,
} from '-/reducers/settings';
-import { OpenedEntry } from '-/reducers/app';
import useEventListener from '-/utils/useEventListener';
import { TS } from '-/tagspaces.namespace';
import FileView from '-/components/FileView';
@@ -69,6 +68,7 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';
import { toFsEntry } from '-/services/utils-io';
import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';
import { SaveIcon, EditIcon } from '-/components/CommonIcons';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
//const defaultSplitSize = '7.86%'; // '7.2%'; // 103;
// const bufferedSplitResize = buffer({
@@ -84,13 +84,14 @@ function EntryContainer() {
const {
openedEntry,
closeAllFiles,
- updateOpenedFile,
reloadOpenedFile,
toggleEntryFullWidth,
isEntryInFullWidth,
reflectUpdateOpenedFileContent,
+ addToEntryContainer,
} = useOpenedEntryContext();
const { saveDescription } = useDescriptionContext();
+ const { setAutoSave } = useEditedEntryMetaContext();
const { readOnlyMode, switchLocationTypeByID, switchCurrentLocationType } =
useCurrentLocationContext();
const { openDirectory, currentDirectoryPath } = useDirectoryContentContext();
@@ -237,10 +238,10 @@ function EntryContainer() {
});
useEffect(() => {
- if (openedEntry && openedEntry.isAutoSaveEnabled) {
+ if (openedEntry && openedEntry.meta && openedEntry.meta.autoSave) {
if (fileChanged.current) {
timer.current = setInterval(() => {
- if (openedEntry.isAutoSaveEnabled && fileChanged.current) {
+ if (openedEntry.meta.autoSave && fileChanged.current) {
startSavingFile();
console.debug('autosave');
}
@@ -560,7 +561,7 @@ function EntryContainer() {
);
};
- async function save(fileOpen: OpenedEntry): Promise<boolean> {
+ async function save(fileOpen: TS.OpenedEntry): Promise<boolean> {
// @ts-ignore
const textContent = fileViewer.current.contentWindow.getContent();
if (Pro && revisionsEnabled) {
@@ -614,14 +615,15 @@ function EntryContainer() {
}
const editOpenedFile = () => {
- switchLocationTypeByID(openedEntry.locationId).then(() => {
+ addToEntryContainer({ ...openedEntry, editMode: true });
+ /* switchLocationTypeByID(openedEntry.locationId).then(() => {
updateOpenedFile(openedEntry.path, {
id: '',
...openedEntry,
editMode: true,
shouldReload: undefined,
}).then(() => switchCurrentLocationType());
- });
+ });*/
};
/*const setPercent = (p: number | undefined) => {
@@ -674,7 +676,8 @@ function EntryContainer() {
const toggleAutoSave = (event: React.ChangeEvent<HTMLInputElement>) => {
const autoSave = event.target.checked;
if (Pro && Pro.MetaOperations) {
- switchLocationTypeByID(openedEntry.locationId).then(
+ setAutoSave(openedEntry, autoSave, openedEntry.locationId);
+ /*switchLocationTypeByID(openedEntry.locationId).then(
(currentLocationId) => {
Pro.MetaOperations.saveFsEntryMeta(openedEntry.path, {
autoSave,
@@ -684,7 +687,7 @@ function EntryContainer() {
);
});
},
- );
+ );*/
} else {
showNotification(t('core:thisFunctionalityIsAvailableInPro'));
}
@@ -710,10 +713,7 @@ function EntryContainer() {
>
<Switch
data-tid="autoSaveTID"
- checked={
- openedEntry.isAutoSaveEnabled !== undefined &&
- openedEntry.isAutoSaveEnabled
- }
+ checked={openedEntry.meta && openedEntry.meta.autoSave}
onChange={toggleAutoSave}
name="autoSave"
color="primary"
@@ -972,13 +972,13 @@ function EntryContainer() {
startSavingFile();
} else {
setSaveBeforeReloadConfirmDialogOpened(false);
- updateOpenedFile(openedEntry.path, {
+ /*updateOpenedFile(openedEntry.path, {
id: '',
...openedEntry,
editMode: false,
// changed: false,
shouldReload: true,
- });
+ });*/
fileChanged.current = false;
}
}}
diff --git a/src/renderer/components/EntryContainerMenu.tsx b/src/renderer/components/EntryContainerMenu.tsx
index 0925411cf..05a1d69d6 100644
--- a/src/renderer/components/EntryContainerMenu.tsx
+++ b/src/renderer/components/EntryContainerMenu.tsx
@@ -13,7 +13,6 @@ import {
MenuList,
Divider,
} from '@mui/material';
-import { OpenedEntry } from '-/reducers/app';
import { useSelector } from 'react-redux';
import AppConfig from '-/AppConfig';
import {
diff --git a/src/renderer/components/EntryContainerTabs.tsx b/src/renderer/components/EntryContainerTabs.tsx
index a6b6e4d6a..f54d13ab2 100644
--- a/src/renderer/components/EntryContainerTabs.tsx
+++ b/src/renderer/components/EntryContainerTabs.tsx
@@ -22,7 +22,7 @@ import { useSelector, useDispatch } from 'react-redux';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
-import { AppDispatch, OpenedEntry } from '-/reducers/app';
+import { AppDispatch } from '-/reducers/app';
import Revisions from '-/components/Revisions';
import EntryProperties from '-/components/EntryProperties';
import {
diff --git a/src/renderer/components/EntryContainerTitle.tsx b/src/renderer/components/EntryContainerTitle.tsx
index 7e4f8b15c..b27bd44d8 100644
--- a/src/renderer/components/EntryContainerTitle.tsx
+++ b/src/renderer/components/EntryContainerTitle.tsx
@@ -175,7 +175,7 @@ function EntryContainerTitle(props: Props) {
setAnchorEl(event.currentTarget);
}}
style={{
- backgroundColor: openedEntry.color,
+ backgroundColor: openedEntry.meta?.color,
display: 'flex',
alignItems: 'center',
textTransform: 'uppercase',
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsx
index 34e7cb6e2..e433ba766 100644
--- a/src/renderer/components/EntryProperties.tsx
+++ b/src/renderer/components/EntryProperties.tsx
@@ -24,10 +24,7 @@ import React, {
useState,
} from 'react';
import { styled, useTheme } from '@mui/material/styles';
-import {
- getBgndFileLocationForDirectory,
- getMetaFileLocationForFile,
-} from '@tagspaces/tagspaces-common/paths';
+import { getMetaFileLocationForFile } from '@tagspaces/tagspaces-common/paths';
import L from 'leaflet';
import {
Grid,
@@ -56,8 +53,6 @@ import { ButtonGroup, IconButton } from '@mui/material';
import { formatBytes } from '@tagspaces/tagspaces-common/misc';
import {
extractContainingDirectoryPath,
- getThumbFileLocationForFile,
- getThumbFileLocationForDirectory,
extractFileName,
extractDirectoryName,
} from '@tagspaces/tagspaces-common/paths';
@@ -66,7 +61,8 @@ import MoveCopyFilesDialog from './dialogs/MoveCopyFilesDialog';
import {
fileNameValidation,
dirNameValidation,
- normalizeUrl,
+ getFolderBgndPath,
+ getThumbPath,
} from '-/services/utils-io';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { parseGeoLocation } from '-/utils/geo';
@@ -74,12 +70,6 @@ import { Pro } from '../pro';
import PlatformIO from '../services/platform-facade';
import TagsSelect from './TagsSelect';
import TransparentBackground from './TransparentBackground';
-import { getThumbnailURLPromise } from '-/services/thumbsgenerator';
-import {
- AppDispatch,
- getLastBackgroundImageChange,
- getLastThumbnailImageChange,
-} from '-/reducers/app';
import MarkerIcon from '-/assets/icons/marker-icon.png';
import Marker2xIcon from '-/assets/icons/marker-icon-2x.png';
import MarkerShadowIcon from '-/assets/icons/marker-shadow.png';
@@ -89,21 +79,18 @@ import NoTileServer from '-/components/NoTileServer';
import InfoIcon from '-/components/InfoIcon';
import { ProTooltip } from '-/components/HelperComponents';
import PerspectiveSelector from '-/components/PerspectiveSelector';
-import { useDispatch, useSelector } from 'react-redux';
import FormHelperText from '@mui/material/FormHelperText';
-import { actions as AppActions } from '-/reducers/app';
-import useFirstRender from '-/utils/useFirstRender';
import LinkGeneratorDialog from '-/components/dialogs/LinkGeneratorDialog';
import { LinkIcon } from '-/components/CommonIcons';
import { useTranslation } from 'react-i18next';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';
import { useIOActionsContext } from '-/hooks/useIOActionsContext';
-import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';
import RefreshIcon from '@mui/icons-material/Refresh';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
const PREFIX = 'EntryProperties';
@@ -201,31 +188,22 @@ const defaultBackgrounds = [
function EntryProperties(props: Props) {
const { t } = useTranslation();
const theme = useTheme();
- const { openedEntry, updateOpenedFile, sharingLink, getOpenedDirProps } =
+ const { openedEntry, sharingLink, getOpenedDirProps } =
useOpenedEntryContext();
const { renameDirectory, renameFile } = useIOActionsContext();
+ const { setBackgroundColorChange, saveDirectoryPerspective } =
+ useEditedEntryMetaContext();
const { addTags, removeTags, removeAllTags } = useTaggingActionsContext();
- const {
- currentDirectoryPath,
- updateThumbnailUrl,
- setDirectoryMeta,
- setDirectoryPerspective,
- } = useDirectoryContentContext();
const { switchLocationTypeByID, switchCurrentLocationType, readOnlyMode } =
useCurrentLocationContext();
const { showNotification } = useNotificationContext();
const { ignoreByWatcher, deignoreByWatcher } = useFSWatcherContext();
- const dispatch: AppDispatch = useDispatch();
const dirProps = useRef<TS.DirProp>(undefined);
const fileNameRef = useRef<HTMLInputElement>(null);
const sharingLinkRef = useRef<HTMLInputElement>(null);
- // const fileDescriptionRef = useRef<MilkdownRef>(null);
const disableConfirmButton = useRef<boolean>(true);
const fileNameError = useRef<boolean>(false);
- //const openedEntry = openedEntries[0];
- const lastBackgroundImageChange = useSelector(getLastBackgroundImageChange);
- const lastThumbnailImageChange = useSelector(getLastThumbnailImageChange);
const entryName = openedEntry
? openedEntry.isFile
@@ -245,11 +223,8 @@ function EntryProperties(props: Props) {
const [isBgndImgChooseDialogOpened, setBgndImgChooseDialogOpened] =
useState<boolean>(false);
const [displayColorPicker, setDisplayColorPicker] = useState<boolean>(false);
- const bgndUrl = useRef<string>(getBgndUrl());
- const thumbUrl = useRef<string>(getThumbUrl());
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
- const firstRender = useFirstRender();
useEffect(() => {
if (editName === entryName && fileNameRef.current) {
@@ -257,20 +232,6 @@ function EntryProperties(props: Props) {
}
}, [editName]);
- useEffect(() => {
- if (!firstRender) {
- bgndUrl.current = getBgndUrl();
- forceUpdate();
- }
- }, [lastBackgroundImageChange]);
-
- useEffect(() => {
- if (!firstRender) {
- thumbUrl.current = getThumbUrl();
- forceUpdate();
- }
- }, [lastThumbnailImageChange]);
-
const renameEntry = () => {
if (editName !== undefined) {
const path = extractContainingDirectoryPath(
@@ -355,47 +316,6 @@ function EntryProperties(props: Props) {
return t(PlatformIO.haveObjectStoreSupport() ? 'core:notAvailable' : '?');
};
- const setThumb = (filePath, thumbFilePath) => {
- if (filePath !== undefined) {
- return switchLocationTypeByID(openedEntry.locationId).then(
- (currentLocationId) => {
- if (
- PlatformIO.haveObjectStoreSupport() ||
- PlatformIO.haveWebDavSupport()
- ) {
- updateThumbnailUrl(
- openedEntry.path,
- PlatformIO.getURLforPath(thumbFilePath),
- );
- return true;
- }
- /*return replaceThumbnailURLPromise(filePath, thumbFilePath)
- .then(objUrl => {*/
- updateThumbnailUrl(
- openedEntry.path,
- thumbFilePath,
- // objUrl.tmbPath
- /*(props.lastThumbnailImageChange
- ? '?' + props.lastThumbnailImageChange
- : '')*/
- );
- return switchCurrentLocationType();
- },
- );
- } else {
- // reset Thumbnail
- return getThumbnailURLPromise(openedEntry.path)
- .then((objUrl) => {
- updateThumbnailUrl(openedEntry.path, objUrl.tmbPath);
- return true;
- })
- .catch((err) => {
- console.warn('Error getThumbnailURLPromise ' + err);
- showNotification('Error reset Thumbnail');
- });
- }
- };
-
const toggleBackgroundColorPicker = () => {
if (readOnlyMode) {
return;
@@ -416,35 +336,9 @@ function EntryProperties(props: Props) {
// eslint-disable-next-line no-param-reassign
color = 'transparent';
}
- openedEntry.color = color;
- switchLocationTypeByID(openedEntry.locationId).then((currentLocationId) => {
- Pro.MetaOperations.saveFsEntryMeta(openedEntry.path, { color })
- .then((entryMeta) => {
- if (openedEntry.path === currentDirectoryPath) {
- setDirectoryMeta(entryMeta);
- }
- // for KanBan
- dispatch(
- AppActions.setLastBackgroundColorChange(
- openedEntry.path,
- new Date().getTime(),
- ),
- );
- // todo handle LastBackgroundColorChange and skip updateOpenedFile
- updateOpenedFile(openedEntry.path, entryMeta).then(() =>
- switchCurrentLocationType(),
- );
-
- /* } else {
- setCurrentEntry({ ...openedEntry, color });
- } */
- return true;
- })
- .catch((error) => {
- switchCurrentLocationType();
- console.warn('Error saving color for folder ' + error);
- showNotification(t('Error saving color for folder'));
- });
+ //openedEntry.color = color;
+ setBackgroundColorChange(openedEntry, color).then(() => {
+ openedEntry.meta = { ...openedEntry.meta, color };
});
};
@@ -468,15 +362,6 @@ function EntryProperties(props: Props) {
}
};
- /*const handleDescriptionChange = (event: ChangeEvent<HTMLInputElement>) => {
- const { target } = event;
- const { value, name } = target;
-
- if (name === 'description') {
- setEditDescription(value);
- }
- };*/
-
const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {
const metaFilePath = getMetaFileLocationForFile(
openedEntry.path,
@@ -489,12 +374,12 @@ function EntryProperties(props: Props) {
if (action === 'remove-value') {
if (!value) {
// no tags left in the select element
- return removeAllTags([openedEntry.path]).then(() =>
+ return removeAllTags([openedEntry.path]); /*.then(() =>
updateOpenedFile(openedEntry.path, {
id: '',
tags: [],
}),
- );
+ );*/
} else {
return removeTags([openedEntry.path], value);
}
@@ -520,71 +405,6 @@ function EntryProperties(props: Props) {
return <div />;
}
- function getBgndUrl() {
- if (openedEntry && !openedEntry.isFile) {
- const bgndPath = getBgndFileLocationForDirectory(
- openedEntry.path,
- PlatformIO.getDirSeparator(),
- );
- if (bgndPath !== undefined) {
- if (
- PlatformIO.haveObjectStoreSupport() ||
- PlatformIO.haveWebDavSupport()
- ) {
- return PlatformIO.getURLforPath(bgndPath);
- } else {
- return (
- normalizeUrl(bgndPath) +
- (lastBackgroundImageChange &&
- lastBackgroundImageChange.folderPath === bgndPath
- ? '?' + lastBackgroundImageChange.dt
- : '')
- );
- }
- }
- }
- return undefined;
- }
-
- function getThumbPath() {
- if (!openedEntry) {
- return undefined;
- }
- if (openedEntry.isFile) {
- return getThumbFileLocationForFile(
- openedEntry.path,
- PlatformIO.getDirSeparator(),
- false,
- );
- }
- return getThumbFileLocationForDirectory(
- openedEntry.path,
- PlatformIO.getDirSeparator(),
- );
- }
-
- function getThumbUrl() {
- const thumbPath = getThumbPath();
-
- if (thumbPath !== undefined) {
- if (
- PlatformIO.haveObjectStoreSupport() ||
- PlatformIO.haveWebDavSupport()
- ) {
- return PlatformIO.getURLforPath(thumbPath);
- } else {
- return (
- normalizeUrl(thumbPath) +
- (lastThumbnailImageChange &&
- lastThumbnailImageChange.thumbPath === thumbPath
- ? '?' + lastThumbnailImageChange.dt
- : '')
- );
- }
- }
- return undefined;
- }
-
const ldtm = openedEntry.lmdt
? new Date(openedEntry.lmdt)
.toISOString()
@@ -595,21 +415,21 @@ function EntryProperties(props: Props) {
const changePerspective = (event: any) => {
const perspective = event.target.value;
- setDirectoryPerspective(perspective, openedEntry.path, false)
- .then((entryMeta: TS.FileSystemEntryMeta) => {
- // openedEntry = {...openedEntry, perspective: perspective}
- return updateOpenedFile(openedEntry.path, entryMeta);
- // return true;
+ openedEntry.meta.perspective = perspective;
+ saveDirectoryPerspective(openedEntry, perspective, openedEntry.locationId);
+ /*.then((entryMeta: TS.FileSystemEntryMeta) => {
+ openedEntry.meta = entryMeta;
+ //return updateOpenedFile(openedEntry.path, entryMeta);
})
.catch((error) => {
console.warn('Error saving perspective for folder ' + error);
showNotification(t('Error saving perspective for folder'));
- });
+ });*/
};
let perspectiveDefault;
- if (openedEntry.perspective) {
- perspectiveDefault = openedEntry.perspective; // props.perspective;
+ if (openedEntry.meta && openedEntry.meta.perspective) {
+ perspectiveDefault = openedEntry.meta.perspective; // props.perspective;
} else {
perspectiveDefault = 'unspecified'; // perspectives.DEFAULT;
}
@@ -647,6 +467,11 @@ function EntryProperties(props: Props) {
const showLinkForDownloading = isCloudLocation && openedEntry.isFile;
+ const thumbUrl = getThumbPath(
+ openedEntry.meta?.thumbPath,
+ openedEntry.meta?.lastUpdated,
+ );
+
return (
<Root>
<Grid container>
@@ -1064,7 +889,7 @@ function EntryProperties(props: Props) {
fullWidth
style={{
width: 100,
- background: openedEntry.color,
+ background: openedEntry.meta?.color,
}}
onClick={toggleBackgroundColorPicker}
>
@@ -1091,7 +916,7 @@ function EntryProperties(props: Props) {
</IconButton>
</ProTooltip>
))}
- {openedEntry.color && (
+ {openedEntry.meta && openedEntry.meta.color && (
<>
<ProTooltip tooltip={t('clearFolderColor')}>
<span>
@@ -1157,8 +982,8 @@ function EntryProperties(props: Props) {
style={{
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
- backgroundImage: thumbUrl.current
- ? 'url("' + thumbUrl.current + '")'
+ backgroundImage: thumbUrl
+ ? 'url("' + thumbUrl + '")'
: '',
backgroundPosition: 'center',
borderRadius: 8,
@@ -1215,9 +1040,13 @@ function EntryProperties(props: Props) {
style={{
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
- backgroundImage: bgndUrl.current
- ? 'url("' + bgndUrl.current + '")'
- : '',
+ backgroundImage:
+ 'url("' +
+ getFolderBgndPath(
+ openedEntry.path,
+ openedEntry.meta?.lastUpdated,
+ ) +
+ '")',
backgroundPosition: 'center',
borderRadius: 8,
minHeight: 150,
@@ -1276,9 +1105,10 @@ function EntryProperties(props: Props) {
<ThumbnailChooserDialog
open={isFileThumbChooseDialogOpened}
onClose={toggleThumbFilesDialog}
- selectedFile={openedEntry.path}
+ entry={openedEntry as TS.FileSystemEntry}
+ /*selectedFile={openedEntry.path}
thumbPath={getThumbPath()}
- setThumb={setThumb}
+ setThumb={setThumb}*/
/>
)}
{showSharingLinkDialog && (
@@ -1293,12 +1123,12 @@ function EntryProperties(props: Props) {
<BgndImgChooserDialog
open={isBgndImgChooseDialogOpened}
onClose={toggleBgndImgDialog}
- currentDirectoryPath={openedEntry.path}
+ entry={openedEntry as TS.FileSystemEntry}
/>
)}
{CustomBackgroundDialog && (
<CustomBackgroundDialog
- color={openedEntry.color}
+ color={openedEntry.meta?.color}
open={displayColorPicker}
setColor={handleChangeColor}
onClose={toggleBackgroundColorPicker}
diff --git a/src/renderer/components/FileView.tsx b/src/renderer/components/FileView.tsx
index de20f0b41..6a23a52e2 100644
--- a/src/renderer/components/FileView.tsx
+++ b/src/renderer/components/FileView.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { MutableRefObject } from 'react';
+import React, { MutableRefObject, useEffect, useRef } from 'react';
import { rgbToHex, useTheme } from '@mui/material/styles';
import CloseIcon from '@mui/icons-material/Close';
import useEventListener from '-/utils/useEventListener';
@@ -47,6 +47,11 @@ function FileView(props: Props) {
} = props;
const { searchQuery } = useDirectoryContentContext();
+ const fileOpenerURL = useRef<string>(getFileOpenerURL());
+
+ useEffect(() => {
+ fileOpenerURL.current = getFileOpenerURL();
+ }, [openedEntry]);
useEventListener('toggle-resume', () => {
if (
@@ -61,75 +66,75 @@ function FileView(props: Props) {
}
});
- let fileOpenerURL: string;
-
- if (openedEntry.path) {
- // if (fileTitle.length > maxCharactersTitleLength) {
- // fileTitle = fileTitle.substr(0, maxCharactersTitleLength) + '...';
- // }
-
- const textColor = theme.palette.text.primary;
- const primaryColor = theme.palette.primary.main;
- const bgndColor = theme.palette.background.default;
-
- const extPrimaryColor =
- '&primecolor=' +
- encodeURIComponent(
- primaryColor.startsWith('#') ? primaryColor : rgbToHex(primaryColor),
- );
- const extTextColor =
- '&textcolor=' +
- encodeURIComponent(
- textColor.startsWith('#') ? textColor : rgbToHex(textColor),
- );
- const extBgndColor =
- '&bgndcolor=' +
- encodeURIComponent(
- bgndColor.startsWith('#') ? bgndColor : rgbToHex(bgndColor),
- );
+ function getFileOpenerURL(): string {
+ if (openedEntry && openedEntry.path) {
+ // if (fileTitle.length > maxCharactersTitleLength) {
+ // fileTitle = fileTitle.substr(0, maxCharactersTitleLength) + '...';
+ // }
- const event = eventID ? '&eventID=' + eventID : '';
- const extQuery = searchQuery.textQuery
- ? '&query=' + encodeURIComponent(searchQuery.textQuery)
- : '';
- const locale = '&locale=' + i18n.language;
- const theming =
- '&theme=' +
- theme.palette.mode +
- extPrimaryColor +
- extTextColor +
- extBgndColor;
+ const textColor = theme.palette.text.primary;
+ const primaryColor = theme.palette.primary.main;
+ const bgndColor = theme.palette.background.default;
- if (openedEntry.editMode && openedEntry.editingExtensionPath) {
- fileOpenerURL =
- openedEntry.editingExtensionPath +
- '/index.html?file=' +
+ const extPrimaryColor =
+ '&primecolor=' +
encodeURIComponent(
- openedEntry.url ? openedEntry.url : openedEntry.path,
- ) +
- locale +
- theming +
- extQuery +
- event +
- '&edit=true' +
- (openedEntry.shouldReload === true ? '&t=' + new Date().getTime() : '');
- // } else if (!currentEntry.isFile) { // TODO needed for loading folder's default html
- // fileOpenerURL = 'node_modules/@tagspaces/html-viewer/index.html?locale=' + i18n.language;
- } else {
- fileOpenerURL =
- openedEntry.viewingExtensionPath +
- '/index.html?file=' +
+ primaryColor.startsWith('#') ? primaryColor : rgbToHex(primaryColor),
+ );
+ const extTextColor =
+ '&textcolor=' +
encodeURIComponent(
- openedEntry.url ? openedEntry.url : openedEntry.path,
- ) +
- locale +
- theming +
- extQuery +
- event +
- (openedEntry.shouldReload === true ? '&t=' + new Date().getTime() : '');
+ textColor.startsWith('#') ? textColor : rgbToHex(textColor),
+ );
+ const extBgndColor =
+ '&bgndcolor=' +
+ encodeURIComponent(
+ bgndColor.startsWith('#') ? bgndColor : rgbToHex(bgndColor),
+ );
+
+ const event = eventID ? '&eventID=' + eventID : '';
+ const extQuery = searchQuery.textQuery
+ ? '&query=' + encodeURIComponent(searchQuery.textQuery)
+ : '';
+ const locale = '&locale=' + i18n.language;
+ const theming =
+ '&theme=' +
+ theme.palette.mode +
+ extPrimaryColor +
+ extTextColor +
+ extBgndColor;
+
+ if (openedEntry.editMode && openedEntry.editingExtensionPath) {
+ return (
+ openedEntry.editingExtensionPath +
+ '/index.html?file=' +
+ encodeURIComponent(
+ openedEntry.url ? openedEntry.url : openedEntry.path,
+ ) +
+ locale +
+ theming +
+ extQuery +
+ event +
+ '&edit=true&t=' +
+ openedEntry.lmdt
+ );
+ } else {
+ return (
+ openedEntry.viewingExtensionPath +
+ '/index.html?file=' +
+ encodeURIComponent(
+ openedEntry.url ? openedEntry.url : openedEntry.path,
+ ) +
+ locale +
+ theming +
+ extQuery +
+ event +
+ '&t=' +
+ openedEntry.lmdt
+ );
+ }
}
- } else {
- fileOpenerURL = 'about:blank';
+ return 'about:blank';
}
return (
@@ -170,7 +175,7 @@ function FileView(props: Props) {
zIndex: 3,
border: 0,
}}
- src={fileOpenerURL}
+ src={fileOpenerURL.current}
allowFullScreen
sandbox="allow-same-origin allow-scripts allow-modals allow-downloads"
id={'FileViewer' + eventID}
@@ -180,12 +185,4 @@ function FileView(props: Props) {
);
}
-/*const areEqual = (prevProp, nextProp) =>
- nextProp.openedFile.path === prevProp.openedFile.path &&
- nextProp.openedFile.url === prevProp.openedFile.url &&
- nextProp.openedFile.editMode === prevProp.openedFile.editMode &&
- nextProp.openedFile.shouldReload === prevProp.openedFile.shouldReload &&
- nextProp.isFullscreen === prevProp.isFullscreen &&
- nextProp.height === prevProp.height;*/
-
export default FileView;
diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsx
index 6d92e055f..b0acc8b0e 100644
--- a/src/renderer/components/FolderContainer.tsx
+++ b/src/renderer/components/FolderContainer.tsx
@@ -70,7 +70,7 @@ function FolderContainer(props: Props) {
currentDirectoryEntries,
currentDirectoryPath,
perspective,
- setDirectoryPerspective,
+ setManualDirectoryPerspective,
enterSearchMode,
isSearchMode,
} = useDirectoryContentContext();
@@ -139,7 +139,7 @@ function FolderContainer(props: Props) {
perspectiveId === PerspectiveIDs.GRID ||
perspectiveId === PerspectiveIDs.LIST
) {
- setDirectoryPerspective(perspectiveId, undefined, true);
+ setManualDirectoryPerspective(perspectiveId);
} else if (perspectiveId === PerspectiveIDs.GALLERY) {
toggleProTeaser(PerspectiveIDs.GALLERY);
} else if (perspectiveId === PerspectiveIDs.MAPIQUE) {
diff --git a/src/renderer/components/Revisions.tsx b/src/renderer/components/Revisions.tsx
index ff9f83354..ce43404e6 100644
--- a/src/renderer/components/Revisions.tsx
+++ b/src/renderer/components/Revisions.tsx
@@ -23,7 +23,6 @@ import {
extractFileNameWithoutExt,
} from '@tagspaces/tagspaces-common/paths';
import Tooltip from '-/components/Tooltip';
-import { OpenedEntry } from '-/reducers/app';
import PlatformIO from '-/services/platform-facade';
import { TS } from '-/tagspaces.namespace';
import { format, formatDistanceToNow } from 'date-fns';
@@ -53,10 +52,9 @@ const initialRowsPerPage = 10;
function Revisions() {
const { t } = useTranslation();
- // const dispatch: AppDispatch = useDispatch();
const { switchLocationTypeByID, switchCurrentLocationType } =
useCurrentLocationContext();
- const { openedEntry, updateOpenedFile } = useOpenedEntryContext();
+ const { openedEntry } = useOpenedEntryContext();
const { copyFilePromiseOverwrite } = usePlatformFacadeContext();
const [rows, setRows] = useState<Array<TS.FileSystemEntry>>([]);
const [page, setPage] = useState<number>(0);
@@ -78,7 +76,7 @@ function Revisions() {
return parseInt(extractFileNameWithoutExt(fileName));
}
- function loadHistoryItems(openedFile: OpenedEntry) {
+ function loadHistoryItems(openedFile: TS.OpenedEntry) {
if (Pro) {
Pro.MetaOperations.getMetadataID(openedFile.path, openedFile.uuid).then(
(id) => {
@@ -145,13 +143,13 @@ function Revisions() {
);
return copyFilePromiseOverwrite(openedEntry.path, targetPath).then(() =>
copyFilePromiseOverwrite(revisionPath, openedEntry.path).then(() => {
- const fsMeta = {
+ /*const fsMeta = {
id: '',
...openedEntry,
editMode: false,
shouldReload: !openedEntry.shouldReload,
};
- updateOpenedFile(openedEntry.path, fsMeta);
+ updateOpenedFile(openedEntry.path, fsMeta);*/
}),
);
}
diff --git a/src/renderer/components/dialogs/FilePreviewDialog.tsx b/src/renderer/components/dialogs/FilePreviewDialog.tsx
index c663d8172..fc6b16a63 100644
--- a/src/renderer/components/dialogs/FilePreviewDialog.tsx
+++ b/src/renderer/components/dialogs/FilePreviewDialog.tsx
@@ -24,9 +24,8 @@ import Dialog from '@mui/material/Dialog';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';
import DraggablePaper from '-/components/DraggablePaper';
-import { OpenedEntry } from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
-import { getCurrentTheme, getSupportedFileTypes } from '-/reducers/settings';
+import { getCurrentTheme } from '-/reducers/settings';
import { useSelector } from 'react-redux';
import FileView from '-/components/FileView';
import useEventListener from '-/utils/useEventListener';
@@ -55,7 +54,7 @@ function FilePreviewDialog(props: Props) {
useRef<HTMLDivElement>(null);
const eventID = useRef<string>(getUuid());
- const openedFile: OpenedEntry =
+ const openedFile: TS.OpenedEntry =
fsEntry && openedEntry
? {
...openedEntry,
diff --git a/src/renderer/components/dialogs/FileUploadDialog.tsx b/src/renderer/components/dialogs/FileUploadDialog.tsx
index 6fedcf597..0fcfdd2e1 100644
--- a/src/renderer/components/dialogs/FileUploadDialog.tsx
+++ b/src/renderer/components/dialogs/FileUploadDialog.tsx
@@ -38,7 +38,6 @@ import {
} from '-/reducers/app';
import { extractFileName } from '@tagspaces/tagspaces-common/paths';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
-import { PerspectiveIDs } from '-/perspectives';
import { useTranslation } from 'react-i18next';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
@@ -55,11 +54,7 @@ function FileUploadDialog(props: Props) {
const { t } = useTranslation();
const dispatch: AppDispatch = useDispatch();
- const {
- loadDirectoryContent,
- currentDirectoryPerspective,
- currentDirectoryPath,
- } = useDirectoryContentContext();
+ const { currentDirectoryPath } = useDirectoryContentContext();
const { currentLocation } = useCurrentLocationContext();
const progress = useSelector(getProgress);
diff --git a/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx b/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx
index 2d2024257..a582c84fe 100644
--- a/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/TargetPathContextProvider.tsx
@@ -42,7 +42,7 @@ export const TargetPathContextProvider = ({
}: TargetPathContextProviderProps) => {
const { currentLocation } = useCurrentLocationContext();
const { selectedEntries } = useSelectedEntriesContext();
- const { currentDirectoryPerspective, currentDirectoryPath, getPerspective } =
+ const { perspective, currentDirectoryPath, getPerspective } =
useDirectoryContentContext();
const firstRWLocation = useSelector(getFirstRWLocation);
@@ -70,12 +70,7 @@ export const TargetPathContextProvider = ({
return {
targetDirectoryPath,
};
- }, [
- firstRWLocation,
- selectedEntries,
- currentDirectoryPath,
- currentDirectoryPerspective,
- ]);
+ }, [firstRWLocation, selectedEntries, currentDirectoryPath, perspective]);
return (
<TargetPathContext.Provider value={context}>
diff --git a/src/renderer/components/menus/DirectoryMenu.tsx b/src/renderer/components/menus/DirectoryMenu.tsx
index 1a83d556f..f4535da22 100644
--- a/src/renderer/components/menus/DirectoryMenu.tsx
+++ b/src/renderer/components/menus/DirectoryMenu.tsx
@@ -77,7 +77,7 @@ function DirectoryMenu(props: Props) {
openDirectory,
currentDirectoryPath,
currentDirectoryEntries,
- setDirectoryPerspective,
+ setManualDirectoryPerspective,
openCurrentDirectory,
} = useDirectoryContentContext();
const { generateThumbnails } = useThumbGenerationContext();
@@ -167,7 +167,7 @@ function DirectoryMenu(props: Props) {
if (switchPerspective) {
switchPerspective(perspectiveId);
} else {
- setDirectoryPerspective(perspectiveId, undefined, true);
+ setManualDirectoryPerspective(perspectiveId);
}
} else if (perspectiveId === PerspectiveIDs.GALLERY) {
toggleProTeaser(PerspectiveIDs.GALLERY);
diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsx
index fc7850750..7d3c36b15 100644
--- a/src/renderer/components/menus/FileMenu.tsx
+++ b/src/renderer/components/menus/FileMenu.tsx
@@ -44,11 +44,11 @@ import PlatformIO from '-/services/platform-facade';
import {
setFolderBackgroundPromise,
getRelativeEntryPath,
+ toFsEntry,
} from '-/services/utils-io';
import { getKeyBindingObject } from '-/reducers/settings';
import { Pro } from '-/pro';
-import { actions as AppActions, AppDispatch } from '-/reducers/app';
-import { useSelector, useDispatch } from 'react-redux';
+import { useSelector } from 'react-redux';
import { supportedImgs } from '-/services/thumbsgenerator';
import {
OpenNewWindowIcon,
@@ -65,6 +65,8 @@ import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';
import { useIOActionsContext } from '-/hooks/useIOActionsContext';
import MenuKeyBinding from '-/components/menus/MenuKeyBinding';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
+import PlatformFacade from '-/services/platform-facade';
interface Props {
anchorEl: Element;
@@ -102,8 +104,9 @@ function FileMenu(props: Props) {
const keyBindings = useSelector(getKeyBindingObject);
const { t } = useTranslation();
- const dispatch: AppDispatch = useDispatch();
const { selectedEntries } = useSelectedEntriesContext();
+ const { setBackgroundImageChange, setThumbnailImageChange } =
+ useEditedEntryMetaContext();
const { openEntry } = useOpenedEntryContext();
const { openDirectory, currentLocationPath } = useDirectoryContentContext();
const { showNotification } = useNotificationContext();
@@ -162,15 +165,25 @@ function FileMenu(props: Props) {
function setFolderThumbnail() {
onClose();
- setFolderThumbnailPromise(selectedFilePath)
- .then((directoryPath: string) => {
- showNotification('Thumbnail created for: ' + directoryPath);
+ setFolderThumbnailPromise(selectedEntries[0].path) //selectedFilePath)
+ .then((thumbPath: string) => {
+ setThumbnailImageChange(
+ toFsEntry(
+ extractContainingDirectoryPath(
+ selectedEntries[0].path,
+ PlatformFacade.getDirSeparator(),
+ ),
+ false,
+ ),
+ thumbPath,
+ );
+ showNotification('Thumbnail created: ' + thumbPath);
return true;
})
.catch((error) => {
showNotification('Thumbnail creation failed.');
console.warn(
- 'Error setting Thumb for entry: ' + selectedFilePath,
+ 'Error setting Thumb for entry: ' + selectedEntries[0].path,
error,
);
return true;
@@ -191,9 +204,10 @@ function FileMenu(props: Props) {
setFolderBackgroundPromise(path, directoryPath)
.then((directoryPath: string) => {
- dispatch(
+ setBackgroundImageChange(toFsEntry(directoryPath, false));
+ /*dispatch(
AppActions.setLastBackgroundImageChange(path, new Date().getTime()),
- );
+ );*/
showNotification('Background created for: ' + directoryPath);
return true;
})
diff --git a/src/renderer/containers/Root.tsx b/src/renderer/containers/Root.tsx
index a804909bf..be494f28c 100644
--- a/src/renderer/containers/Root.tsx
+++ b/src/renderer/containers/Root.tsx
@@ -39,6 +39,7 @@ import { PlatformFacadeContextProvider } from '-/hooks/PlatformFacadeContextProv
import { EditedEntryContextProvider } from '-/hooks/EditedEntryContextProvider';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { DndProvider } from 'react-dnd';
+import { EditedEntryMetaContextProvider } from '-/hooks/EditedEntryMetaContextProvider';
type RootType = {
store: Store<{}>;
@@ -63,25 +64,27 @@ export default function Root({ store, persistor }: RootType) {
<NotificationContextProvider>
<CurrentLocationContextProvider>
<EditedEntryContextProvider>
- <SelectedEntryContextProvider>
- <DirectoryContentContextProvider>
- <FSWatcherContextProvider>
- <PlatformFacadeContextProvider>
- <LocationIndexContextProvider>
- <OpenedEntryContextProvider>
- <IOActionsContextProvider>
- <TaggingActionsContextProvider>
- <DndProvider backend={HTML5Backend}>
- <MainPage />
- </DndProvider>
- </TaggingActionsContextProvider>
- </IOActionsContextProvider>
- </OpenedEntryContextProvider>
- </LocationIndexContextProvider>
- </PlatformFacadeContextProvider>
- </FSWatcherContextProvider>
- </DirectoryContentContextProvider>
- </SelectedEntryContextProvider>
+ <EditedEntryMetaContextProvider>
+ <SelectedEntryContextProvider>
+ <DirectoryContentContextProvider>
+ <FSWatcherContextProvider>
+ <PlatformFacadeContextProvider>
+ <LocationIndexContextProvider>
+ <OpenedEntryContextProvider>
+ <IOActionsContextProvider>
+ <TaggingActionsContextProvider>
+ <DndProvider backend={HTML5Backend}>
+ <MainPage />
+ </DndProvider>
+ </TaggingActionsContextProvider>
+ </IOActionsContextProvider>
+ </OpenedEntryContextProvider>
+ </LocationIndexContextProvider>
+ </PlatformFacadeContextProvider>
+ </FSWatcherContextProvider>
+ </DirectoryContentContextProvider>
+ </SelectedEntryContextProvider>
+ </EditedEntryMetaContextProvider>
</EditedEntryContextProvider>
</CurrentLocationContextProvider>
</NotificationContextProvider>
diff --git a/src/renderer/hooks/DescriptionContextProvider.tsx b/src/renderer/hooks/DescriptionContextProvider.tsx
index 3c2dfb724..a8e0cc7a0 100644
--- a/src/renderer/hooks/DescriptionContextProvider.tsx
+++ b/src/renderer/hooks/DescriptionContextProvider.tsx
@@ -20,22 +20,17 @@ import React, {
createContext,
useEffect,
useMemo,
+ useReducer,
useRef,
useState,
} from 'react';
-import { useDispatch, useSelector } from 'react-redux';
-import {
- actions as AppActions,
- AppDispatch,
- OpenedEntry,
-} from '-/reducers/app';
import { Pro } from '-/pro';
import { useTranslation } from 'react-i18next';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useNotificationContext } from '-/hooks/useNotificationContext';
-import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
-import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
+import { TS } from '-/tagspaces.namespace';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
type DescriptionContextData = {
description: string;
@@ -50,7 +45,7 @@ export const DescriptionContext = createContext<DescriptionContextData>({
isSaveDescriptionConfirmOpened: false,
setSaveDescriptionConfirmOpened: () => {},
setDescription: () => {},
- saveDescription: () => {},
+ saveDescription: undefined,
});
export type DescriptionContextProviderProps = {
@@ -61,39 +56,36 @@ export const DescriptionContextProvider = ({
children,
}: DescriptionContextProviderProps) => {
const { t } = useTranslation();
- const { setSelectedEntries } = useSelectedEntriesContext();
- const {
- openedEntry,
- addToEntryContainer,
- updateOpenedFile,
- reloadOpenedFile,
- } = useOpenedEntryContext();
- const { switchLocationTypeByID, switchCurrentLocationType, readOnlyMode } =
- useCurrentLocationContext();
- const { updateCurrentDirEntry } = useDirectoryContentContext();
+ const { openedEntry } = useOpenedEntryContext();
+ const { readOnlyMode } = useCurrentLocationContext();
const { showNotification } = useNotificationContext();
- const openedFile = useRef<OpenedEntry>(openedEntry);
+ const { setDescriptionChange } = useEditedEntryMetaContext();
+ //const description = useRef<string>(openedEntry.meta?.description);
+ const lastOpenedFile = useRef<TS.OpenedEntry>(openedEntry);
const isChanged = useRef<boolean>(false);
const [isSaveDescriptionConfirmOpened, saveDescriptionConfirmOpened] =
useState<boolean>(false);
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
useEffect(() => {
if (openedEntry) {
if (
- openedFile.current !== undefined &&
isChanged.current &&
- openedFile.current.path !== openedEntry.path &&
- openedFile.current.description !== openedEntry.description
+ lastOpenedFile.current !== undefined &&
+ lastOpenedFile.current.path !== openedEntry.path
+ //lastOpenedFile.current.meta &&
+ //openedEntry.meta &&
+ //lastOpenedFile.current.meta.description !== openedEntry.meta.description
) {
// handle not saved changes
- addToEntryContainer({ ...openedFile.current, editMode: false });
- setSelectedEntries([]);
saveDescriptionConfirmOpened(true);
} else {
- openedFile.current = openedEntry;
+ lastOpenedFile.current = { ...openedEntry };
+ //description.current = openedEntry.meta?.description;
}
} else {
- openedFile.current = undefined;
+ lastOpenedFile.current = undefined;
+ //description.current = undefined;
}
}, [openedEntry]);
@@ -109,69 +101,46 @@ export const DescriptionContextProvider = ({
showNotification(t('Saving description not supported'));
return;
}
- if (openedFile.current.description !== undefined) {
- //forceUpdate();
- //setDescriptionChanged(false);
- if (openedFile.current.locationId) {
- switchLocationTypeByID(openedFile.current.locationId).then(
- (currentLocationId) => {
- saveMetaData()
- .then(() => switchCurrentLocationType())
- .catch((error) => {
- console.warn('Error saving description ' + error);
- switchCurrentLocationType().then(() =>
- showNotification(t('Error saving description')),
- );
- });
- },
- );
- } else {
- console.debug(
- 'openedFile:' +
- openedFile.current.path +
- ' dont have locationId! Current Location can be changed. Trying to save opened file in current location',
- );
- saveMetaData();
- }
+ if (lastOpenedFile.current !== undefined) {
+ // to reload description
+ lastOpenedFile.current = { ...lastOpenedFile.current };
+ isChanged.current = false;
+ forceUpdate();
+ setDescriptionChange(
+ lastOpenedFile.current,
+ lastOpenedFile.current.meta?.description,
+ lastOpenedFile.current.locationId,
+ ).then(() => {
+ if (lastOpenedFile.current.path !== openedEntry.path) {
+ lastOpenedFile.current = { ...openedEntry };
+ }
+ // description.current = openedEntry.meta?.description;
+ });
}
};
- function saveMetaData() {
- return Pro.MetaOperations.saveFsEntryMeta(openedFile.current.path, {
- description: openedFile.current.description,
- }).then((entryMeta) => {
- // @ts-ignore
- updateCurrentDirEntry(openedFile.current.path, {
- description: entryMeta.description,
- });
- openedFile.current.description = undefined;
- isChanged.current = false;
- return updateOpenedFile(openedFile.current.path, entryMeta);
- });
- }
-
function setDescription(d: string) {
- openedFile.current.description = d;
+ lastOpenedFile.current.meta.description = d;
isChanged.current = true;
}
function setSaveDescriptionConfirmOpened(isOpened: boolean) {
if (!isOpened) {
isChanged.current = false;
- reloadOpenedFile();
+ // reloadOpenedFile();
}
saveDescriptionConfirmOpened(isOpened);
}
const context = useMemo(() => {
return {
- description: openedFile.current?.description,
+ description: lastOpenedFile.current?.meta?.description,
isSaveDescriptionConfirmOpened,
setSaveDescriptionConfirmOpened,
setDescription,
saveDescription,
};
- }, [openedFile.current, isSaveDescriptionConfirmOpened]);
+ }, [lastOpenedFile.current, isSaveDescriptionConfirmOpened]);
return (
<DescriptionContext.Provider value={context}>
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 7c9c547fc..d202869e7 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -39,6 +39,8 @@ import {
} from '@tagspaces/tagspaces-common/paths';
import PlatformIO from '-/services/platform-facade';
import {
+ getAllPropertiesPromise,
+ getFolderBgndPath,
loadJSONFile,
merge,
toFsEntry,
@@ -63,15 +65,15 @@ import { defaultTitle } from '-/services/search';
import { Pro } from '-/pro';
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';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
type DirectoryContentContextData = {
currentLocationPath: string;
currentDirectoryEntries: TS.FileSystemEntry[];
directoryMeta: TS.FileSystemEntryMeta;
- currentDirectoryPerspective: TS.PerspectiveType;
+ //currentDirectoryPerspective: TS.PerspectiveType;
currentDirectoryPath: string;
/**
* used for reorder files in KanBan
@@ -110,18 +112,13 @@ type DirectoryContentContextData = {
openCurrentDirectory: (showHiddenEntries?: boolean) => Promise<boolean>;
clearDirectoryContent: () => void;
perspective: TS.PerspectiveType;
- setDirectoryPerspective: (
- perspective: string,
- dir?: string,
- isManual?: boolean,
- reload?: boolean,
- ) => Promise<TS.FileSystemEntryMeta | null>;
+ setManualDirectoryPerspective: (perspective: string, dir?: string) => void;
setCurrentDirectoryColor: (color: string) => void;
setCurrentDirectoryDirs: (dirs: TS.OrderVisibilitySettings[]) => void;
setCurrentDirectoryFiles: (files: TS.OrderVisibilitySettings[]) => void;
updateCurrentDirEntry: (path: string, entry: TS.FileSystemEntry) => void;
updateCurrentDirEntries: (dirEntries: TS.FileSystemEntry[]) => void;
- updateThumbnailUrl: (filePath: string, thumbUrl: string) => void;
+ //updateThumbnailUrl: (filePath: string, thumbUrl: string) => void;
setDirectoryMeta: (meta: TS.FileSystemEntryMeta) => void;
setSearchResults: (entries: TS.FileSystemEntry[]) => void;
appendSearchResults: (entries: TS.FileSystemEntry[]) => void;
@@ -142,7 +139,7 @@ export const DirectoryContentContext =
currentLocationPath: undefined,
currentDirectoryEntries: [],
directoryMeta: undefined,
- currentDirectoryPerspective: undefined,
+ //currentDirectoryPerspective: undefined,
currentDirectoryPath: undefined,
currentDirectoryFiles: [],
currentDirectoryDirs: [],
@@ -161,13 +158,13 @@ export const DirectoryContentContext =
openCurrentDirectory: undefined,
clearDirectoryContent: () => {},
perspective: undefined,
- setDirectoryPerspective: undefined,
+ setManualDirectoryPerspective: undefined,
setCurrentDirectoryColor: () => {},
setCurrentDirectoryDirs: () => {},
setCurrentDirectoryFiles: () => {},
updateCurrentDirEntry: () => {},
updateCurrentDirEntries: () => {},
- updateThumbnailUrl: () => {},
+ //updateThumbnailUrl: () => {},
setDirectoryMeta: () => {},
setSearchResults: () => {},
appendSearchResults: () => {},
@@ -195,6 +192,7 @@ export const DirectoryContentContextProvider = ({
getLocationPath,
} = useCurrentLocationContext();
const { actions } = useEditedEntryContext();
+ const { metaActions, setReflectMetaActions } = useEditedEntryMetaContext();
const { showNotification, hideNotifications } = useNotificationContext();
const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();
@@ -215,7 +213,7 @@ export const DirectoryContentContextProvider = ({
const currentDirectoryEntries = useRef<TS.FileSystemEntry[]>([]);
const searchQuery = useRef<TS.SearchQuery>({});
const isSearchMode = useRef<boolean>(false);
- const currentPerspective = useRef<TS.PerspectiveType>('unspecified');
+ //const currentPerspective = useRef<TS.PerspectiveType>('unspecified');
const manualPerspective = useRef<TS.PerspectiveType>('unspecified');
const directoryMeta = useRef<TS.FileSystemEntryMeta>(getDefaultDirMeta());
/**
@@ -248,6 +246,31 @@ export const DirectoryContentContextProvider = ({
}
}, [currentLocation]);
+ useEffect(() => {
+ if (metaActions && metaActions.length > 0) {
+ for (const action of metaActions) {
+ if (currentDirectoryPath.current === action.entry.path) {
+ if (action.action === 'perspectiveChange') {
+ manualPerspective.current =
+ action.entry.meta.perspective === PerspectiveIDs.UNSPECIFIED
+ ? defaultPerspective
+ : action.entry.meta.perspective;
+ forceUpdate();
+ //setManualDirectoryPerspective(action.entry.meta.perspective);
+ } else if (
+ action.action === 'bgdColorChange' ||
+ action.action === 'thumbChange' ||
+ action.action === 'bgdImgChange' ||
+ action.action === 'descriptionChange'
+ ) {
+ directoryMeta.current = { ...action.entry.meta };
+ forceUpdate();
+ }
+ }
+ }
+ }
+ }, [metaActions]);
+
useEffect(() => {
reflectActions(actions).catch(console.error);
}, [actions]);
@@ -368,9 +391,9 @@ export const DirectoryContentContextProvider = ({
}
function getDefaultDirMeta(): TS.FileSystemEntryMeta {
- const perspective = getPerspective();
+ // const perspective = getPerspective();
const settings: TS.PerspectiveSettings = {
- [getPerspective()]: getDefaultPerspectiveSettings(perspective),
+ [defaultPerspective]: getDefaultPerspectiveSettings(defaultPerspective),
};
return {
id: getUuid(),
@@ -473,7 +496,7 @@ export const DirectoryContentContextProvider = ({
);
}
- const getMergedEntries = (entries1, entries2) => {
+ /*const getMergedEntries = (entries1, entries2) => {
if (entries1 && entries1.length > 0) {
return entries1.map((currentEntry) => {
const updatedEntries = entries2.filter(
@@ -490,7 +513,7 @@ export const DirectoryContentContextProvider = ({
});
}
return entries2;
- };
+ };*/
function updateCurrentDirEntries(
dirEntries: TS.FileSystemEntry[],
@@ -508,7 +531,17 @@ export const DirectoryContentContextProvider = ({
currentDirectoryEntries.current.length > 0
) {
setCurrentDirectoryEntries(
- getMergedEntries(currentDirectoryEntries.current, entries),
+ currentDirectoryEntries.current.map((e) => {
+ const eUpdated = entries.filter((u) => u.path === e.path);
+ if (eUpdated.length > 0) {
+ const mergedMeta = eUpdated.reduce((merged, obj) => {
+ return { ...merged, ...obj.meta };
+ }, {});
+ return { ...e, meta: { ...e.meta, ...mergedMeta } };
+ }
+ return e;
+ }),
+ //getMergedEntries(currentDirectoryEntries.current, entries),
);
} else {
setCurrentDirectoryEntries(entries);
@@ -517,7 +550,7 @@ export const DirectoryContentContextProvider = ({
}
}
- function updateThumbnailUrl(filePath: string, thumbUrl: string) {
+ /*function updateThumbnailUrl(filePath: string, thumbUrl: string) {
const dirEntries = currentDirectoryEntries.current.map((entry) => {
if (entry.path === filePath) {
return { ...entry, thumbPath: thumbUrl };
@@ -525,7 +558,7 @@ export const DirectoryContentContextProvider = ({
return entry;
});
setCurrentDirectoryEntries(dirEntries);
- }
+ }*/
function loadDirectoryContent(
directoryPath: string,
@@ -653,12 +686,12 @@ export const DirectoryContentContextProvider = ({
hideNotifications(['error']);
if (directoryMeta.current) {
- if (directoryMeta.current.perspective) {
+ /*if (directoryMeta.current.perspective) {
currentPerspective.current = directoryMeta.current
.perspective as TS.PerspectiveType;
} else {
currentPerspective.current = 'unspecified';
- }
+ }*/
if (directoryMeta.current.customOrder) {
if (directoryMeta.current.customOrder.files) {
currentDirectoryFiles.current =
@@ -669,9 +702,9 @@ export const DirectoryContentContextProvider = ({
directoryMeta.current.customOrder.folders;
}
}
- } else {
+ } /*else {
currentPerspective.current = 'unspecified';
- }
+ }*/
const directoryContent = enhanceDirectoryContent(
dirEntries,
currentLocation && currentLocation.type === locationType.TYPE_CLOUD,
@@ -751,26 +784,47 @@ export const DirectoryContentContextProvider = ({
const perspective = useMemo(
() => getPerspective(),
- [currentPerspective.current, manualPerspective.current],
+ [directoryMeta.current?.perspective, manualPerspective.current],
);
function getPerspective(): TS.PerspectiveType {
if (manualPerspective.current === 'unspecified') {
- if (currentPerspective.current === 'unspecified') {
+ if (
+ !directoryMeta.current ||
+ directoryMeta.current.perspective === 'unspecified'
+ ) {
return defaultPerspective;
}
- return currentPerspective.current;
+ return directoryMeta.current.perspective;
}
return manualPerspective.current;
}
- function setDirectoryPerspective(
+ function setManualDirectoryPerspective(
perspective: TS.PerspectiveType,
directory: string = undefined,
- isManual: boolean = false,
- reload: boolean = true,
- ): Promise<TS.FileSystemEntryMeta | null> {
- return new Promise((resolve) => {
+ ) {
+ manualPerspective.current = perspective;
+ getAllPropertiesPromise(
+ directory ? directory : currentDirectoryPath.current,
+ )
+ .then((entry: TS.FileSystemEntry) => {
+ const action: TS.EditMetaAction = {
+ action: 'perspectiveChange',
+ entry: {
+ ...entry,
+ meta: { ...(entry.meta && { ...entry.meta }), perspective },
+ },
+ };
+ setReflectMetaActions(action);
+ })
+ .catch((error) => {
+ console.warn(
+ 'Error getting properties for entry: ' + directory + ' - ' + error,
+ );
+ });
+
+ /*return new Promise((resolve) => {
if (isManual) {
//&& currentPerspective.current === 'unspecified') {
manualPerspective.current = perspective;
@@ -792,7 +846,7 @@ export const DirectoryContentContextProvider = ({
if (reload) {
forceUpdate();
}
- });
+ });*/
}
function setCurrentDirectoryDirs(dirs: TS.OrderVisibilitySettings[]) {
@@ -917,7 +971,7 @@ export const DirectoryContentContextProvider = ({
currentLocationPath: currentLocationPath.current,
currentDirectoryEntries: currentDirectoryEntries.current,
directoryMeta: directoryMeta.current,
- currentDirectoryPerspective: currentPerspective.current,
+ //currentDirectoryPerspective: currentPerspective.current,
currentDirectoryPath: currentDirectoryPath.current,
currentDirectoryFiles: currentDirectoryFiles.current,
currentDirectoryDirs: currentDirectoryDirs.current,
@@ -934,7 +988,7 @@ export const DirectoryContentContextProvider = ({
openDirectory,
openCurrentDirectory,
clearDirectoryContent,
- setDirectoryPerspective,
+ setManualDirectoryPerspective,
perspective,
setCurrentDirectoryColor,
setCurrentDirectoryDirs,
@@ -943,7 +997,7 @@ export const DirectoryContentContextProvider = ({
//removeDirectoryEntries,
//reflectRenameEntries,
updateCurrentDirEntries,
- updateThumbnailUrl,
+ //updateThumbnailUrl,
setDirectoryMeta,
setSearchResults,
appendSearchResults,
@@ -959,7 +1013,7 @@ export const DirectoryContentContextProvider = ({
currentDirectoryEntries.current,
currentDirectoryPath.current,
directoryMeta.current,
- currentPerspective.current,
+ //currentPerspective.current,
perspective,
currentDirectoryFiles.current,
currentDirectoryDirs.current,
diff --git a/src/renderer/hooks/EditedEntryMetaContextProvider.tsx b/src/renderer/hooks/EditedEntryMetaContextProvider.tsx
new file mode 100644
index 000000000..8dd546677
--- /dev/null
+++ b/src/renderer/hooks/EditedEntryMetaContextProvider.tsx
@@ -0,0 +1,243 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2023-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import React, { createContext, useMemo, useReducer, useRef } from 'react';
+import { TS } from '-/tagspaces.namespace';
+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
+import { saveFsEntryMeta } from '-/utils/metaoperations';
+
+type EditedEntryMetaContextData = {
+ metaActions: TS.EditMetaAction[];
+ setReflectMetaActions: (...actionsArray: TS.EditMetaAction[]) => void;
+ setAutoSave: (
+ entry: TS.FileSystemEntry,
+ autoSave: boolean,
+ locationId?,
+ ) => Promise<boolean>;
+ setDescriptionChange: (
+ entry: TS.FileSystemEntry,
+ description: string,
+ locationId?,
+ ) => Promise<boolean>;
+ saveDirectoryPerspective: (
+ entry: TS.FileSystemEntry,
+ perspective: TS.PerspectiveType,
+ locationId?,
+ ) => Promise<boolean>;
+ setBackgroundImageChange: (entry: TS.FileSystemEntry) => void;
+ setBackgroundColorChange: (
+ entry: TS.FileSystemEntry,
+ color: string,
+ locationId?,
+ ) => Promise<boolean>;
+ setThumbnailImageChange: (
+ entry: TS.FileSystemEntry,
+ thumbPath: string,
+ locationId?,
+ ) => Promise<boolean>;
+};
+
+export const EditedEntryMetaContext = createContext<EditedEntryMetaContextData>(
+ {
+ metaActions: undefined,
+ setReflectMetaActions: undefined,
+ setAutoSave: undefined,
+ setDescriptionChange: undefined,
+ saveDirectoryPerspective: undefined,
+ setBackgroundImageChange: undefined,
+ setBackgroundColorChange: undefined,
+ setThumbnailImageChange: undefined,
+ },
+);
+
+export type EditedEntryMetaContextProviderProps = {
+ children: React.ReactNode;
+};
+
+export const EditedEntryMetaContextProvider = ({
+ children,
+}: EditedEntryMetaContextProviderProps) => {
+ const { switchLocationTypeByID, switchCurrentLocationType } =
+ useCurrentLocationContext();
+ const metaActions = useRef<TS.EditMetaAction[]>(undefined);
+
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
+
+ function setReflectMetaActions(...actionsArray: TS.EditMetaAction[]) {
+ metaActions.current = actionsArray;
+ forceUpdate();
+ }
+
+ function setAutoSave(
+ entry: TS.FileSystemEntry,
+ autoSave: boolean,
+ locationId = undefined,
+ ) {
+ return saveMetaData(entry.path, { autoSave }, locationId).then((meta) => {
+ if (meta) {
+ const action: TS.EditMetaAction = {
+ action: 'autoSaveChange',
+ entry: {
+ ...entry,
+ meta: meta,
+ },
+ };
+ setReflectMetaActions(action);
+ return true;
+ }
+ return false;
+ });
+ }
+
+ function saveDirectoryPerspective(
+ entry: TS.FileSystemEntry,
+ perspective: TS.PerspectiveType,
+ locationId = undefined,
+ ): Promise<boolean> {
+ return saveMetaData(entry.path, { perspective }, locationId).then(
+ (meta) => {
+ if (meta) {
+ const action: TS.EditMetaAction = {
+ action: 'perspectiveChange',
+ entry: {
+ ...entry,
+ meta: meta,
+ },
+ };
+ setReflectMetaActions(action);
+ return true;
+ }
+ return false;
+ },
+ );
+ }
+
+ function setDescriptionChange(
+ entry: TS.FileSystemEntry,
+ description: string,
+ locationId = undefined,
+ ): Promise<boolean> {
+ return saveMetaData(entry.path, { description }, locationId).then(
+ (meta) => {
+ if (meta) {
+ const action: TS.EditMetaAction = {
+ action: 'descriptionChange',
+ entry: {
+ ...entry,
+ meta: meta,
+ },
+ };
+ setReflectMetaActions(action);
+ return true;
+ }
+ return false;
+ },
+ );
+ }
+
+ function setBackgroundImageChange(entry: TS.FileSystemEntry) {
+ const action: TS.EditMetaAction = {
+ action: 'bgdImgChange',
+ entry: {
+ ...entry,
+ meta: { ...entry.meta, lastUpdated: new Date().getTime() },
+ },
+ };
+ setReflectMetaActions(action);
+ }
+
+ function setBackgroundColorChange(
+ entry: TS.FileSystemEntry,
+ color: string,
+ locationId = undefined,
+ ): Promise<boolean> {
+ return saveMetaData(entry.path, { color }, locationId).then((meta) => {
+ if (meta) {
+ const action: TS.EditMetaAction = {
+ action: 'bgdColorChange',
+ entry: {
+ ...entry,
+ meta: meta,
+ },
+ };
+ setReflectMetaActions(action);
+ return true;
+ }
+ return false;
+ });
+ }
+
+ function setThumbnailImageChange(
+ entry: TS.FileSystemEntry,
+ thumbPath: string,
+ locationId = undefined,
+ ): Promise<boolean> {
+ return saveMetaData(entry.path, { thumbPath }, locationId).then((meta) => {
+ if (meta) {
+ const action: TS.EditMetaAction = {
+ action: 'thumbChange',
+ entry: {
+ ...entry,
+ meta: meta,
+ },
+ };
+ setReflectMetaActions(action);
+ return true;
+ }
+ return false;
+ });
+ }
+
+ function saveMetaData(
+ path: string,
+ meta: any,
+ locationId = undefined,
+ ): Promise<TS.FileSystemEntryMeta> {
+ return switchLocationTypeByID(locationId).then((currentLocationId) =>
+ saveFsEntryMeta(path, meta)
+ .then((entryMeta) => entryMeta)
+ .catch((error) => {
+ if (currentLocationId) {
+ switchCurrentLocationType();
+ }
+ console.warn('Error saving color for folder ' + error);
+ // showNotification(t('Error saving color for folder'));
+ return undefined;
+ }),
+ );
+ }
+
+ const context = useMemo(() => {
+ return {
+ metaActions: metaActions.current,
+ setReflectMetaActions,
+ setAutoSave,
+ setDescriptionChange,
+ saveDirectoryPerspective,
+ setBackgroundImageChange,
+ setBackgroundColorChange,
+ setThumbnailImageChange,
+ };
+ }, [metaActions.current]);
+
+ return (
+ <EditedEntryMetaContext.Provider value={context}>
+ {children}
+ </EditedEntryMetaContext.Provider>
+ );
+};
diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsx
index 389870be1..7bca23429 100644
--- a/src/renderer/hooks/FSWatcherContextProvider.tsx
+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx
@@ -63,7 +63,7 @@ export const FSWatcherContextProvider = ({
currentDirectoryEntries,
loadDirectoryContent,
currentDirectoryPath,
- currentDirectoryPerspective,
+ perspective,
} = useDirectoryContentContext();
const { reflectDeleteEntries, reflectAddEntry, reflectUpdateMeta } =
useEditedEntryContext();
@@ -77,8 +77,7 @@ export const FSWatcherContextProvider = ({
currentLocation.type !== locationType.TYPE_CLOUD
) {
if (currentDirectoryPath && currentDirectoryPath.length > 0) {
- const depth =
- currentDirectoryPerspective === PerspectiveIDs.KANBAN ? 3 : 1;
+ const depth = perspective === PerspectiveIDs.KANBAN ? 3 : 1;
watchFolder(currentDirectoryPath, depth);
}
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index 4e415d5f7..77832ba72 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -731,7 +731,7 @@ export const IOActionsContextProvider = ({
console.log('error generateThumbnail:', err);
});
if (thumbPath) {
- fsEntry.thumbPath = PlatformIO.getURLforPath(thumbPath);
+ fsEntry.meta.thumbPath = PlatformIO.getURLforPath(thumbPath);
}
fsEntries.push(fsEntry);
showNotification(
@@ -800,7 +800,7 @@ export const IOActionsContextProvider = ({
}
} else if (fileType === 'thumb') {
// eslint-disable-next-line no-param-reassign
- fsEntry.thumbPath = fsEntry.path;
+ fsEntry.meta.thumbPath = fsEntry.path;
}
return fsEntry;
@@ -972,8 +972,8 @@ export const IOActionsContextProvider = ({
thumbFilePath.replace(/[/\\]/g, '')
) {
// eslint-disable-next-line no-param-reassign
- file.thumbPath = PlatformIO.getURLforPath(
- thumbFile.thumbPath,
+ file.meta.thumbPath = PlatformIO.getURLforPath(
+ thumbFile.meta.thumbPath,
);
}
}
diff --git a/src/renderer/hooks/LocationIndexContextProvider.tsx b/src/renderer/hooks/LocationIndexContextProvider.tsx
index d7b635810..01e33770c 100644
--- a/src/renderer/hooks/LocationIndexContextProvider.tsx
+++ b/src/renderer/hooks/LocationIndexContextProvider.tsx
@@ -356,15 +356,16 @@ export const LocationIndexContextProvider = ({
if (isCloudLocation) {
searchResults.forEach((entry: TS.FileSystemEntry) => {
if (
- entry.thumbPath &&
- entry.thumbPath.length > 1
+ entry.meta &&
+ entry.meta.thumbPath &&
+ entry.meta.thumbPath.length > 1
// !entry.thumbPath.startsWith('http')
) {
const thumbPath = entry.path.startsWith('/')
? entry.path.substring(1)
: entry.path;
// eslint-disable-next-line no-param-reassign
- entry.thumbPath = PlatformIO.getURLforPath(
+ entry.meta.thumbPath = PlatformIO.getURLforPath(
getThumbFileLocationForFile(
thumbPath,
PlatformIO.getDirSeparator(),
@@ -474,11 +475,14 @@ export const LocationIndexContextProvider = ({
const url = PlatformIO.getURLforPath(cleanedPath);
let thumbPath;
if (
- entry.thumbPath &&
- entry.thumbPath.length > 1 &&
- !entry.thumbPath.startsWith('http')
+ entry.meta &&
+ entry.meta.thumbPath &&
+ entry.meta.thumbPath.length > 1 &&
+ !entry.meta.thumbPath.startsWith('http')
) {
- thumbPath = PlatformIO.getURLforPath(entry.thumbPath);
+ thumbPath = PlatformIO.getURLforPath(
+ entry.meta.thumbPath,
+ );
}
return { ...entry, url, thumbPath };
});
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index ad9887d0f..a3c86559b 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -24,7 +24,7 @@ import React, {
useRef,
} from 'react';
import { useDispatch, useSelector } from 'react-redux';
-import { AppDispatch, OpenedEntry } from '-/reducers/app';
+import { AppDispatch } from '-/reducers/app';
import { Pro } from '-/pro';
import { TS } from '-/tagspaces.namespace';
import PlatformIO from '-/services/platform-facade';
@@ -32,7 +32,6 @@ import {
findExtensionsForEntry,
getAllPropertiesPromise,
getRelativeEntryPath,
- loadJSONFile,
openURLExternally,
} from '-/services/utils-io';
import {
@@ -65,23 +64,24 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';
import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
type OpenedEntryContextData = {
- openedEntry: OpenedEntry;
+ openedEntry: TS.OpenedEntry;
isEntryInFullWidth: boolean;
sharingLink: string;
sharingParentFolderLink: string;
setEntryInFullWidth: (fullWidth: boolean) => void;
- addToEntryContainer: (fsEntry: OpenedEntry) => void;
+ addToEntryContainer: (fsEntry: TS.OpenedEntry) => void;
closeAllFiles: () => void;
reflectUpdateOpenedFileContent: (entry: TS.FileSystemEntry) => void;
reloadOpenedFile: () => void;
- updateOpenedFile: (
+ /*updateOpenedFile: (
entryPath: string,
fsEntryMeta: TS.FileSystemEntryMeta,
- ) => Promise<boolean>;
- openEntry: (path?: string, showDetails?) => void;
- openFsEntry: (fsEntry?: TS.FileSystemEntry, showDetails?) => void;
+ ) => Promise<boolean>;*/
+ openEntry: (path?: string, showDetails?) => Promise<boolean>;
+ openFsEntry: (fsEntry?: TS.FileSystemEntry, showDetails?) => Promise<boolean>;
toggleEntryFullWidth: () => void;
openLink: (url: string, options?) => void;
goForward: () => void;
@@ -106,9 +106,9 @@ export const OpenedEntryContext = createContext<OpenedEntryContextData>({
closeAllFiles: () => {},
reflectUpdateOpenedFileContent: () => {},
reloadOpenedFile: () => {},
- updateOpenedFile: () => Promise.resolve(false),
- openEntry: () => {},
- openFsEntry: () => {},
+ //updateOpenedFile: () => Promise.resolve(false),
+ openEntry: undefined,
+ openFsEntry: undefined,
toggleEntryFullWidth: () => {},
openLink: () => {},
goForward: () => {},
@@ -130,16 +130,13 @@ export const OpenedEntryContextProvider = ({
const { openLocation, currentLocation, getLocationPath } =
useCurrentLocationContext();
- const {
- currentDirectoryPath,
- currentDirectoryPerspective,
- currentLocationPath,
- openDirectory,
- } = useDirectoryContentContext();
+ const { currentDirectoryPath, currentLocationPath, openDirectory } =
+ useDirectoryContentContext();
const { selectedEntries } = useSelectedEntriesContext();
const { showNotification } = useNotificationContext();
const { actions } = useEditedEntryContext();
+ const { metaActions } = useEditedEntryMetaContext();
const { saveFilePromise } = usePlatformFacadeContext();
const supportedFileTypes = useSelector(getSupportedFileTypes);
@@ -152,7 +149,7 @@ export const OpenedEntryContextProvider = ({
(state: any) => state.settings[historyKeys.folderOpenKey],
);
const newHTMLFileContent = useSelector(getNewHTMLFileContent);
- const currentEntry = useRef<OpenedEntry>(undefined);
+ const currentEntry = useRef<TS.OpenedEntry>(undefined);
/* const dirProps = useRef<TS.DirProp>({
totalSize: undefined,
filesCount: undefined,
@@ -213,6 +210,45 @@ export const OpenedEntryContextProvider = ({
}, [actions]);
useEffect(() => {
+ if (metaActions && metaActions.length > 0) {
+ let isChanged = false;
+ for (const action of metaActions) {
+ if (
+ currentEntry.current &&
+ currentEntry.current.path === action.entry.path
+ ) {
+ if (action.action === 'thumbChange') {
+ if (action.entry.meta.thumbPath) {
+ currentEntry.current = {
+ ...currentEntry.current,
+ meta: { ...currentEntry.current.meta, ...action.entry.meta },
+ };
+ } else {
+ const { thumbPath, ...meta } = currentEntry.current.meta;
+ currentEntry.current = { ...currentEntry.current, meta };
+ }
+ isChanged = true;
+ } else if (
+ action.action === 'bgdColorChange' ||
+ //action.action === 'thumbChange' ||
+ action.action === 'bgdImgChange' ||
+ action.action === 'descriptionChange'
+ ) {
+ currentEntry.current = {
+ ...currentEntry.current,
+ meta: action.entry.meta,
+ };
+ isChanged = true;
+ }
+ }
+ }
+ if (isChanged) {
+ forceUpdate();
+ }
+ }
+ }, [metaActions]);
+
+ /*useEffect(() => {
if (
currentEntry.current &&
currentEntry.current.path === currentDirectoryPath
@@ -223,7 +259,7 @@ export const OpenedEntryContextProvider = ({
};
forceUpdate();
}
- }, [currentDirectoryPerspective]);
+ }, [currentDirectoryPerspective]);*/
function getOpenedDirProps(): Promise<TS.DirProp> {
if (
@@ -307,9 +343,9 @@ export const OpenedEntryContextProvider = ({
}
}
- function addToEntryContainer(fsEntry: OpenedEntry) {
+ function addToEntryContainer(fsEntry: TS.OpenedEntry) {
setSharedLinks(fsEntry);
- currentEntry.current = fsEntry;
+ currentEntry.current = { ...fsEntry };
forceUpdate();
// setOpenedEntries([fsEntry]); // [...openedEntries, fsEntry] // TODO uncomment for multiple file support
}
@@ -350,7 +386,9 @@ export const OpenedEntryContextProvider = ({
function reloadOpenedFile(): Promise<boolean> {
if (currentEntry.current) {
- //openedEntries && openedEntries.length > 0) {
+ currentEntry.current.editMode = false;
+ return openEntry(currentEntry.current.path, true);
+ /*//openedEntries && openedEntries.length > 0) {
const openedFile = currentEntry.current; //openedEntries[0];
const metaFilePath = openedFile.isFile
? getMetaFileLocationForFile(
@@ -386,12 +424,12 @@ export const OpenedEntryContextProvider = ({
shouldReload: !openedFile.shouldReload,
};
return updateOpenedFile(openedFile.path, entryMeta);
- }
+ }*/
}
return Promise.resolve(false);
}
- function updateOpenedFile(
+ /*function updateOpenedFile(
entryPath: string,
fsEntryMeta: TS.FileSystemEntryMeta,
): Promise<boolean> {
@@ -399,14 +437,14 @@ export const OpenedEntryContextProvider = ({
return PlatformIO.getPropertiesPromise(entryPath)
.then((entryProps) => {
if (entryProps) {
- let entryForOpening: OpenedEntry;
+ let entryForOpening: TS.OpenedEntry;
entryForOpening = { ...currentEntry.current }; //entryExist };
if (fsEntryMeta.editMode !== undefined) {
entryForOpening.editMode = fsEntryMeta.editMode;
}
- entryForOpening.shouldReload = fsEntryMeta.shouldReload;
+ //entryForOpening.shouldReload = fsEntryMeta.shouldReload;
if (fsEntryMeta.color) {
if (fsEntryMeta.color === 'transparent') {
entryForOpening.color = undefined;
@@ -440,22 +478,26 @@ export const OpenedEntryContextProvider = ({
});
}
return Promise.resolve(false);
- }
+ }*/
- function openEntry(path?: string, showDetails = false) {
+ function openEntry(path?: string, showDetails = false): Promise<boolean> {
if (path === undefined) {
return openFsEntry(undefined, showDetails);
}
return getAllPropertiesPromise(path)
.then((fsEntry: TS.FileSystemEntry) => openFsEntry(fsEntry, showDetails))
- .catch((error) =>
+ .catch((error) => {
console.warn(
'Error getting properties for entry: ' + path + ' - ' + error,
- ),
- );
+ );
+ return false;
+ });
}
- function openFsEntry(fsEntry?: TS.FileSystemEntry, showDetails = false) {
+ function openFsEntry(
+ fsEntry?: TS.FileSystemEntry,
+ showDetails = false,
+ ): Promise<boolean> {
dispatch(SettingsActions.setShowDetails(showDetails));
if (fsEntry === undefined) {
if (selectedEntries && selectedEntries.length > 0) {
@@ -464,10 +506,10 @@ export const OpenedEntryContextProvider = ({
return openDirectory(lastSelectedEntry.path); //, false);
}
} else {
- return;
+ return Promise.resolve(false);
}
}
- let entryForOpening: OpenedEntry;
+ let entryForOpening: TS.OpenedEntry;
/**
* check for editMode in order to show save changes dialog (shouldReload: false)
@@ -478,10 +520,6 @@ export const OpenedEntryContextProvider = ({
if (openFile.editMode) {
entryForOpening = {
...openFile,
- shouldReload:
- openFile.shouldReload !== undefined
- ? !openFile.shouldReload
- : undefined,
}; // false };
addToEntryContainer(entryForOpening);
showNotification(
@@ -489,16 +527,10 @@ export const OpenedEntryContextProvider = ({
'default',
true,
);
- return false;
+ return Promise.resolve(false);
}
}
- // TODO decide to copy all props from {...fsEntry} into openedEntry
- entryForOpening = findExtensionsForEntry(
- fsEntry.uuid,
- supportedFileTypes,
- fsEntry.path,
- fsEntry.isFile,
- );
+ entryForOpening = findExtensionsForEntry(fsEntry, supportedFileTypes);
if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
const cleanedPath = fsEntry.path.startsWith('/')
? fsEntry.path.substr(1)
@@ -507,35 +539,12 @@ export const OpenedEntryContextProvider = ({
} else if (fsEntry.url) {
entryForOpening.url = fsEntry.url;
}
- if (fsEntry.perspective) {
- entryForOpening.perspective = fsEntry.perspective;
- }
- if (fsEntry.color) {
- entryForOpening.color = fsEntry.color;
- }
- if (fsEntry.description) {
- entryForOpening.description = fsEntry.description;
- }
- if (fsEntry.tags) {
- entryForOpening.tags = fsEntry.tags;
- }
- if (fsEntry.lmdt) {
- entryForOpening.lmdt = fsEntry.lmdt;
- }
- if (fsEntry.size) {
- entryForOpening.size = fsEntry.size;
- }
if (
fsEntry.isNewFile &&
AppConfig.editableFiles.includes(fsEntry.extension)
) {
entryForOpening.editMode = true;
}
- if (fsEntry.isAutoSaveEnabled !== undefined) {
- entryForOpening.isAutoSaveEnabled = fsEntry.isAutoSaveEnabled;
- } else if (fsEntry.meta && fsEntry.meta.autoSave) {
- entryForOpening.isAutoSaveEnabled = fsEntry.meta.autoSave;
- }
const locationName = currentLocation ? currentLocation.name : 'TagSpaces'; // TODO get it later from app config
@@ -587,6 +596,7 @@ export const OpenedEntryContextProvider = ({
}
}
}
+ return Promise.resolve(true);
}
function toggleEntryFullWidth() {
@@ -855,7 +865,7 @@ export const OpenedEntryContextProvider = ({
closeAllFiles,
reflectUpdateOpenedFileContent,
reloadOpenedFile,
- updateOpenedFile,
+ //updateOpenedFile,
openEntry,
openFsEntry,
toggleEntryFullWidth,
diff --git a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
index 72191a5d5..8c2dba1c2 100644
--- a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
+++ b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
@@ -83,7 +83,7 @@ export const PerspectiveSettingsContextProvider = ({
}: PerspectiveSettingsContextProviderProps) => {
const {
currentDirectoryPath,
- currentDirectoryPerspective,
+ perspective,
directoryMeta,
setDirectoryMeta,
getDefaultPerspectiveSettings,
@@ -97,22 +97,22 @@ export const PerspectiveSettingsContextProvider = ({
useEffect(() => {
settings.current = getSettings(getPerspective(), directoryMeta);
forceUpdate();
- }, [currentDirectoryPerspective, directoryMeta]);
+ }, [perspective, directoryMeta]);
function getSettings(
- perspective: string,
+ persp: string,
directoryMeta: TS.FileSystemEntryMeta,
): TS.FolderSettings {
- const defaultSettings = getDefaultPerspectiveSettings(perspective);
+ const defaultSettings = getDefaultPerspectiveSettings(persp);
let s: TS.FolderSettings = defaultSettings;
if (
Pro &&
directoryMeta &&
directoryMeta.perspectiveSettings &&
- directoryMeta.perspectiveSettings[perspective]
+ directoryMeta.perspectiveSettings[persp]
) {
const proSettings: TS.FolderSettings =
- directoryMeta.perspectiveSettings[perspective];
+ directoryMeta.perspectiveSettings[persp];
if (proSettings) {
s = { ...s, ...proSettings };
}
diff --git a/src/renderer/hooks/PlatformFacadeContextProvider.tsx b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
index 7fb0ce81b..2e84e96ff 100644
--- a/src/renderer/hooks/PlatformFacadeContextProvider.tsx
+++ b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
@@ -29,7 +29,7 @@ import {
normalizePath,
} from '@tagspaces/tagspaces-common/paths';
import { useTranslation } from 'react-i18next';
-import { actions as AppActions, AppDispatch } from '-/reducers/app';
+import { AppDispatch } from '-/reducers/app';
import { useDispatch, useSelector } from 'react-redux';
import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';
import {
@@ -169,7 +169,7 @@ export const PlatformFacadeContextProvider = ({
/**
* @param filePath
- * return Promise<directoryPath> of directory in order to open Folder properties next
+ * return Promise<destThumbPath>
*/
function setFolderThumbnailPromise(filePath: string): Promise<string> {
const directoryPath = extractContainingDirectoryPath(
@@ -196,8 +196,8 @@ export const PlatformFacadeContextProvider = ({
destThumbPath,
t('core:thumbAlreadyExists', { directoryName }),
).then(() => {
- dispatch(AppActions.setLastThumbnailImageChange(destThumbPath));
- return directoryPath;
+ // dispatch(AppActions.setLastThumbnailImageChange(destThumbPath));
+ return destThumbPath;
});
}
diff --git a/src/renderer/hooks/useEditedEntryMetaContext.tsx b/src/renderer/hooks/useEditedEntryMetaContext.tsx
new file mode 100644
index 000000000..c1e320a9b
--- /dev/null
+++ b/src/renderer/hooks/useEditedEntryMetaContext.tsx
@@ -0,0 +1,24 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2023-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import { useContext } from 'react';
+
+import { EditedEntryMetaContext } from '-/hooks/EditedEntryMetaContextProvider';
+
+export const useEditedEntryMetaContext = () =>
+ useContext(EditedEntryMetaContext);
diff --git a/src/renderer/perspectives/grid/components/GridCell.tsx b/src/renderer/perspectives/grid/components/GridCell.tsx
index 0ba97b269..49e6e747c 100644
--- a/src/renderer/perspectives/grid/components/GridCell.tsx
+++ b/src/renderer/perspectives/grid/components/GridCell.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useMemo } from 'react';
+import React, { useEffect, useMemo, useReducer, useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useTheme, styled } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
@@ -47,6 +47,7 @@ import {
findBackgroundColorForFolder,
findColorForEntry,
getDescriptionPreview,
+ getThumbPath,
} from '-/services/utils-io';
import TagContainerDnd from '-/components/TagContainerDnd';
import TagContainer from '-/components/TagContainer';
@@ -54,23 +55,16 @@ import TagsPreview from '-/components/TagsPreview';
import PlatformIO from '-/services/platform-facade';
import EntryIcon from '-/components/EntryIcon';
import { TS } from '-/tagspaces.namespace';
-import {
- actions as AppActions,
- AppDispatch,
- getLastThumbnailImageChange,
-} from '-/reducers/app';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { dataTidFormat } from '-/services/test';
-import {
- getSupportedFileTypes,
- isDesktopMode,
- isReorderTags,
-} from '-/reducers/settings';
+import { getSupportedFileTypes, isReorderTags } from '-/reducers/settings';
import { defaultSettings } from '../index';
import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';
import i18n from '-/services/i18n';
+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
export function urlGetDelim(url) {
return url.indexOf('?') > 0 ? '&' : '?';
@@ -136,14 +130,54 @@ function GridCell(props: Props) {
const theme = useTheme();
const { entrySize, showEntriesDescription, showTags, thumbnailMode } =
usePerspectiveSettingsContext();
+ const { metaActions } = useEditedEntryMetaContext();
const { selectedEntries, selectEntry } = useSelectedEntriesContext();
const { addTags, editTagForEntry } = useTaggingActionsContext();
const { readOnlyMode } = useCurrentLocationContext();
const supportedFileTypes = useSelector(getSupportedFileTypes);
const reorderTags: boolean = useSelector(isReorderTags);
- const lastThumbnailImageChange = useSelector(getLastThumbnailImageChange);
+ //const lastThumbnailImageChange = useSelector(getLastThumbnailImageChange);
// const desktopMode = useSelector(isDesktopMode);
const dispatch: AppDispatch = useDispatch();
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
+
+ const fileSystemEntryBgColor = useRef<string>(
+ findBackgroundColorForFolder(fsEntry),
+ );
+ const thumbUrl = useRef<string>(undefined);
+
+ useEffect(() => {
+ if (metaActions && metaActions.length > 0) {
+ for (const action of metaActions) {
+ if (fsEntry.path === action.entry.path) {
+ if (action.action === 'thumbChange') {
+ if (action.entry.meta.thumbPath) {
+ thumbUrl.current = getThumbPath(
+ action.entry.meta.thumbPath,
+ action.entry.meta?.lastUpdated,
+ );
+ } else {
+ //thumbnail deleted
+ thumbUrl.current = undefined;
+ if (fsEntry.meta) {
+ const { thumbPath, ...meta } = fsEntry.meta;
+ fsEntry.meta = meta;
+ }
+ }
+ forceUpdate();
+ } else if (action.action === 'bgdColorChange') {
+ fileSystemEntryBgColor.current = findBackgroundColorForFolder(
+ action.entry,
+ );
+ forceUpdate();
+ } else if (action.action === 'descriptionChange') {
+ fsEntry.meta = { ...action.entry.meta };
+ forceUpdate();
+ }
+ }
+ }
+ }
+ }, [metaActions]);
const handleEditTag = (path: string, tag: TS.Tag, newTagTitle?: string) => {
editTagForEntry(path, tag, newTagTitle);
@@ -157,19 +191,19 @@ function GridCell(props: Props) {
};
// remove isNewFile on Cell click it will open file in editMode
- const fSystemEntry: TS.FileSystemEntry = (({ isNewFile, ...o }) => o)(
+ /*const fSystemEntry: TS.FileSystemEntry = (({ isNewFile, ...o }) => o)(
fsEntry,
- );
+ );*/
const entryTitle = extractTitle(
- fSystemEntry.name,
- !fSystemEntry.isFile,
+ fsEntry.name,
+ !fsEntry.isFile,
PlatformIO.getDirSeparator(),
);
let description;
if (showEntriesDescription) {
- description = fSystemEntry.description;
+ description = fsEntry.meta?.description;
if (
description &&
description.length > defaultSettings.maxDescriptionPreviewLength
@@ -181,29 +215,26 @@ function GridCell(props: Props) {
}
}
- const fileSystemEntryColor = findColorForEntry(
- fSystemEntry,
- supportedFileTypes,
- );
- const fileSystemEntryBgColor = findBackgroundColorForFolder(fSystemEntry);
+ const fileSystemEntryColor = findColorForEntry(fsEntry, supportedFileTypes);
let fileNameTags = [];
- if (fSystemEntry.isFile) {
+ if (fsEntry.isFile) {
fileNameTags = extractTagsAsObjects(
- fSystemEntry.name,
+ fsEntry.name,
AppConfig.tagDelimiter,
PlatformIO.getDirSeparator(),
);
}
- const fileSystemEntryTags = fSystemEntry.tags ? fSystemEntry.tags : [];
+ const fileSystemEntryTags =
+ fsEntry.meta && fsEntry.meta.tags ? fsEntry.meta.tags : [];
const sideCarTagsTitles = fileSystemEntryTags.map((tag) => tag.title);
const entryTags = [
...fileSystemEntryTags,
...fileNameTags.filter((tag) => !sideCarTagsTitles.includes(tag.title)),
];
- const entryPath = fSystemEntry.path;
+ const entryPath = fsEntry.path;
const isSmall = entrySize === 'tiny' || entrySize === 'small';
const renderTags = useMemo(() => {
@@ -244,20 +275,18 @@ function GridCell(props: Props) {
function generateCardHeader() {
return (
!isSmall &&
- fSystemEntry.isFile &&
- fSystemEntry.lmdt && (
+ fsEntry.isFile &&
+ fsEntry.lmdt && (
<>
<Tooltip
title={
- t('core:modifiedDate') +
- ': ' +
- formatDateTime(fSystemEntry.lmdt, true)
+ t('core:modifiedDate') + ': ' + formatDateTime(fsEntry.lmdt, true)
}
>
- {formatDateTime(fSystemEntry.lmdt, false)}
+ {formatDateTime(fsEntry.lmdt, false)}
</Tooltip>
- <Tooltip title={fSystemEntry.size + ' ' + t('core:sizeInBytes')}>
- <span>{' | ' + formatFileSize(fSystemEntry.size)}</span>
+ <Tooltip title={fsEntry.size + ' ' + t('core:sizeInBytes')}>
+ <span>{' | ' + formatFileSize(fsEntry.size)}</span>
</Tooltip>
</>
)
@@ -284,9 +313,9 @@ function GridCell(props: Props) {
onClick={(e) => {
e.stopPropagation();
if (selected) {
- selectEntry(fSystemEntry, false);
+ selectEntry(fsEntry, false);
} else {
- selectEntry(fSystemEntry);
+ selectEntry(fsEntry);
}
}}
>
@@ -307,7 +336,7 @@ function GridCell(props: Props) {
)}
</IconButton>
) : (
- <Tooltip title={i18n.t('clickToSelect') + ' ' + fSystemEntry.path}>
+ <Tooltip title={i18n.t('clickToSelect') + ' ' + fsEntry.path}>
<Typography
style={{
paddingTop: 1,
@@ -324,34 +353,25 @@ function GridCell(props: Props) {
textShadow: '1px 1px #8f8f8f',
textOverflow: 'unset',
height: 15,
- maxWidth: fSystemEntry.isFile ? 50 : 100,
+ maxWidth: fsEntry.isFile ? 50 : 100,
}}
noWrap={true}
variant="button"
onClick={(e) => {
e.stopPropagation();
- selectEntry(fSystemEntry);
+ selectEntry(fsEntry);
}}
>
- {fSystemEntry.isFile ? fSystemEntry.extension : <FolderOutlineIcon />}
+ {fsEntry.isFile ? fsEntry.extension : <FolderOutlineIcon />}
</Typography>
</Tooltip>
);
}
- const tmbImgSrc =
- fSystemEntry.thumbPath +
- (lastThumbnailImageChange &&
- lastThumbnailImageChange.thumbPath === fSystemEntry.thumbPath &&
- !PlatformIO.haveObjectStoreSupport() &&
- !PlatformIO.haveWebDavSupport()
- ? urlGetDelim(fSystemEntry.thumbPath) + lastThumbnailImageChange.dt
- : '');
-
return (
<Card
- data-entry-id={fSystemEntry.uuid}
- data-tid={'fsEntryName_' + dataTidFormat(fSystemEntry.name)}
+ data-entry-id={fsEntry.uuid}
+ data-tid={'fsEntryName_' + dataTidFormat(fsEntry.name)}
raised={selected}
style={{
height: maxHeight,
@@ -365,25 +385,25 @@ function GridCell(props: Props) {
display: 'flex',
flexDirection: 'column',
}}
- onContextMenu={(event) => handleGridContextMenu(event, fSystemEntry)}
+ onContextMenu={(event) => handleGridContextMenu(event, fsEntry)}
onDoubleClick={(event) => {
- handleGridCellDblClick(event, fSystemEntry);
+ handleGridCellDblClick(event, fsEntry);
}}
onClick={(event) => {
event.stopPropagation();
AppConfig.isCordovaiOS // TODO DoubleClick not fired in Cordova IOS
- ? handleGridCellDblClick(event, fSystemEntry)
- : handleGridCellClick(event, fSystemEntry);
+ ? handleGridCellDblClick(event, fsEntry)
+ : handleGridCellClick(event, fsEntry);
}}
onDrag={(event) => {
- handleGridCellClick(event, fSystemEntry);
+ handleGridCellClick(event, fsEntry);
}}
>
<Box
style={{
height: maxHeight - 70,
position: 'relative',
- backgroundColor: fileSystemEntryBgColor || 'transparent',
+ backgroundColor: fileSystemEntryBgColor.current || 'transparent',
}}
>
<Box style={{ position: 'absolute' }}>
@@ -393,7 +413,7 @@ function GridCell(props: Props) {
<TagsPreview tags={entryTags} />
)}
</Box>
- {fSystemEntry.thumbPath ? (
+ {(fsEntry.meta && fsEntry.meta.thumbPath) || thumbUrl.current ? (
<CardMedia
component="img"
loading="lazy"
@@ -401,7 +421,14 @@ function GridCell(props: Props) {
onError={(i) => (i.target.style.display = 'none')}
alt="thumbnail image"
height="auto"
- src={tmbImgSrc}
+ src={
+ thumbUrl.current
+ ? thumbUrl.current
+ : getThumbPath(
+ fsEntry.meta.thumbPath,
+ fsEntry.meta?.lastUpdated,
+ )
+ }
style={{
height: maxHeight - 70,
objectFit: thumbnailMode,
@@ -416,8 +443,8 @@ function GridCell(props: Props) {
}}
>
<EntryIcon
- isFile={fSystemEntry.isFile}
- fileExtension={fSystemEntry.extension}
+ isFile={fsEntry.isFile}
+ fileExtension={fsEntry.extension}
/>
</Box>
)}
@@ -425,7 +452,7 @@ function GridCell(props: Props) {
<CardContent sx={{ padding: '1px 5px 0px 5px', flexGrow: 1 }}>
<Typography
- title={fSystemEntry.name}
+ title={fsEntry.name}
style={{
paddingRight: 4,
overflowX: 'clip',
@@ -476,7 +503,7 @@ function GridCell(props: Props) {
aria-label="entry context menu"
size="small"
style={{ marginRight: 5 }}
- onClick={(event) => handleGridContextMenu(event, fSystemEntry)}
+ onClick={(event) => handleGridContextMenu(event, fsEntry)}
>
<MoreMenuIcon />
</IconButton>
diff --git a/src/renderer/perspectives/grid/components/GridPagination.tsx b/src/renderer/perspectives/grid/components/GridPagination.tsx
index 2093fcbc8..0de230772 100644
--- a/src/renderer/perspectives/grid/components/GridPagination.tsx
+++ b/src/renderer/perspectives/grid/components/GridPagination.tsx
@@ -17,7 +17,6 @@
*/
import React, { useEffect, useReducer, useRef } from 'react';
-import { connect } from 'react-redux';
import { useTheme } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import Tooltip from '-/components/Tooltip';
@@ -27,10 +26,6 @@ import ButtonBase from '@mui/material/ButtonBase';
import Pagination from '@mui/material/Pagination';
import AppConfig from '-/AppConfig';
import { extractDirectoryName } from '@tagspaces/tagspaces-common/paths';
-import {
- getLastBackgroundImageChange,
- getLastThumbnailImageChange,
-} from '-/reducers/app';
import EntryIcon from '-/components/EntryIcon';
import TagsPreview from '-/components/TagsPreview';
import TagContainer from '-/components/TagContainer';
@@ -74,8 +69,6 @@ interface Props {
onClick: (event: React.MouseEvent<HTMLDivElement>) => void;
// eslint-disable-next-line react/no-unused-prop-types
selectedEntries; // cache only
- lastBackgroundImageChange: any;
- lastThumbnailImageChange: any;
setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
setFileContextMenuAnchorEl: (HTMLElement) => void;
setDirContextMenuAnchorEl: (HTMLElement) => void;
@@ -89,9 +82,7 @@ function GridPagination(props: Props) {
getCellContent,
desktopMode,
currentDirectoryPath,
- lastThumbnailImageChange,
openRenameEntryDialog,
- lastBackgroundImageChange,
setFileContextMenuAnchorEl,
setDirContextMenuAnchorEl,
selectedEntries,
@@ -126,31 +117,6 @@ function GridPagination(props: Props) {
: 10;
const containerEl = useRef<HTMLDivElement>(null);
- const folderTmbPath = useRef<string>(
- getFolderThumbPath(currentDirectoryPath, lastThumbnailImageChange),
- );
- const folderBgndPath = useRef<string>(
- getFolderBgndPath(currentDirectoryPath, lastBackgroundImageChange),
- );
-
- const [, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
-
- // TODO move in DirectoryContentContextProvider
- useEffect(() => {
- folderTmbPath.current = getFolderThumbPath(
- props.currentDirectoryPath,
- props.lastThumbnailImageChange,
- );
- forceUpdate();
- }, [props.currentDirectoryPath, props.lastThumbnailImageChange]);
-
- useEffect(() => {
- folderBgndPath.current = getFolderBgndPath(
- props.currentDirectoryPath,
- props.lastBackgroundImageChange,
- );
- forceUpdate();
- }, [props.currentDirectoryPath, props.lastBackgroundImageChange]);
const handleChange = (event, value) => {
setCurrentPage(value);
@@ -194,7 +160,13 @@ function GridPagination(props: Props) {
style={{
height: '100%',
overflowY: 'auto',
- backgroundImage: 'url("' + folderBgndPath.current + '")',
+ backgroundImage:
+ 'url("' +
+ getFolderBgndPath(
+ currentDirectoryPath,
+ directoryMeta?.lastUpdated,
+ ) +
+ '")',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
}}
@@ -295,13 +267,18 @@ function GridPagination(props: Props) {
</Typography>
)}
</Box>
- {/* <Tooltip title={t('core:thumbnail')}> */}
<div
style={{
borderRadius: 10,
height: 100,
width: 140,
- backgroundImage: `url("${folderTmbPath.current}")`,
+ backgroundImage:
+ 'url("' +
+ getFolderThumbPath(
+ currentDirectoryPath,
+ directoryMeta?.lastUpdated,
+ ) +
+ '")',
backgroundSize: 'cover', // cover contain
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center center',
@@ -309,8 +286,7 @@ function GridPagination(props: Props) {
top: 0,
right: 0,
}}
- ></div>
- {/* </Tooltip> */}
+ />
</div>
</Grid>
)}
@@ -472,14 +448,7 @@ function GridPagination(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- lastBackgroundImageChange: getLastBackgroundImageChange(state),
- lastThumbnailImageChange: getLastThumbnailImageChange(state),
- };
-}
-
-const areEqual = (prevProp: Props, nextProp: Props) =>
+/*const areEqual = (prevProp: Props, nextProp: Props) =>
JSON.stringify(nextProp.lastBackgroundImageChange) ===
JSON.stringify(prevProp.lastBackgroundImageChange) &&
JSON.stringify(nextProp.lastThumbnailImageChange) ===
@@ -495,6 +464,6 @@ const areEqual = (prevProp: Props, nextProp: Props) =>
JSON.stringify(prevProp.directories) &&
// JSON.stringify(nextProp.settings) === JSON.stringify(prevProp.settings) &&
JSON.stringify(nextProp.selectedEntries) ===
- JSON.stringify(prevProp.selectedEntries);
+ JSON.stringify(prevProp.selectedEntries);*/
-export default connect(mapStateToProps)(React.memo(GridPagination, areEqual));
+export default GridPagination;
diff --git a/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx b/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx
index eecbc3a34..dd9ed239b 100644
--- a/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx
+++ b/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx
@@ -51,16 +51,13 @@ export type SortedDirContextProviderProps = {
export const SortedDirContextProvider = ({
children,
}: SortedDirContextProviderProps) => {
- const {
- currentDirectoryEntries,
- directoryMeta,
- currentDirectoryPerspective,
- } = useDirectoryContentContext();
+ const { currentDirectoryEntries, directoryMeta, perspective } =
+ useDirectoryContentContext();
const searchFilter: string = useSelector(getSearchFilter);
const settings: TS.FolderSettings = useMemo(() => {
- return getSettings(directoryMeta, currentDirectoryPerspective);
- }, [directoryMeta, currentDirectoryPerspective]);
+ return getSettings(directoryMeta, perspective);
+ }, [directoryMeta, perspective]);
const [sortBy, setSortBy] = useState<string>(
settings && settings.sortBy ? settings.sortBy : defaultSettings.sortBy,
@@ -71,20 +68,17 @@ export const SortedDirContextProvider = ({
: defaultSettings.orderBy,
);
- function getSettings(
- meta,
- perspective = PerspectiveIDs.GRID,
- ): TS.FolderSettings {
- if (perspective === PerspectiveIDs.UNSPECIFIED) {
- perspective = PerspectiveIDs.GRID;
+ function getSettings(meta, persp = PerspectiveIDs.GRID): TS.FolderSettings {
+ if (persp === PerspectiveIDs.UNSPECIFIED) {
+ persp = PerspectiveIDs.GRID;
}
if (
Pro &&
meta &&
meta.perspectiveSettings &&
- meta.perspectiveSettings[perspective]
+ meta.perspectiveSettings[persp]
) {
- return meta.perspectiveSettings[perspective];
+ return meta.perspectiveSettings[persp];
} else {
// loading settings for not Pro
return JSON.parse(localStorage.getItem(defaultSettings.settingsKey));
diff --git a/src/renderer/perspectives/list/components/RowCell.tsx b/src/renderer/perspectives/list/components/RowCell.tsx
index d854da1ac..827cd45ba 100644
--- a/src/renderer/perspectives/list/components/RowCell.tsx
+++ b/src/renderer/perspectives/list/components/RowCell.tsx
@@ -49,11 +49,7 @@ import TagContainer from '-/components/TagContainer';
import TagsPreview from '-/components/TagsPreview';
import PlatformIO from '-/services/platform-facade';
import { TS } from '-/tagspaces.namespace';
-import {
- actions as AppActions,
- AppDispatch,
- getLastThumbnailImageChange,
-} from '-/reducers/app';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { getSupportedFileTypes, isReorderTags } from '-/reducers/settings';
import { defaultSettings } from '../index';
import { useTranslation } from 'react-i18next';
@@ -142,7 +138,6 @@ function RowCell(props: Props) {
const { readOnlyMode } = useCurrentLocationContext();
const supportedFileTypes = useSelector(getSupportedFileTypes);
const reorderTags: boolean = useSelector(isReorderTags);
- const lastThumbnailImageChange = useSelector(getLastThumbnailImageChange);
const dispatch: AppDispatch = useDispatch();
// You can use the dispatch function to dispatch actions
@@ -158,19 +153,19 @@ function RowCell(props: Props) {
};
// remove isNewFile on Cell click it will open file in editMode
- const fSystemEntry: TS.FileSystemEntry = (({ isNewFile, ...o }) => o)(
+ /*const fSystemEntry: TS.FileSystemEntry = (({ isNewFile, ...o }) => o)(
fsEntry,
- );
+ );*/
const entryTitle = extractTitle(
- fSystemEntry.name,
- !fSystemEntry.isFile,
+ fsEntry.name,
+ !fsEntry.isFile,
PlatformIO.getDirSeparator(),
);
let description;
if (showEntriesDescription) {
- description = fSystemEntry.description;
+ description = fsEntry.meta?.description;
if (
description &&
description.length > defaultSettings.maxDescriptionPreviewLength
@@ -181,41 +176,37 @@ function RowCell(props: Props) {
);
}
- if (description && fSystemEntry.isFile) {
+ if (description && fsEntry.isFile) {
description = ' | ' + description;
}
}
- const fileSystemEntryColor = findColorForEntry(
- fSystemEntry,
- supportedFileTypes,
- );
- const fileSystemEntryBgColor = findBackgroundColorForFolder(fSystemEntry);
+ const fileSystemEntryColor = findColorForEntry(fsEntry, supportedFileTypes);
+ const fileSystemEntryBgColor = findBackgroundColorForFolder(fsEntry);
let fileNameTags = [];
- if (fSystemEntry.isFile) {
+ if (fsEntry.isFile) {
fileNameTags = extractTagsAsObjects(
- fSystemEntry.name,
+ fsEntry.name,
AppConfig.tagDelimiter,
PlatformIO.getDirSeparator(),
);
}
- const fileSystemEntryTags = fSystemEntry.tags ? fSystemEntry.tags : [];
+ const fileSystemEntryTags =
+ fsEntry.meta && fsEntry.meta.tags ? fsEntry.meta.tags : [];
const sideCarTagsTitles = fileSystemEntryTags.map((tag) => tag.title);
const entryTags = [
...fileSystemEntryTags,
...fileNameTags.filter((tag) => !sideCarTagsTitles.includes(tag.title)),
];
- const entrySizeFormatted = fSystemEntry.isFile
- ? formatFileSize(fSystemEntry.size) + ' | '
+ const entrySizeFormatted = fsEntry.isFile
+ ? formatFileSize(fsEntry.size) + ' | '
: '';
const entryLMDTFormatted =
- fSystemEntry.isFile &&
- fSystemEntry.lmdt &&
- formatDateTime(fSystemEntry.lmdt, true);
+ fsEntry.isFile && fsEntry.lmdt && formatDateTime(fsEntry.lmdt, true);
let tagTitles = '';
if (entryTags) {
@@ -231,7 +222,7 @@ function RowCell(props: Props) {
return url.indexOf('?') > 0 ? '&' : '?';
}
- const entryPath = fSystemEntry.path;
+ const entryPath = fsEntry.path;
const renderTags = useMemo(() => {
let sideCarLength = 0;
@@ -288,9 +279,9 @@ function RowCell(props: Props) {
onClick={(e) => {
e.stopPropagation();
if (selected) {
- selectEntry(fSystemEntry, false);
+ selectEntry(fsEntry, false);
} else {
- selectEntry(fSystemEntry);
+ selectEntry(fsEntry);
}
}}
>
@@ -311,7 +302,7 @@ function RowCell(props: Props) {
)}
</IconButton>
) : (
- <Tooltip title={i18n.t('clickToSelect') + ' ' + fSystemEntry.path}>
+ <Tooltip title={i18n.t('clickToSelect') + ' ' + fsEntry.path}>
<Typography
style={{
paddingTop: 1,
@@ -328,17 +319,17 @@ function RowCell(props: Props) {
textShadow: '1px 1px #8f8f8f',
textOverflow: 'unset',
height: 15,
- maxWidth: fSystemEntry.isFile ? 50 : 100,
+ maxWidth: fsEntry.isFile ? 50 : 100,
alignSelf: 'center',
}}
noWrap={true}
variant="button"
onClick={(e) => {
e.stopPropagation();
- selectEntry(fSystemEntry);
+ selectEntry(fsEntry);
}}
>
- {fSystemEntry.isFile ? fSystemEntry.extension : <FolderOutlineIcon />}
+ {fsEntry.isFile ? fsEntry.extension : <FolderOutlineIcon />}
</Typography>
</Tooltip>
);
@@ -354,7 +345,7 @@ function RowCell(props: Props) {
return (
<RowPaper
elevation={2}
- data-entry-id={fSystemEntry.uuid}
+ data-entry-id={fsEntry.uuid}
className={classNames(
classes.rowCell,
selected && classes.selectedRowCell,
@@ -364,18 +355,18 @@ function RowCell(props: Props) {
marginBottom: isLast ? 40 : 'auto',
backgroundColor: theme.palette.background.default,
}}
- onContextMenu={(event) => handleGridContextMenu(event, fSystemEntry)}
+ onContextMenu={(event) => handleGridContextMenu(event, fsEntry)}
onDoubleClick={(event) => {
- handleGridCellDblClick(event, fSystemEntry);
+ handleGridCellDblClick(event, fsEntry);
}}
onClick={(event) => {
event.stopPropagation();
AppConfig.isCordovaiOS // TODO DoubleClick not fired in Cordova IOS
- ? handleGridCellDblClick(event, fSystemEntry)
- : handleGridCellClick(event, fSystemEntry);
+ ? handleGridCellDblClick(event, fsEntry)
+ : handleGridCellClick(event, fsEntry);
}}
onDrag={(event) => {
- handleGridCellClick(event, fSystemEntry);
+ handleGridCellClick(event, fsEntry);
}}
>
<Grid
@@ -416,10 +407,10 @@ function RowCell(props: Props) {
alignSelf: 'center',
}}
title={
- fSystemEntry.name +
+ fsEntry.name +
' | ' +
entrySizeFormatted +
- formatDateTime(fSystemEntry.lmdt, true)
+ formatDateTime(fsEntry.lmdt, true)
}
>
<>{entryTitle}</>
@@ -431,7 +422,7 @@ function RowCell(props: Props) {
<Grid item xs zeroMinWidth style={{ alignSelf: 'center' }}>
<Typography
variant="body1"
- title={fSystemEntry.name}
+ title={fsEntry.name}
style={{ wordBreak: 'break-all' }}
>
{entryTitle}
@@ -443,14 +434,14 @@ function RowCell(props: Props) {
}}
variant="body2"
>
- <Tooltip title={fSystemEntry.size + ' ' + t('core:sizeInBytes')}>
+ <Tooltip title={fsEntry.size + ' ' + t('core:sizeInBytes')}>
{entrySizeFormatted}
</Tooltip>
<Tooltip
title={
t('core:modifiedDate') +
': ' +
- formatDateTime(fSystemEntry.lmdt, true)
+ formatDateTime(fsEntry.lmdt, true)
}
>
<span>{entryLMDTFormatted}</span>
@@ -460,7 +451,7 @@ function RowCell(props: Props) {
{showTags && entryTags ? renderTags : tagPlaceholder}
</Grid>
)}
- {fSystemEntry.thumbPath && (
+ {fsEntry.meta && fsEntry.meta.thumbPath && (
<Grid
item
style={{
@@ -472,13 +463,13 @@ function RowCell(props: Props) {
<img
alt="thumbnail"
src={
- fSystemEntry.thumbPath +
- (lastThumbnailImageChange &&
- lastThumbnailImageChange.thumbPath === fSystemEntry.thumbPath &&
+ fsEntry.meta?.thumbPath +
+ (fsEntry.meta &&
+ fsEntry.meta.thumbPath &&
!PlatformIO.haveObjectStoreSupport() &&
!PlatformIO.haveWebDavSupport()
- ? urlGetDelim(fSystemEntry.thumbPath) +
- lastThumbnailImageChange.dt
+ ? urlGetDelim(fsEntry.meta?.thumbPath) +
+ fsEntry.meta.lastUpdated
: '')
}
// @ts-ignore
diff --git a/src/renderer/reducers/app.ts b/src/renderer/reducers/app.ts
index be11b9495..673c8b3e7 100644
--- a/src/renderer/reducers/app.ts
+++ b/src/renderer/reducers/app.ts
@@ -49,9 +49,9 @@ export const types = {
PROGRESS: 'APP/PROGRESS',
PROGRESS_FINISH: 'APP/PROGRESS_FINISH',
RESET_PROGRESS: 'APP/RESET_PROGRESS',
- LAST_BACKGROUND_IMAGE_CHANGE: 'APP/LAST_BACKGROUND_IMAGE_CHANGE',
- LAST_BACKGROUND_COLOR_CHANGE: 'APP/LAST_BACKGROUND_COLOR_CHANGE',
- LAST_THUMBNAIL_IMAGE_CHANGE: 'APP/LAST_THUMBNAIL_IMAGE_CHANGE',
+ //LAST_BACKGROUND_IMAGE_CHANGE: 'APP/LAST_BACKGROUND_IMAGE_CHANGE',
+ //LAST_BACKGROUND_COLOR_CHANGE: 'APP/LAST_BACKGROUND_COLOR_CHANGE',
+ //LAST_THUMBNAIL_IMAGE_CHANGE: 'APP/LAST_THUMBNAIL_IMAGE_CHANGE',
//OPEN_LINK: 'APP/OPEN_LINK',
LOGIN_SUCCESS: 'APP/LOGIN_SUCCESS',
LOGIN_FAILURE: 'APP/LOGIN_FAILURE',
@@ -115,7 +115,7 @@ export const types = {
UPDATE_EXTENSION: 'APP/UPDATE_EXTENSION',
};
-export type OpenedEntry = {
+/*export type OpenedEntry = {
uuid: string;
path: string;
url?: string;
@@ -133,15 +133,15 @@ export type OpenedEntry = {
perspective?: TS.PerspectiveType;
editMode?: boolean;
// changed?: boolean;
- /**
+ /!**
* if its true iframe will be reloaded
* if its false && editMode==true and changed==true => show reload dialog
* default: undefined
- */
+ *!/
shouldReload?: boolean;
focused?: boolean; // TODO make it mandatory once support for multiple files is added
tags?: Array<TS.Tag>;
-};
+};*/
let showLocations = true;
let showTagLibrary = false;
@@ -226,7 +226,7 @@ export const initialState = {
// eslint-disable-next-line default-param-last
export default (state: any = initialState, action: any) => {
switch (action.type) {
- case types.LAST_BACKGROUND_IMAGE_CHANGE: {
+ /*case types.LAST_BACKGROUND_IMAGE_CHANGE: {
return {
...state,
lastBackgroundImageChange: {
@@ -252,7 +252,7 @@ export default (state: any = initialState, action: any) => {
dt: action.lastThumbnailImageChange,
},
};
- }
+ }*/
case types.LOGIN_SUCCESS: {
return { ...state, user: action.user };
}
@@ -626,7 +626,7 @@ export const actions = {
type: types.UPDATE_EXTENSION,
extension,
}),
- setLastBackgroundImageChange: (folderPath, lastBackgroundImageChange) => ({
+ /*setLastBackgroundImageChange: (folderPath, lastBackgroundImageChange) => ({
type: types.LAST_BACKGROUND_IMAGE_CHANGE,
folderPath,
lastBackgroundImageChange,
@@ -636,15 +636,15 @@ export const actions = {
folderPath,
lastBackgroundColorChange,
}),
- /**
+ /!**
* @param thumbPath
* @param lastThumbnailImageChange - timestamp set -1 if thumbnail image deleted
- */
+ *!/
setLastThumbnailImageChange: (thumbPath, lastThumbnailImageChange?) => ({
type: types.LAST_THUMBNAIL_IMAGE_CHANGE,
thumbPath,
lastThumbnailImageChange: lastThumbnailImageChange || new Date().getTime(),
- }),
+ }),*/
loggedIn: (user) => ({ type: types.LOGIN_SUCCESS, user }),
/*openLink: (url: string, options = { fullWidth: true }) => ({
type: types.OPEN_LINK,
@@ -946,12 +946,12 @@ export const actions = {
};
// Selectors
-export const getLastBackgroundImageChange = (state: any) =>
+/*export const getLastBackgroundImageChange = (state: any) =>
state.app.lastBackgroundImageChange;
export const getLastBackgroundColorChange = (state: any) =>
state.app.lastBackgroundColorChange;
export const getLastThumbnailImageChange = (state: any) =>
- state.app.lastThumbnailImageChange;
+ state.app.lastThumbnailImageChange;*/
export const currentUser = (state: any) => state.app.user;
//export const getEditedEntryPaths = (state: any) => state.app.editedEntryPaths;
/*export const getCurrentDirectoryColor = (state: any) =>
diff --git a/src/renderer/services/meta-loader.ts b/src/renderer/services/meta-loader.ts
index 726146093..06365bec3 100644
--- a/src/renderer/services/meta-loader.ts
+++ b/src/renderer/services/meta-loader.ts
@@ -1,12 +1,13 @@
import { TS } from '-/tagspaces.namespace';
import PlatformIO from '-/services/platform-facade';
-import { getMetaForEntry } from '-/services/utils-io';
+import { executePromisesInBatches, getMetaForEntry } from '-/services/utils-io';
import {
getMetaFileLocationForDir,
getMetaFileLocationForFile,
getThumbFileLocationForDirectory,
getThumbFileLocationForFile,
} from '@tagspaces/tagspaces-common/paths';
+import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import AppConfig from '-/AppConfig';
export function loadCurrentDirMeta(
@@ -37,8 +38,9 @@ export function loadCurrentDirMeta(
}
function getEntries(metaPromises): Promise<TS.FileSystemEntry[]> {
- const catchHandler = (error) => undefined;
- return Promise.all(metaPromises.map((promise) => promise.catch(catchHandler)))
+ // const catchHandler = (error) => undefined;
+ //return Promise.all(metaPromises.map((promise) => promise.catch(catchHandler)))
+ return executePromisesInBatches(metaPromises, 100)
.then((entries: TS.FileSystemEntry[]) => {
return entries;
})
@@ -84,7 +86,7 @@ function getThumbs(
function setThumbForEntry(
entry: TS.FileSystemEntry,
- meta: Array<any>,
+ meta: Array<any>, //TS.FileSystemEntryMeta[], -> todo extra path in meta
): TS.FileSystemEntry {
const thumbEntry = { ...entry, tags: [] };
let thumbPath = getThumbFileLocationForFile(
@@ -92,8 +94,9 @@ function setThumbForEntry(
PlatformIO.getDirSeparator(),
false,
);
- if (thumbPath && meta.some((metaFile) => thumbPath.endsWith(metaFile.path))) {
- thumbEntry.thumbPath = thumbPath;
+ const metaFile = meta.find((m) => thumbPath.endsWith(m.path));
+ if (thumbPath && metaFile) {
+ thumbEntry.meta = { id: getUuid(), thumbPath }; //{ ...metaFile, thumbPath };
if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
if (thumbPath && thumbPath.startsWith('/')) {
thumbPath = thumbPath.substring(1);
@@ -101,7 +104,7 @@ function setThumbForEntry(
thumbPath = PlatformIO.getURLforPath(thumbPath, 604800);
if (thumbPath) {
- thumbEntry.thumbPath = thumbPath;
+ thumbEntry.meta = { id: getUuid(), thumbPath };
}
}
}
diff --git a/src/renderer/services/thumbsgenerator.ts b/src/renderer/services/thumbsgenerator.ts
index a357fe9f2..b3029ae18 100644
--- a/src/renderer/services/thumbsgenerator.ts
+++ b/src/renderer/services/thumbsgenerator.ts
@@ -353,109 +353,121 @@ export function getMimeType(extension) {
return types[extension];
}
-export function generateImageThumbnail(
- fileURL: string,
+/**
+ * src: image url or base64string
+ * maxTmbSize - max size of image if not set return full image size (from url)
+ * return: base64 image string
+ */
+export function getResizedImageThumbnail(
+ src: string,
maxTmbSize?: number,
): Promise<string> {
return new Promise((resolve) => {
- try {
- PlatformIO.getFileContentPromise(fileURL, 'arraybuffer')
- .then((content) => {
- let canvas: HTMLCanvasElement = document.createElement('canvas');
- const ctx = canvas.getContext('2d');
- let img: HTMLImageElement = new Image();
- if (maxTmbSize && maxTmbSize > maxSize) {
- maxSize = maxTmbSize;
- }
- img.crossOrigin = 'anonymous';
- img.onload = () => {
- // EXIF extraction not need because the image are rotated
- // automatically in Chrome version 81 and higher
- // EXIF.getData(img as any, function() {
- // // TODO Use EXIF only for jpegs
- // const orientation = EXIF.getTag(this, 'Orientation');
- // /*
- // 1 - 0 degrees – the correct orientation, no adjustment is required.
- // 2 - 0 degrees, mirrored – image has been flipped back-to-front.
- // 3 - 180 degrees – image is upside down.
- // 4 - 180 degrees, mirrored – image is upside down and flipped back-to-front.
- // 5 - 90 degrees – image is on its side.
- // 6 - 90 degrees, mirrored – image is on its side and flipped back-to-front.
- // 7 - 270 degrees – image is on its far side.
- // 8 - 270 degrees, mirrored – image is on its far side and flipped back-to-front.
- // */
- // let angleInRadians;
- // switch (orientation) {
- // case 8:
- // angleInRadians = 270 * (Math.PI / 180);
- // break;
- // case 3:
- // angleInRadians = 180 * (Math.PI / 180);
- // break;
- // case 6:
- // angleInRadians = 90 * (Math.PI / 180);
- // break;
- // case 1:
- // // ctx.rotate(0);
- // break;
- // default:
- // // ctx.rotate(0);
- // }
- let maxSizeWidth = maxSize;
- if (img.width < maxSize) {
- maxSizeWidth = img.width;
- }
- let maxSizeHeight = maxSize;
- if (img.height < maxSize) {
- maxSizeHeight = img.height;
- }
- if (img.width >= img.height) {
- canvas.width = maxSizeWidth;
- canvas.height = (maxSizeWidth * img.height) / img.width;
- } else {
- canvas.height = maxSizeHeight;
- canvas.width = (maxSizeHeight * img.width) / img.height;
- }
+ let canvas: HTMLCanvasElement = document.createElement('canvas');
+ const ctx = canvas.getContext('2d');
+ let img: HTMLImageElement = new Image();
+ if (maxTmbSize && maxTmbSize > maxSize) {
+ maxSize = maxTmbSize;
+ }
+ img.crossOrigin = 'anonymous';
+ img.onload = () => {
+ // EXIF extraction not need because the image are rotated
+ // automatically in Chrome version 81 and higher
+ // EXIF.getData(img as any, function() {
+ // // TODO Use EXIF only for jpegs
+ // const orientation = EXIF.getTag(this, 'Orientation');
+ // /*
+ // 1 - 0 degrees – the correct orientation, no adjustment is required.
+ // 2 - 0 degrees, mirrored – image has been flipped back-to-front.
+ // 3 - 180 degrees – image is upside down.
+ // 4 - 180 degrees, mirrored – image is upside down and flipped back-to-front.
+ // 5 - 90 degrees – image is on its side.
+ // 6 - 90 degrees, mirrored – image is on its side and flipped back-to-front.
+ // 7 - 270 degrees – image is on its far side.
+ // 8 - 270 degrees, mirrored – image is on its far side and flipped back-to-front.
+ // */
+ // let angleInRadians;
+ // switch (orientation) {
+ // case 8:
+ // angleInRadians = 270 * (Math.PI / 180);
+ // break;
+ // case 3:
+ // angleInRadians = 180 * (Math.PI / 180);
+ // break;
+ // case 6:
+ // angleInRadians = 90 * (Math.PI / 180);
+ // break;
+ // case 1:
+ // // ctx.rotate(0);
+ // break;
+ // default:
+ // // ctx.rotate(0);
+ // }
+ let maxSizeWidth = maxSize;
+ if (img.width < maxSize) {
+ maxSizeWidth = img.width;
+ }
+ let maxSizeHeight = maxSize;
+ if (img.height < maxSize) {
+ maxSizeHeight = img.height;
+ }
+ if (img.width >= img.height) {
+ canvas.width = maxSizeWidth;
+ canvas.height = (maxSizeWidth * img.height) / img.width;
+ } else {
+ canvas.height = maxSizeHeight;
+ canvas.width = (maxSizeHeight * img.width) / img.height;
+ }
- const { width, height } = canvas;
- const x = canvas.width / 2;
- const y = canvas.height / 2;
+ const { width, height } = canvas;
+ const x = canvas.width / 2;
+ const y = canvas.height / 2;
- ctx.translate(x, y);
- // ctx.rotate(angleInRadians);
- ctx.fillStyle = thumbnailBackgroundColor;
- ctx.fillRect(-width / 2, -height / 2, width, height);
- ctx.drawImage(img, -width / 2, -height / 2, width, height);
- // ctx.rotate(-angleInRadians);
- ctx.translate(-x, -y);
- const dataurl = canvas.toDataURL(AppConfig.thumbType);
- resolve(dataurl);
- img = null;
- canvas = null;
- // });
- };
- const ext = extractFileExtension(
- fileURL,
- PlatformIO.getDirSeparator(),
- ).toLowerCase();
- const blob = new Blob([content], { type: getMimeType(ext) });
- img.src = URL.createObjectURL(blob);
- img.onerror = (err) => {
- console.warn(`Error loading: ${fileURL} for tmb gen`, err);
- resolve('');
- };
- })
- .catch((e) => {
- console.log(`Error get: ${fileURL}`, e);
- resolve('');
- });
- } catch (e) {
- console.warn(`Error creating image thumb for : ${fileURL}`, e);
+ ctx.translate(x, y);
+ // ctx.rotate(angleInRadians);
+ ctx.fillStyle = thumbnailBackgroundColor;
+ ctx.fillRect(-width / 2, -height / 2, width, height);
+ ctx.drawImage(img, -width / 2, -height / 2, width, height);
+ // ctx.rotate(-angleInRadians);
+ ctx.translate(-x, -y);
+ const dataurl = canvas.toDataURL(AppConfig.thumbType);
+ resolve(dataurl);
+ img = null;
+ canvas = null;
+ // });
+ };
+ img.src = src;
+ img.onerror = (err) => {
+ console.warn(`Error getResizedImageThumbnail`, err);
resolve('');
- }
+ };
});
}
+export function generateImageThumbnail(
+ fileURL: string,
+ maxTmbSize?: number,
+): Promise<string> {
+ try {
+ return PlatformIO.getFileContentPromise(fileURL, 'arraybuffer')
+ .then((content) => {
+ const ext = extractFileExtension(
+ fileURL,
+ PlatformIO.getDirSeparator(),
+ ).toLowerCase();
+ const blob = new Blob([content], { type: getMimeType(ext) });
+ return getResizedImageThumbnail(URL.createObjectURL(blob), maxTmbSize);
+ })
+ .catch((e) => {
+ console.log(`Error get: ${fileURL}`, e);
+ return Promise.resolve('');
+ });
+ } catch (e) {
+ console.warn(`Error creating image thumb for : ${fileURL}`, e);
+ return Promise.resolve('');
+ }
+}
+
function generateVideoThumbnail(fileURL): Promise<string> {
return new Promise((resolve) => {
try {
diff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.ts
index 20db4d904..ef9aa8a03 100644
--- a/src/renderer/services/utils-io.ts
+++ b/src/renderer/services/utils-io.ts
@@ -45,13 +45,13 @@ import {
extractFileName,
normalizePath,
getThumbFileLocationForDirectory,
+ getThumbFileLocationForFile,
getBgndFileLocationForDirectory,
cleanFrontDirSeparator,
} from '@tagspaces/tagspaces-common/paths';
import AppConfig from '-/AppConfig';
import PlatformIO from './platform-facade';
import versionMeta from '../version.json';
-import { OpenedEntry } from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import { generateImageThumbnail } from '-/services/thumbsgenerator';
import { base64ToArrayBuffer } from '-/utils/dom';
@@ -99,9 +99,9 @@ export function getMetaForEntry(
}
export function enhanceOpenedEntry(
- entry: OpenedEntry,
+ entry: TS.OpenedEntry,
tagDelimiter,
-): OpenedEntry {
+): TS.OpenedEntry {
if (entry.isFile) {
const fineNameTags = extractTagsAsObjects(
entry.path,
@@ -318,9 +318,9 @@ export function findExtensionPathForId(
}
export function addExtensionsForEntry(
- openedEntry: OpenedEntry,
+ openedEntry: TS.OpenedEntry,
supportedFileTypes: Array<TS.FileTypes>,
-): OpenedEntry {
+): TS.OpenedEntry {
const fileExtension = extractFileExtension(
openedEntry.path,
PlatformIO.getDirSeparator(),
@@ -334,7 +334,9 @@ export function addExtensionsForEntry(
if (fileType) {
fileForOpening.viewingExtensionId = fileType.viewer;
if (fileType.color) {
- fileForOpening.color = fileType.color;
+ fileForOpening.meta = fileForOpening.meta
+ ? { ...fileForOpening.meta, color: fileType.color }
+ : { id: openedEntry.uuid, color: fileType.color };
}
fileForOpening.viewingExtensionPath = findExtensionPathForId(
fileType.viewer,
@@ -356,22 +358,18 @@ export function addExtensionsForEntry(
}
export function findExtensionsForEntry(
- uuid: string,
+ entry: TS.FileSystemEntry,
supportedFileTypes: Array<any>,
- entryPath: string,
- isFile = true,
-): OpenedEntry {
+): TS.OpenedEntry {
return addExtensionsForEntry(
{
- ...(uuid && { uuid: uuid }),
- path: entryPath,
+ ...entry,
viewingExtensionPath: 'about:blank',
viewingExtensionId: '',
- isFile,
- // changed: false,
- // locationId: undefined,
- lmdt: 0,
+ /*lmdt: 0,
size: 0,
+ name: '',
+ tags: [],*/
},
supportedFileTypes,
);
@@ -986,6 +984,9 @@ export function cleanMetaData(
if (metaData.autoSave) {
cleanedMeta.autoSave = metaData.autoSave;
}
+ if (metaData.thumbPath) {
+ cleanedMeta.thumbPath = metaData.thumbPath;
+ }
/*if (metaData.perspectiveSettings) { // clean perspectiveSettings !== defaultSettings
Object.keys(metaData.perspectiveSettings).forEach(perspective => {
if (!cleanedMeta.perspectiveSettings) {
@@ -1097,10 +1098,14 @@ export async function saveLocationDataPromise(
return Promise.reject(new Error('file not found' + path));
}
+/**
+ * @param path
+ * @param metaData - this will override existing meta data
+ */
export async function saveMetaDataPromise(
path: string,
metaData: any,
-): Promise<any> {
+): Promise<TS.FileSystemEntryMeta> {
const entryProperties = await PlatformIO.getPropertiesPromise(path);
const cleanedMetaData = cleanMetaData(metaData);
if (entryProperties) {
@@ -1142,12 +1147,13 @@ export async function saveMetaDataPromise(
PlatformIO.getDirSeparator(),
);
}
- const content = JSON.stringify(mergeFsEntryMeta(cleanedMetaData));
+ const meta = mergeFsEntryMeta(cleanedMetaData);
+ const content = JSON.stringify(meta);
return PlatformIO.saveTextFilePromise(
{ path: metaFilePath },
content,
true,
- );
+ ).then(() => meta);
}
return Promise.reject(new Error('file not found' + path));
}
@@ -1193,8 +1199,8 @@ export function setFolderBackgroundPromise(
export function findBackgroundColorForFolder(fsEntry: TS.FileSystemEntry) {
if (!fsEntry.isFile) {
- if (fsEntry.color) {
- return fsEntry.color;
+ if (fsEntry.meta && fsEntry.meta.color) {
+ return fsEntry.meta.color;
}
}
return 'transparent';
@@ -1415,23 +1421,44 @@ function mergeTags(oldTagsArray: Array<TS.Tag>, newTagsArray: Array<TS.Tag>) {
return [...oldTagsArray, ...uniqueTags];
}
-export function getFolderThumbPath(
- path: string,
- lastThumbnailImageChange: any,
-) {
+export function getThumbEntryPath(entry: TS.FileSystemEntry, encoded = false) {
+ if (!entry) {
+ return undefined;
+ }
+ return entry.isFile
+ ? getThumbFileLocationForFile(
+ entry.path,
+ PlatformIO.getDirSeparator(),
+ encoded,
+ )
+ : getThumbFileLocationForDirectory(
+ entry.path,
+ PlatformIO.getDirSeparator(),
+ );
+}
+
+export function getEntryThumbPath(entry: TS.FileSystemEntry, dt = undefined) {
+ if (entry) {
+ return getThumbPath(getThumbEntryPath(entry), dt);
+ }
+ return undefined;
+}
+
+/**
+ * @param path
+ * @param dt
+ */
+export function getFolderThumbPath(path: string, dt = undefined) {
if (path) {
return getThumbPath(
getThumbFileLocationForDirectory(path, PlatformIO.getDirSeparator()),
- lastThumbnailImageChange,
+ dt,
);
}
return undefined;
}
-export function getThumbPath(
- thumbPath: string,
- lastThumbnailImageChange?: any,
-) {
+export function getThumbPath(thumbPath: string, dt = undefined) {
if (!thumbPath) {
return undefined;
}
@@ -1441,13 +1468,7 @@ export function getThumbPath(
}
return PlatformIO.getURLforPath(thumbPath);
}
- return (
- normalizeUrl(thumbPath) +
- (lastThumbnailImageChange &&
- lastThumbnailImageChange.thumbPath === thumbPath
- ? '?' + lastThumbnailImageChange.dt
- : '')
- );
+ return normalizeUrl(thumbPath) + (dt ? '?' + dt : '');
}
function isSignedURL(signedUrl) {
@@ -1458,33 +1479,24 @@ function isSignedURL(signedUrl) {
return false;
}
-export function getFolderBgndPath(
- path: string,
- lastBackgroundImageChange: any,
-) {
+export function getFolderBgndPath(path: string, dt = undefined) {
if (path !== undefined) {
return getBgndPath(
getBgndFileLocationForDirectory(path, PlatformIO.getDirSeparator()),
- lastBackgroundImageChange,
+ dt,
);
}
return undefined;
}
-export function getBgndPath(bgndPath: string, lastBackgroundImageChange: any) {
+export function getBgndPath(bgndPath: string, dt = undefined) {
if (!bgndPath) {
return undefined;
}
if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
return PlatformIO.getURLforPath(bgndPath);
}
- return (
- normalizeUrl(bgndPath) +
- (lastBackgroundImageChange
- ? // && lastBackgroundImageChange.folderPath === bgndPath
- '?' + lastBackgroundImageChange.dt
- : '')
- );
+ return normalizeUrl(bgndPath) + (dt ? '?' + dt : '');
}
export function setLocationType(location: TS.Location): Promise<boolean> {
@@ -1566,7 +1578,6 @@ export function toFsEntry(path: string, isFile: boolean): TS.FileSystemEntry {
: extractDirectoryName(path, PlatformIO.getDirSeparator()),
isFile,
extension: extractFileExtension(path, PlatformIO.getDirSeparator()),
- description: '',
tags: [],
size: 0,
lmdt: new Date().getTime(),
@@ -1574,7 +1585,7 @@ export function toFsEntry(path: string, isFile: boolean): TS.FileSystemEntry {
};
}
-export function openedToFsEntry(openedEntry: OpenedEntry): TS.FileSystemEntry {
+/*export function openedToFsEntry(openedEntry: TS.OpenedEntry): TS.FileSystemEntry {
return {
uuid: getUuid(),
name: openedEntry.isFile
@@ -1585,13 +1596,13 @@ export function openedToFsEntry(openedEntry: OpenedEntry): TS.FileSystemEntry {
openedEntry.path,
PlatformIO.getDirSeparator(),
),
- description: openedEntry.description,
+ description: openedEntry.meta?.description,
tags: openedEntry.tags,
size: openedEntry.size,
lmdt: openedEntry.lmdt,
path: openedEntry.path,
};
-}
+}*/
export function createFsEntryMeta(
path: string,
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 27c06b054..c25828d49 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -107,6 +107,17 @@ export namespace TS {
open?: boolean;
}
+ interface EditMetaAction {
+ action:
+ | 'perspectiveChange'
+ | 'autoSaveChange'
+ | 'descriptionChange'
+ | 'thumbChange'
+ | 'bgdImgChange'
+ | 'bgdColorChange';
+ entry: TS.FileSystemEntry;
+ }
+
interface Tag {
title?: string;
/**
@@ -148,20 +159,15 @@ export namespace TS {
name: string;
isFile: boolean;
isNewFile?: boolean;
- isAutoSaveEnabled?: boolean; // common with OpenedEntry
+ //isAutoSaveEnabled?: boolean; // common with OpenedEntry
extension?: string;
- thumbPath?: string;
- color?: string;
- perspective?: TS.PerspectiveType;
textContent?: string;
- description?: string;
- tags: Array<TS.Tag>;
+ tags?: TS.Tag[];
size: number;
lmdt: number;
path: string;
url?: string;
meta?: FileSystemEntryMeta;
- // isIgnored?: boolean;
}
interface FileSystemEntryMeta {
@@ -169,10 +175,10 @@ export namespace TS {
description?: string;
isFile?: boolean;
autoSave?: boolean;
- editMode?: boolean;
- shouldReload?: boolean;
+ //shouldReload?: boolean;
tags?: Array<TS.Tag>;
tagGroups?: Array<TS.TagGroup>;
+ thumbPath?: string;
color?: string;
perspective?: TS.PerspectiveType;
appName?: string;
@@ -181,6 +187,17 @@ export namespace TS {
customOrder?: CustomOrder;
perspectiveSettings?: PerspectiveSettings;
}
+
+ interface OpenedEntry extends FileSystemEntry {
+ locationId?: string;
+ viewingExtensionPath: string;
+ viewingExtensionId: string;
+ editingExtensionPath?: string;
+ editingExtensionId?: string;
+ editMode?: boolean;
+ focused?: boolean; // TODO make it mandatory once support for multiple files is added
+ }
+
interface CustomOrder {
folders?: Array<OrderVisibilitySettings>;
files?: Array<OrderVisibilitySettings>;
diff --git a/src/renderer/utils/metaoperations.ts b/src/renderer/utils/metaoperations.ts
index cfe84b3e6..bcc44970b 100644
--- a/src/renderer/utils/metaoperations.ts
+++ b/src/renderer/utils/metaoperations.ts
@@ -5,6 +5,37 @@ import {
} from '-/services/utils-io';
import { TS } from '-/tagspaces.namespace';
+export function saveFsEntryMeta(
+ path: string,
+ meta: any,
+): Promise<TS.FileSystemEntryMeta> {
+ return loadMetaDataPromise(path)
+ .then((fsEntryMeta) => {
+ return saveMetaData(path, {
+ ...fsEntryMeta,
+ ...meta,
+ lastUpdated: new Date().getTime(),
+ });
+ })
+ .catch(() => {
+ return saveMetaData(path, mergeFsEntryMeta(meta));
+ });
+}
+
+function saveMetaData(
+ path: string,
+ fsEntryMeta: TS.FileSystemEntryMeta,
+): Promise<TS.FileSystemEntryMeta> {
+ return saveMetaDataPromise(path, fsEntryMeta)
+ .then(() => {
+ return fsEntryMeta;
+ })
+ .catch((err) => {
+ console.warn('Error saveMetaData for ' + path + ' ', err);
+ return fsEntryMeta;
+ });
+}
+
// eslint-disable-next-line import/prefer-default-export
export function savePerspective(
path: string,