Skip to content

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

Bug: Use of Metadata Features Prevents Preview of Files (#1770)

Stanimirccb4bf1ebee4
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index 63b0c7c5d..e7a6b7e89 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -165,7 +165,17 @@ function FileMenu(props: Props) {
function setFolderBackground() {
onClose();
- setFolderBackgroundPromise(props.selectedFilePath)
+ let path =
+ PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()
+ ? PlatformIO.getURLforPath(props.selectedFilePath)
+ : props.selectedFilePath;
+
+ const directoryPath = extractContainingDirectoryPath(
+ props.selectedFilePath,
+ PlatformIO.getDirSeparator()
+ );
+
+ setFolderBackgroundPromise(path, directoryPath)
.then((directoryPath: string) => {
props.setLastBackgroundImageChange(new Date().getTime());
showNotification('Background created for: ' + directoryPath);
diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsx
index 44dc97400..149ec578a 100644
--- a/app/perspectives/grid-perspective/components/GridPagination.tsx
+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useEffect, useRef } from 'react';
+import React, { useEffect, useReducer, useRef } from 'react';
import { connect } from 'react-redux';
import { alpha } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
@@ -44,7 +44,8 @@ import {
getCurrentDirectoryTags,
isLoading,
getCurrentDirectoryDescription,
- getLastBackgroundImageChange
+ getLastBackgroundImageChange,
+ getLastThumbnailImageChange
} from '-/reducers/app';
import EntryIcon from '-/components/EntryIcon';
import TagsPreview from '-/components/TagsPreview';
@@ -92,6 +93,7 @@ interface Props {
selectedEntries; // cache only
// setMetaForCurrentDir: (metaFiles: Array<any>) => void;
lastBackgroundImageChange: number;
+ lastThumbnailImageChange: number;
}
function GridPagination(props: Props) {
@@ -107,7 +109,6 @@ function GridPagination(props: Props) {
isAppLoading,
currentDirectoryColor,
currentDirectoryTags,
- currentDirectoryPath,
currentDirectoryDescription,
openRenameEntryDialog,
gridPageLimit,
@@ -124,6 +125,18 @@ function GridPagination(props: Props) {
// const entriesUpdated = useRef([]);
const page = useRef<number>(currentPage);
const metaLoadedLock = useRef<boolean>(false); // TODO move this for all perspectives - not lock if you open folder with diff perspective now
+ const folderTmbPath = useRef<string>(
+ getFolderThumbPath(
+ props.currentDirectoryPath,
+ props.lastThumbnailImageChange
+ )
+ );
+ const folderBgndPath = useRef<string>(
+ getFolderBgndPath(
+ props.currentDirectoryPath,
+ props.lastBackgroundImageChange
+ )
+ );
// const [page, setPage] = useState(currentPage);
let pageFiles;
@@ -133,7 +146,7 @@ function GridPagination(props: Props) {
} else {
pageFiles = files;
}
- // const [, forceUpdate] = useReducer(x => x + 1, 0);
+ const [, forceUpdate] = useReducer(x => x + 1, 0);
useEffect(() => {
if (!props.isMetaLoaded && !metaLoadedLock.current) {
@@ -157,6 +170,22 @@ function GridPagination(props: Props) {
}
}, [page.current, props.isMetaLoaded, files]);
+ 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]);
+
useEffect(() => {
page.current = currentPage;
/* if (page !== currentPage) {
@@ -304,7 +333,7 @@ function GridPagination(props: Props) {
};
const folderName = extractDirectoryName(
- decodeURIComponent(currentDirectoryPath),
+ decodeURIComponent(props.currentDirectoryPath),
PlatformIO.getDirSeparator()
);
@@ -321,32 +350,34 @@ function GridPagination(props: Props) {
return url;
}
- let folderTmbPath = getThumbFileLocationForDirectory(
- currentDirectoryPath,
- PlatformIO.getDirSeparator()
- );
- if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
- folderTmbPath = PlatformIO.getURLforPath(folderTmbPath);
- } else {
- folderTmbPath =
- normalizeUrl(folderTmbPath) +
- (props.lastBackgroundImageChange
- ? '?' + props.lastBackgroundImageChange
- : '');
+ function getFolderThumbPath(path: string, lastThumbnailImageChange: number) {
+ let tmbPath = getThumbFileLocationForDirectory(
+ path,
+ PlatformIO.getDirSeparator()
+ );
+ if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
+ tmbPath = PlatformIO.getURLforPath(tmbPath);
+ } else {
+ tmbPath =
+ normalizeUrl(tmbPath) +
+ (lastThumbnailImageChange ? '?' + lastThumbnailImageChange : '');
+ }
+ return tmbPath;
}
- let folderBgndPath = getBgndFileLocationForDirectory(
- currentDirectoryPath,
- PlatformIO.getDirSeparator()
- );
- if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
- folderBgndPath = PlatformIO.getURLforPath(folderBgndPath);
- } else {
- folderBgndPath =
- normalizeUrl(folderBgndPath) +
- (props.lastBackgroundImageChange
- ? '?' + props.lastBackgroundImageChange
- : '');
+ function getFolderBgndPath(path: string, lastBackgroundImageChange: number) {
+ let bgndPath = getBgndFileLocationForDirectory(
+ path,
+ PlatformIO.getDirSeparator()
+ );
+ if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {
+ bgndPath = PlatformIO.getURLforPath(bgndPath);
+ } else {
+ bgndPath =
+ normalizeUrl(bgndPath) +
+ (lastBackgroundImageChange ? '?' + lastBackgroundImageChange : '');
+ }
+ return bgndPath;
}
const dirColor = currentDirectoryColor || 'transparent';
@@ -357,7 +388,7 @@ function GridPagination(props: Props) {
if (showDescription && currentDirectoryDescription) {
descriptionHTML = convertMarkDown(
currentDirectoryDescription,
- currentDirectoryPath
+ props.currentDirectoryPath
);
}
@@ -369,10 +400,6 @@ function GridPagination(props: Props) {
}
}
- function renderTags(tags: Array<TS.Tag>) {
- return;
- }
-
return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-noninteractive-element-interactions,jsx-a11y/no-static-element-interactions
<div
@@ -393,7 +420,7 @@ function GridPagination(props: Props) {
height: '100%',
// @ts-ignore
overflowY: AppConfig.isFirefox ? 'auto' : 'overlay',
- backgroundImage: 'url("' + folderBgndPath + '")',
+ backgroundImage: 'url("' + folderBgndPath.current + '")',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat'
}}
@@ -487,7 +514,7 @@ function GridPagination(props: Props) {
marginRight: 'auto',
height: 140,
width: 140,
- backgroundImage: 'url("' + folderTmbPath + '")',
+ backgroundImage: 'url("' + folderTmbPath.current + '")',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center center',
@@ -610,7 +637,8 @@ function mapStateToProps(state) {
currentDirectoryTags: getCurrentDirectoryTags(state),
isMetaLoaded: getIsMetaLoaded(state),
currentDirectoryDescription: getCurrentDirectoryDescription(state),
- lastBackgroundImageChange: getLastBackgroundImageChange(state)
+ lastBackgroundImageChange: getLastBackgroundImageChange(state),
+ lastThumbnailImageChange: getLastThumbnailImageChange(state)
};
}
@@ -628,6 +656,7 @@ function mapActionCreatorsToProps(dispatch) {
const areEqual = (prevProp: Props, nextProp: Props) =>
nextProp.theme === prevProp.theme &&
nextProp.lastBackgroundImageChange === prevProp.lastBackgroundImageChange &&
+ nextProp.lastThumbnailImageChange === prevProp.lastThumbnailImageChange &&
nextProp.currentDirectoryPath === prevProp.currentDirectoryPath &&
nextProp.isMetaLoaded === prevProp.isMetaLoaded &&
nextProp.showDirectories === prevProp.showDirectories &&
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index be5a6a592..d2a13f1e5 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -51,7 +51,8 @@ import {
findExtensionsForEntry,
getNextFile,
getPrevFile,
- loadJSONFile
+ loadJSONFile,
+ merge
} from '-/services/utils-io';
import i18n from '../services/i18n';
import { Pro } from '../pro';
@@ -662,19 +663,35 @@ export default (state: any = initialState, action: any) => {
};
} */
case types.UPDATE_CURRENTDIR_ENTRIES: {
- const newDirEntries = [...state.currentDirectoryEntries];
- for (let i = 0; i < newDirEntries.length; i += 1) {
- const dirEntry = action.dirEntries.find(
- entry => entry.path === newDirEntries[i].path
+ if (
+ state.currentDirectoryEntries &&
+ state.currentDirectoryEntries.length > 0
+ ) {
+ const newDirEntries = state.currentDirectoryEntries.map(
+ currentEntry => {
+ const updatedEntries = action.dirEntries.filter(
+ newEntry => newEntry.path === currentEntry.path
+ );
+ if (updatedEntries && updatedEntries.length > 0) {
+ const updatedEntry = updatedEntries.reduce(
+ (prevValue, currentValue) => {
+ return merge(currentValue, prevValue);
+ }
+ );
+ return merge(updatedEntry, currentEntry);
+ }
+ return currentEntry;
+ }
);
- if (dirEntry) {
- newDirEntries[i] = dirEntry;
- }
- }
+ return {
+ ...state,
+ currentDirectoryEntries: newDirEntries
+ };
+ }
return {
...state,
- currentDirectoryEntries: newDirEntries
+ currentDirectoryEntries: action.dirEntries
};
}
case types.UPDATE_CURRENTDIR_ENTRY: {
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index dd77ebf1b..5b366915a 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -1061,14 +1061,13 @@ export function setFolderThumbnailPromise(filePath: string): Promise<string> {
/**
* @param filePath
+ * @param directoryPath
* return Promise<directoryPath> of directory in order to open Folder properties next
*/
-export function setFolderBackgroundPromise(filePath: string): Promise<string> {
- const directoryPath = extractContainingDirectoryPath(
- filePath,
- PlatformIO.getDirSeparator()
- );
-
+export function setFolderBackgroundPromise(
+ filePath: string,
+ directoryPath: string
+): Promise<string> {
const folderBgndPath = getBgndFileLocationForDirectory(
directoryPath,
PlatformIO.getDirSeparator()
@@ -1085,12 +1084,13 @@ export function setFolderBackgroundPromise(filePath: string): Promise<string> {
})
.catch(error => {
console.error('Save to file failed ', error);
- return true;
+ return Promise.reject(error);
});
}
})
.catch(error => {
- console.error('Background generation failed ' + error);
+ console.error('Background generation failed ', error);
+ return Promise.reject(error);
});
}
@@ -1217,3 +1217,17 @@ export function fileNameValidation(fileName): boolean {
}
return true;
}
+
+/**
+ * https://stackoverflow.com/a/71981197/2285631
+ * TODO this not merge with "b" properties that missing in "a"
+ * @param a
+ * @param b
+ */
+export const merge = (a, b) =>
+ Object.fromEntries(
+ Object.entries(a).map(([k, v]) => [
+ k,
+ v && Array.isArray(v) ? [...v, ...b[k]] : v || b[k]
+ ])
+ );