TagSpaces is an offline, open source, document manager with tagging support
fix duplicate gallery
sytolk2528c440fedd
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsxindex 1c07d2e6a..3bb847304 100644--- a/src/renderer/components/LocationView.tsx+++ b/src/renderer/components/LocationView.tsx@@ -81,7 +81,7 @@ function LocationView(props: Props) {const dispatch: AppDispatch = useDispatch();const { location, hideDrawer } = props;- const isCloudLocation = location.type === locationType.TYPE_CLOUD;+ const isCloudLocation = location?.type === locationType.TYPE_CLOUD;const handleLocationIconClick = (event: React.MouseEvent<HTMLSpanElement, MouseEvent>,@@ -180,7 +180,7 @@ function LocationView(props: Props) {};let locationNameTitle = location?.path;- if (isCloudLocation && location.bucketName) {+ if (isCloudLocation && location?.bucketName) {if (location.endpointURL) {locationNameTitle = location.endpointURL + ' - ' + location.bucketName;} else if (location.region) {@@ -281,7 +281,7 @@ function LocationView(props: Props) {</TargetMoveFileBox>)}</ListItemText>- {location.isDefault && (+ {location?.isDefault && (<Tooltip title={t('core:thisIsStartupLocation')}><DefaultLocationIcon data-tid="startupIndication" /></Tooltip>diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex 5ef0ac32d..af2cc5e41 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -781,27 +781,10 @@ export const DirectoryContentContextProvider = ({entries.length > 0 &&!isNotFromCurrentDir //entries[0].path.startsWith(currentDirectoryPath.current)) {- //const currDirEntries = currentDirEntries ? currentDirEntries : currentDirectoryEntries;- if (+ /*if (currentDirectoryEntries.current &¤tDirectoryEntries.current.length > 0) {- /*if (inlineUpdate) {- // inline update currentDirectoryEntries- let isUpdated = false;- for (const oldEntry of currentDirectoryEntries.current) {- const entryUpdated = entries.find(- (updated) => updated.path === oldEntry.path,- );- if (entryUpdated) {- oldEntry.meta = { ...oldEntry.meta, ...entryUpdated.meta };- isUpdated = true;- }- }- if (isUpdated) {- forceUpdate();- }- }*/setCurrentDirectoryEntries(currentDirectoryEntries.current.map((e) => {const eUpdated = entries.filter((u) => u.path === e.path);@@ -814,9 +797,9 @@ export const DirectoryContentContextProvider = ({return e;}),);- } else {- setCurrentDirectoryEntries(entries);- }+ } else {*/+ setCurrentDirectoryEntries(entries);+ // }}}}@@ -1346,11 +1329,10 @@ export const DirectoryContentContextProvider = ({: dirEntries.filter((entry) => entry.isFile);const fileEntriesPromises = getFileEntriesPromises(files, meta);const thumbs = getThumbs(files, meta);- return getEntries([- ...dirEntriesPromises,- ...fileEntriesPromises,- ...thumbs,- ]);+ return getEntries(+ [...dirEntriesPromises, ...fileEntriesPromises, ...thumbs],+ dirEntries,+ );}).catch((ex) => {console.log(ex);@@ -1381,12 +1363,12 @@ export const DirectoryContentContextProvider = ({});}- function getEntries(metaPromises): Promise<TS.FileSystemEntry[]> {+ function getEntries(metaPromises, dirEntries): Promise<TS.FileSystemEntry[]> {// const catchHandler = (error) => undefined;//return Promise.all(metaPromises.map((promise) => promise.catch(catchHandler)))return executePromisesInBatches(metaPromises, 100).then((entries: TS.FileSystemEntry[]) => {- return entries;+ return mergeByPath(entries, dirEntries);}).catch((err) => {console.log('err updateEntries:', err);@@ -1394,6 +1376,40 @@ export const DirectoryContentContextProvider = ({});}+ function buildMetaLookup(+ entriesToMerge: TS.FileSystemEntry[],+ ): Record<string, TS.FileSystemEntryMeta> {+ const metaLookup: Record<string, TS.FileSystemEntryMeta> = {};+ for (const entry of entriesToMerge) {+ const { path, meta } = entry;+ if (!metaLookup[path]) {+ // first time we see this path+ metaLookup[path] = meta;+ }+ // shallow-merge the incoming meta onto our accumulator+ Object.assign(metaLookup[path], meta);+ }+ return metaLookup;+ }++ function mergeByPath(+ entriesToMerge: TS.FileSystemEntry[],+ dirEntries: TS.FileSystemEntry[],+ ): TS.FileSystemEntry[] {+ const lookup = buildMetaLookup(entriesToMerge);++ return dirEntries.map((e) => {+ const extraMeta = lookup[e.path];+ if (extraMeta) {+ return {+ ...e,+ meta: { ...(e.meta || {}), ...extraMeta },+ };+ }+ return e;+ });+ }+function getThumbs(pageFiles: TS.FileSystemEntry[],meta?: Array<any>,diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsxindex d1565c5f4..8fefced3f 100644--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx@@ -757,11 +757,13 @@ export const OpenedEntryContextProvider = ({const locationId = lid ? lid : getFirstRWLocation()?.uuid;getAllPropertiesPromise(entryPath, locationId).then((fsEntry: TS.FileSystemEntry) => {- if (fsEntry.isFile) {- openFsEntry(fsEntry);- setEntryInFullWidth(options.fullWidth);- } else {- openDirectory(fsEntry.path);+ if (fsEntry) {+ if (fsEntry.isFile) {+ openFsEntry(fsEntry);+ setEntryInFullWidth(options.fullWidth);+ } else {+ openDirectory(fsEntry.path);+ }}return true;})diff --git a/src/renderer/hooks/ThumbGenerationContextProvider.tsx b/src/renderer/hooks/ThumbGenerationContextProvider.tsxindex bbed44b35..dd1605467 100644--- a/src/renderer/hooks/ThumbGenerationContextProvider.tsx+++ b/src/renderer/hooks/ThumbGenerationContextProvider.tsx@@ -138,7 +138,8 @@ export const ThumbGenerationContextProvider = ({}, [currentDirectoryPath, page]); //, isMetaFolderExist]);*/useEffect(() => {- if (!firstRender && metaActions && metaActions.length > 0) {+ if (metaActions && metaActions.length > 0) {+ //!firstRender (skip firstRender: if switch from KanBan perspective to Gallery thumbGenerate missing)const entries = [];let genThumbs = false;for (const action of metaActions) {