Skip to content

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

Location tags not always loaded (#2109)

Stanimir1e93502ec82d
diff --git a/src/main/electron-menus.ts b/src/main/electron-menus.ts
index 2b87b3cf2..949368cbe 100644
--- a/src/main/electron-menus.ts
+++ b/src/main/electron-menus.ts
@@ -57,15 +57,15 @@ export default function buildDesktopMenu(props: any, i18n) {
{
type: 'separator',
},
- {
- label: i18n.t('print'),
- accelerator: 'CmdOrCtrl+p',
- click: (item, focusedWindow) => {
- if (focusedWindow.webContents && focusedWindow.webContents.print) {
- focusedWindow.webContents.print();
- }
- },
- },
+ // {
+ // label: i18n.t('print'),
+ // accelerator: 'CmdOrCtrl+p',
+ // click: (item, focusedWindow) => {
+ // if (focusedWindow.webContents && focusedWindow.webContents.print) {
+ // focusedWindow.webContents.print();
+ // }
+ // },
+ // },
{
type: 'separator',
},
diff --git a/src/renderer/components/SearchPopover.tsx b/src/renderer/components/SearchPopover.tsx
index 062cac43e..2d4ca24ff 100644
--- a/src/renderer/components/SearchPopover.tsx
+++ b/src/renderer/components/SearchPopover.tsx
@@ -636,7 +636,7 @@ function SearchPopover(props: Props) {
<Tooltip title={t('searchInAllLocationTooltip')}>
<div>{t('globalSearch')}</div>
</Tooltip>
- {Pro ? <BetaLabel /> : <ProLabel />}
+ <ProLabel />
</ToggleButton>
</ToggleButtonGroup>
</FormControl>
diff --git a/src/renderer/components/TagLibrary.tsx b/src/renderer/components/TagLibrary.tsx
index df9bae8a7..9223b692c 100644
--- a/src/renderer/components/TagLibrary.tsx
+++ b/src/renderer/components/TagLibrary.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useCallback, useState } from 'react';
+import React, { useCallback, useEffect, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import classNames from 'classnames';
import Typography from '@mui/material/Typography';
@@ -36,6 +36,7 @@ import TagLibraryMenu from './menus/TagLibraryMenu';
import TagGroupMenu from './menus/TagGroupMenu';
import {
actions as SettingsActions,
+ getSaveTagInLocation,
getTagColor,
getTagGroupCollapsed,
getTagTextColor,
@@ -45,7 +46,7 @@ import SmartTags from '../reducers/smart-tags';
import EditTagDialog from '-/components/dialogs/EditTagDialog';
import { TS } from '-/tagspaces.namespace';
import TagGroupTitleDnD from '-/components/TagGroupTitleDnD';
-import { getAllTags } from '-/services/taglibrary-utils';
+import { getAllTags, getTagLibrary } from '-/services/taglibrary-utils';
import { classes, SidePanel } from '-/components/SidePanels.css';
import { useTranslation } from 'react-i18next';
import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';
@@ -53,6 +54,9 @@ import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';
import { CommonLocation } from '-/utils/CommonLocation';
+import { Pro } from '-/pro';
+import { useTagGroupsLocationContext } from '-/hooks/useTagGroupsLocationContext';
+import useFirstRender from '-/utils/useFirstRender';
interface Props {
style?: any;
@@ -69,10 +73,12 @@ function TagLibrary(props: Props) {
changeTagOrder,
moveTag,
moveTagGroup,
+ importTagGroups,
} = useTaggingActionsContext();
+ const { getTagGroups } = useTagGroupsLocationContext();
const { selectedEntries } = useSelectedEntriesContext();
- const { readOnlyMode, findLocation } = useCurrentLocationContext();
- const { tagGroups } = useEditedTagLibraryContext();
+ const { readOnlyMode, findLocation, locations } = useCurrentLocationContext();
+ const { tagGroups, reflectTagLibraryChanged } = useEditedTagLibraryContext();
const dispatch: AppDispatch = useDispatch();
const tagBackgroundColor = useSelector(getTagColor);
const tagTextColor = useSelector(getTagTextColor);
@@ -103,11 +109,49 @@ function TagLibrary(props: Props) {
useState<boolean>(false);
const [isDeleteTagDialogOpened, setIsDeleteTagDialogOpened] =
useState<boolean>(false);
- // const firstRender = useFirstRender();
+ const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);
+ const firstRender = useFirstRender();
const isTagLibraryReadOnly =
window.ExtTagLibrary && window.ExtTagLibrary.length > 0;
+ useEffect(() => {
+ if (Pro && saveTagInLocation && firstRender) {
+ refreshTagsFromLocation();
+ }
+ }, [saveTagInLocation]);
+
+ function refreshTagsFromLocation() {
+ if (locations && locations.length > 0) {
+ for (const location of locations) {
+ getTagGroups(location).then((locationTagGroups) => {
+ if (locationTagGroups && locationTagGroups.length > 0) {
+ const oldGroups = getTagLibrary();
+ if (checkTagGroupModified(locationTagGroups, oldGroups)) {
+ importTagGroups(locationTagGroups, false, location);
+ } else {
+ // refresh if localStorage is changed - from new instance
+ reflectTagLibraryChanged(oldGroups);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ function checkTagGroupModified(
+ newGroups: Array<TS.TagGroup>,
+ oldGroups: Array<TS.TagGroup>,
+ ) {
+ return !newGroups.every((newGroup) =>
+ oldGroups.some(
+ (oldGroup) =>
+ newGroup.uuid === oldGroup.uuid &&
+ newGroup.modified_date <= oldGroup.modified_date,
+ ),
+ );
+ }
+
const handleTagGroupMenu = (
event: React.ChangeEvent<HTMLInputElement>,
tagGroup,
@@ -355,6 +399,7 @@ function TagLibrary(props: Props) {
open={Boolean(tagLibraryMenuAnchorEl)}
onClose={() => setTagLibraryMenuAnchorEl(null)}
showCreateTagGroupDialog={showCreateTagGroupDialog}
+ refreshTagsFromLocation={refreshTagsFromLocation}
/>
{Boolean(tagMenuAnchorEl) && (
<TagMenu
diff --git a/src/renderer/components/dialogs/EditTagGroupDialog.tsx b/src/renderer/components/dialogs/EditTagGroupDialog.tsx
index 0e04af0d6..4beccba72 100644
--- a/src/renderer/components/dialogs/EditTagGroupDialog.tsx
+++ b/src/renderer/components/dialogs/EditTagGroupDialog.tsx
@@ -117,6 +117,7 @@ function EditTagGroupDialog(props: Props) {
color,
textcolor,
locationId,
+ modified_date: new Date().getTime(),
children: selectedTagGroupEntry.children.map((tag) => ({
...tag,
color: applyChanges ? color : tag.color,
diff --git a/src/renderer/components/menus/TagLibraryMenu.tsx b/src/renderer/components/menus/TagLibraryMenu.tsx
index ed3c1a024..edd81fd22 100644
--- a/src/renderer/components/menus/TagLibraryMenu.tsx
+++ b/src/renderer/components/menus/TagLibraryMenu.tsx
@@ -44,13 +44,13 @@ interface Props {
open: boolean;
onClose: () => void;
showCreateTagGroupDialog: () => void;
+ refreshTagsFromLocation: () => void;
}
function TagLibraryMenu(props: Props) {
const { t } = useTranslation();
const { showNotification } = useNotificationContext();
const { tagGroups } = useEditedTagLibraryContext();
- const { refreshTagsFromLocation } = useTaggingActionsContext();
const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);
const fileInput = useRef<HTMLInputElement>(null);
@@ -132,7 +132,7 @@ function TagLibraryMenu(props: Props) {
disabled={!Pro || !saveTagInLocation}
data-tid="refreshTagGroups"
onClick={() => {
- refreshTagsFromLocation();
+ props.refreshTagsFromLocation();
props.onClose();
}}
>
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index c0d96a949..e7e794de0 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -1630,9 +1630,7 @@ export const IOActionsContextProvider = ({
return true;
})
.catch((err) => {
- console.log(
- 'Error adding perspective for ' + path + ' with ' + err,
- );
+ console.log('Error ' + path + ' with ' + err);
reject();
});
return true;
@@ -1649,9 +1647,7 @@ export const IOActionsContextProvider = ({
return true;
})
.catch((error) => {
- console.log(
- 'Error adding perspective for ' + path + ' with ' + error,
- );
+ console.log('Error ' + path + ' with ' + error);
reject();
});
});
diff --git a/src/renderer/hooks/PlatformFacadeContextProvider.tsx b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
index 904c44790..9c32b3cfe 100644
--- a/src/renderer/hooks/PlatformFacadeContextProvider.tsx
+++ b/src/renderer/hooks/PlatformFacadeContextProvider.tsx
@@ -168,7 +168,8 @@ export const PlatformFacadeContextProvider = ({
reflectDeleteEntries,
setReflectActions,
} = useEditedEntryContext();
- const { currentLocation, findLocation } = useCurrentLocationContext();
+ const { currentLocation, locations, findLocation } =
+ useCurrentLocationContext();
const { getAllPropertiesPromise } = useDirectoryContentContext();
const { ignoreByWatcher, deignoreByWatcher, ignored } = useFSWatcherContext(); //watcher
@@ -734,7 +735,7 @@ export const PlatformFacadeContextProvider = ({
deleteEntriesPromise,
setFolderThumbnailPromise,
};
- }, [ignored, currentLocation]); //watcher
+ }, [ignored, currentLocation, locations]); //watcher
return (
<PlatformFacadeContext.Provider value={context}>
diff --git a/src/renderer/hooks/TagGroupsLocationContextProvider.tsx b/src/renderer/hooks/TagGroupsLocationContextProvider.tsx
index dc664d3cd..ced999f0f 100644
--- a/src/renderer/hooks/TagGroupsLocationContextProvider.tsx
+++ b/src/renderer/hooks/TagGroupsLocationContextProvider.tsx
@@ -228,12 +228,7 @@ export const TagGroupsLocationContextProvider = ({
return true;
})
.catch((err) => {
- console.log(
- 'Error adding perspective for ' +
- location.path +
- ' with ' +
- err,
- );
+ console.log('Error ' + location.path + ' with ' + err);
reject();
});
return true;
@@ -248,12 +243,7 @@ export const TagGroupsLocationContextProvider = ({
return true;
})
.catch((error) => {
- console.log(
- 'Error adding perspective for ' +
- location.path +
- ' with ' +
- error,
- );
+ console.log('Error ' + location.path + ' with ' + error);
reject();
});
});
@@ -270,27 +260,27 @@ export const TagGroupsLocationContextProvider = ({
return new Promise((resolve, reject) => {
loadLocationDataPromise(location)
.then((fsEntryMeta: TS.FileSystemEntryMeta) => {
- const tagGroups = fsEntryMeta.tagGroups.filter(
- (group) => group.uuid !== tagGroupUuid,
- );
- const updatedEntryMeta: TS.FileSystemEntryMeta = {
- ...fsEntryMeta,
- tagGroups,
- };
- saveLocationDataPromise(location, updatedEntryMeta)
- .then(() => {
- resolve(updatedEntryMeta);
- return true;
- })
- .catch((err) => {
- console.log(
- 'Error adding perspective for ' +
- location.path +
- ' with ' +
- err,
- );
- reject();
- });
+ if (fsEntryMeta) {
+ const tagGroups = fsEntryMeta.tagGroups?.filter(
+ (group) => group.uuid !== tagGroupUuid,
+ );
+ if (tagGroups) {
+ const updatedEntryMeta: TS.FileSystemEntryMeta = {
+ ...fsEntryMeta,
+ tagGroups,
+ };
+ return saveLocationDataPromise(location, updatedEntryMeta)
+ .then(() => {
+ resolve(updatedEntryMeta);
+ return true;
+ })
+ .catch((err) => {
+ console.log('Error ' + location.path + ' with ' + err);
+ reject();
+ return false;
+ });
+ }
+ }
return true;
})
.catch((err) => {
@@ -329,12 +319,7 @@ export const TagGroupsLocationContextProvider = ({
return true;
})
.catch((err) => {
- console.log(
- 'Error adding perspective for ' +
- location.path +
- ' with ' +
- err,
- );
+ console.log('Error ' + location.path + ' with ' + err);
reject();
});
return true;
@@ -349,12 +334,7 @@ export const TagGroupsLocationContextProvider = ({
return true;
})
.catch((error) => {
- console.log(
- 'Error adding perspective for ' +
- location.path +
- ' with ' +
- error,
- );
+ console.log('Error ' + location.path + ' with ' + error);
reject();
});
});
diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsx
index 2234fd448..50fc9887d 100644
--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx
+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx
@@ -105,9 +105,12 @@ type TaggingActionsContextData = {
moveTagGroupDown: (parentTagGroupUuid: TS.Uuid) => void;
moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => void;
sortTagGroup: (parentTagGroupUuid: TS.Uuid) => void;
- updateTagGroup: (tg: TS.TagGroup) => void;
- importTagGroups: (newEntries: Array<TS.TagGroup>, replace?: boolean) => void;
- refreshTagsFromLocation: () => void;
+ updateTagGroup: (tg: TS.TagGroup, replaceTags?: boolean) => void;
+ importTagGroups: (
+ newEntries: Array<TS.TagGroup>,
+ replace?: boolean,
+ location?: CommonLocation,
+ ) => void;
};
export const TaggingActionsContext = createContext<TaggingActionsContextData>({
@@ -134,7 +137,6 @@ export const TaggingActionsContext = createContext<TaggingActionsContextData>({
sortTagGroup: undefined,
updateTagGroup: undefined,
importTagGroups: undefined,
- refreshTagsFromLocation: undefined,
});
export type TaggingActionsContextProviderProps = {
@@ -149,7 +151,6 @@ export const TaggingActionsContextProvider = ({
useCurrentLocationContext();
const { tagGroups, reflectTagLibraryChanged } = useEditedTagLibraryContext();
const {
- getTagGroups,
createLocationTagGroup,
editLocationTagGroup,
removeLocationTagGroup,
@@ -172,36 +173,6 @@ export const TaggingActionsContextProvider = ({
//const locations: CommonLocation[] = useSelector(getLocations);
const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);
- useEffect(() => {
- if (Pro && saveTagInLocation) {
- refreshTagsFromLocation();
- }
- }, [saveTagInLocation, currentLocation]);
-
- function refreshTagsFromLocation() {
- if (currentLocation) {
- getTagGroups(currentLocation).then((locationTagGroups) => {
- if (locationTagGroups && locationTagGroups.length > 0) {
- const oldGroups = getTagLibrary();
- if (checkTagGroupModified(locationTagGroups, oldGroups)) {
- importTagGroups(locationTagGroups, false);
- }
- }
- });
- }
- }
-
- function checkTagGroupModified(
- newGroups: Array<TS.TagGroup>,
- oldGroups: Array<TS.TagGroup>,
- ) {
- return !oldGroups.some((group) =>
- newGroups.some(
- (newGroup) => newGroup.modified_date === group.modified_date,
- ),
- );
- }
-
function extractContent(
options: extractOptions = {
EXIFGeo: true,
@@ -1059,7 +1030,7 @@ export const TaggingActionsContextProvider = ({
}
}
- function updateTagGroup(entry: TS.TagGroup) {
+ function updateTagGroup(entry: TS.TagGroup, replaceTags = false) {
let indexForEditing = tagGroups.findIndex(
(tagGroup) => tagGroup.uuid === entry.uuid,
);
@@ -1070,11 +1041,10 @@ export const TaggingActionsContextProvider = ({
...(!entry.created_date && { created_date: new Date().getTime() }),
...(!entry.modified_date && { modified_date: new Date().getTime() }),
};
-
if (Pro && entry.locationId) {
const location: CommonLocation = findLocation(entry.locationId);
if (location) {
- editLocationTagGroup(location, modifiedEntry);
+ editLocationTagGroup(location, modifiedEntry, replaceTags);
}
}
@@ -1246,14 +1216,7 @@ export const TaggingActionsContextProvider = ({
return t;
}),
};
-
- if (Pro && tagGroup && tagGroup.locationId) {
- const location: CommonLocation = findLocation(tagGroup.locationId);
- if (location) {
- editLocationTagGroup(location, newTagGroup, true);
- }
- }
- updateTagGroup(newTagGroup);
+ updateTagGroup(newTagGroup, true);
}
}
@@ -1275,13 +1238,7 @@ export const TaggingActionsContextProvider = ({
],
};
- if (Pro && tagGroup.locationId) {
- const location: CommonLocation = findLocation(tagGroup.locationId);
- if (location) {
- editLocationTagGroup(location, editedTagGroup, true);
- }
- }
- updateTagGroup(editedTagGroup);
+ updateTagGroup(editedTagGroup, true);
}
}
@@ -1409,8 +1366,12 @@ export const TaggingActionsContextProvider = ({
}
}
- function importTagGroups(newEntries: Array<TS.TagGroup>, replace = false) {
- const arr = replace ? [] : [...tagGroups];
+ function importTagGroups(
+ newEntries: Array<TS.TagGroup>,
+ replace = false,
+ location: CommonLocation = undefined,
+ ) {
+ let arr = replace ? [] : [...tagGroups];
// console.log(arr);
// @ts-ignore
if (newEntries[0] && newEntries[0].key) {
@@ -1420,6 +1381,7 @@ export const TaggingActionsContextProvider = ({
// @ts-ignore
if (newTg.key === tagGroups.uuid || newTg.key !== tagGroups.uuid) {
newTg = {
+ ...(location && { locationId: location.uuid }),
title: newTg.title,
// @ts-ignore
uuid: newTg.key,
@@ -1435,7 +1397,23 @@ export const TaggingActionsContextProvider = ({
});
} else {
newEntries.forEach((tagGroup) => {
- const index = arr.findIndex((obj) => obj.uuid === tagGroup.uuid);
+ const exist = arr.some((obj) => obj.uuid === tagGroup.uuid);
+ if (exist) {
+ arr = arr.map((tGroup) => {
+ if (tGroup.uuid === tagGroup.uuid) {
+ return tagGroup;
+ }
+ return tGroup;
+ });
+ } else {
+ arr.push({
+ ...tagGroup,
+ ...(location && {
+ locationId: location.uuid,
+ }),
+ });
+ }
+ /*const index = arr.findIndex((obj) => obj.uuid === tagGroup.uuid);
if (index > -1) {
tagGroup.children.forEach((tag) => {
const stateTag = arr[index].children.find(
@@ -1449,8 +1427,13 @@ export const TaggingActionsContextProvider = ({
arr[index].locationId = tagGroup.locationId;
}
} else {
- arr.push(tagGroup);
- }
+ arr.push({
+ ...tagGroup,
+ ...(location && {
+ locationId: location.uuid,
+ }),
+ });
+ }*/
});
}
@@ -1482,7 +1465,6 @@ export const TaggingActionsContextProvider = ({
sortTagGroup,
updateTagGroup,
importTagGroups,
- refreshTagsFromLocation,
};
}, [
tagGroups,