TagSpaces is an offline, open source, document manager with tagging support
Rewrite methods in utils to not use platform io methods direct v2 (#2072)
Stanimira557ea912f25
diff --git a/package-lock.json b/package-lock.jsonindex 2452254ef..fe0e49a96 100644--- a/package-lock.json+++ b/package-lock.json@@ -197,7 +197,7 @@"yarn": "please-use-npm"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.29"+ "@tagspacespro/tagspacespro": "5.0.30-alpha.1"}},"node_modules/@aashutoshrathi/word-wrap": {@@ -13596,9 +13596,9 @@}},"node_modules/@tagspacespro/tagspacespro": {- "version": "5.0.29",- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.29/b9e614e8df15659036600969f73f8cbdae418aa4",- "integrity": "sha512-TSQOX3gV+FnmnZiVVd75NWmiFK3TyH06aoloEdw+IIiHZ3ot2QRONcfGNArtESIykzeh7JAEScg1ETc9TDwzkw==",+ "version": "5.0.30-alpha.1",+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.30-alpha.1/526234fed61633aa4870be5634d6227dd1b6037c",+ "integrity": "sha512-SriOsNXnDcxX7kufENYf85gvH73jKw4PAETKhx/XF3AdDNneRITEzpqMrtn6cz1UkN7AKwjwnVPIqlMqBxAifw==","license": "Proprietary","optional": true},@@ -59235,9 +59235,9 @@}},"@tagspacespro/tagspacespro": {- "version": "5.0.29",- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.29/b9e614e8df15659036600969f73f8cbdae418aa4",- "integrity": "sha512-TSQOX3gV+FnmnZiVVd75NWmiFK3TyH06aoloEdw+IIiHZ3ot2QRONcfGNArtESIykzeh7JAEScg1ETc9TDwzkw==",+ "version": "5.0.30-alpha.1",+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.30-alpha.1/526234fed61633aa4870be5634d6227dd1b6037c",+ "integrity": "sha512-SriOsNXnDcxX7kufENYf85gvH73jKw4PAETKhx/XF3AdDNneRITEzpqMrtn6cz1UkN7AKwjwnVPIqlMqBxAifw==","optional": true},"@teamsupercell/typings-for-css-modules-loader": {diff --git a/package.json b/package.jsonindex 87a4b461d..7363087f8 100644--- a/package.json+++ b/package.json@@ -228,7 +228,7 @@"uuid": "^9.0.0"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.29"+ "@tagspacespro/tagspacespro": "5.0.30-alpha.1"},"devDependencies": {"@electron/notarize": "^2.2.0",diff --git a/release/app/package.json b/release/app/package.jsonindex 547b43f40..4f4d44e12 100644--- a/release/app/package.json+++ b/release/app/package.json@@ -18,7 +18,7 @@},"dependencies": {"@elife/pm2": "3.6.1",- "@tagspaces/extensions": "1.0.103",+ "@tagspaces/extensions": "1.0.102","@tagspaces/tagspaces-common-node": "4.2.4","@tagspaces/tagspaces-ws": "4.2.4","sharp": "0.32.6",diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsxindex 9408fb949..0020e3317 100644--- a/src/renderer/components/EntryContainer.tsx+++ b/src/renderer/components/EntryContainer.tsx@@ -69,7 +69,7 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';import { getRelativeEntryPath, toFsEntry } from '-/services/utils-io';import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';import { SaveIcon, EditIcon } from '-/components/CommonIcons';-import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';+import { useIOActionsContext } from '-/hooks/useIOActionsContext';const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};@@ -86,7 +86,7 @@ function EntryContainer() {addToEntryContainer,} = useOpenedEntryContext();const { saveDescription, description } = useDescriptionContext();- const { setAutoSave } = useEditedEntryMetaContext();+ const { setAutoSave, getMetadataID } = useIOActionsContext();const { readOnlyMode, switchLocationTypeByID, switchCurrentLocationType } =useCurrentLocationContext();const { openDirectory, currentDirectoryPath, currentLocationPath } =@@ -510,10 +510,7 @@ function EntryContainer() {// @ts-ignoreconst textContent = fileViewer.current.contentWindow.getContent();if (Pro && revisionsEnabled) {- const id = await Pro.MetaOperations.getMetadataID(- fileOpen.path,- fileOpen.uuid,- );+ const id = await getMetadataID(fileOpen.path, fileOpen.uuid);const targetPath = getBackupFileLocation(fileOpen.path,id,diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsxindex d23cbd6cf..16ebaa364 100644--- a/src/renderer/components/EntryProperties.tsx+++ b/src/renderer/components/EntryProperties.tsx@@ -229,14 +229,16 @@ function EntryProperties(props: Props) {const theme = useTheme();const { openedEntry, sharingLink, getOpenedDirProps } =useOpenedEntryContext();- const { renameDirectory, renameFile } = useIOActionsContext();- const { setBackgroundColorChange, saveDirectoryPerspective } =- useEditedEntryMetaContext();+ const {+ renameDirectory,+ renameFile,+ setBackgroundColorChange,+ saveDirectoryPerspective,+ } = useIOActionsContext();const { addTags, removeTags, removeAllTags } = useTaggingActionsContext();const { switchLocationTypeByID, switchCurrentLocationType, readOnlyMode } =useCurrentLocationContext();const { showNotification } = useNotificationContext();- const { ignoreByWatcher, deignoreByWatcher } = useFSWatcherContext();const dirProps = useRef<TS.DirProp>(undefined);const fileNameRef = useRef<HTMLInputElement>(null);@@ -293,25 +295,23 @@ function EntryProperties(props: Props) {);const nextPath = path + PlatformIO.getDirSeparator() + editName;- switchLocationTypeByID(openedEntry.locationId).then(- (currentLocationId) => {- if (openedEntry.isFile) {- renameFile(openedEntry.path, nextPath)- .then(() => switchCurrentLocationType())- .catch(() => {- switchCurrentLocationType();- fileNameRef.current.value = entryName;- });- } else {- renameDirectory(openedEntry.path, editName)- .then((newDirPath) => switchCurrentLocationType())- .catch(() => {- switchCurrentLocationType();- fileNameRef.current.value = entryName;- });- }- },- );+ switchLocationTypeByID(openedEntry.locationId).then(() => {+ if (openedEntry.isFile) {+ renameFile(openedEntry.path, nextPath)+ .then(() => switchCurrentLocationType())+ .catch(() => {+ switchCurrentLocationType();+ fileNameRef.current.value = entryName;+ });+ } else {+ renameDirectory(openedEntry.path, editName)+ .then((newDirPath) => switchCurrentLocationType())+ .catch(() => {+ switchCurrentLocationType();+ fileNameRef.current.value = entryName;+ });+ }+ });setEditName(undefined);}@@ -416,14 +416,8 @@ function EntryProperties(props: Props) {};const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {- const metaFilePath = getMetaFileLocationForFile(- openedEntry.path,- PlatformIO.getDirSeparator(),- );- // tmp fix; saving meta sidecar file is not ignored by watcher- ignoreByWatcher(metaFilePath);switchLocationTypeByID(openedEntry.locationId)- .then((currentLocationId) => {+ .then(() => {if (action === 'remove-value') {if (!value) {// no tags left in the select element@@ -450,7 +444,7 @@ function EntryProperties(props: Props) {return addTags([openedEntry.path], tags);}).then(() => {- switchCurrentLocationType().then(() => deignoreByWatcher(metaFilePath));+ switchCurrentLocationType();});};diff --git a/src/renderer/components/Revisions.tsx b/src/renderer/components/Revisions.tsxindex ce43404e6..fe2e3f9ee 100644--- a/src/renderer/components/Revisions.tsx+++ b/src/renderer/components/Revisions.tsx@@ -47,6 +47,7 @@ import { useTranslation } from 'react-i18next';import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';+import { useIOActionsContext } from '-/hooks/useIOActionsContext';const initialRowsPerPage = 10;@@ -54,6 +55,7 @@ function Revisions() {const { t } = useTranslation();const { switchLocationTypeByID, switchCurrentLocationType } =useCurrentLocationContext();+ const { getMetadataID } = useIOActionsContext();const { openedEntry } = useOpenedEntryContext();const { copyFilePromiseOverwrite } = usePlatformFacadeContext();const [rows, setRows] = useState<Array<TS.FileSystemEntry>>([]);@@ -78,34 +80,30 @@ function Revisions() {function loadHistoryItems(openedFile: TS.OpenedEntry) {if (Pro) {- Pro.MetaOperations.getMetadataID(openedFile.path, openedFile.uuid).then(- (id) => {- openedFile.uuid = id;- const backupFilePath = getBackupFileLocation(- openedFile.path,- openedFile.uuid,- PlatformIO.getDirSeparator(),- );- const backupPath = extractContainingDirectoryPath(- backupFilePath,- PlatformIO.getDirSeparator(),- );- switchLocationTypeByID(openedFile.locationId)- .then(() => {- PlatformIO.listDirectoryPromise(backupPath, []).then((h) => {- setRows(- h.sort((a, b) =>- getLmdt(a.name) < getLmdt(b.name) ? 1 : -1,- ),- );- return switchCurrentLocationType();- });- })- .catch(() => {+ getMetadataID(openedFile.path, openedFile.uuid).then((id) => {+ openedFile.uuid = id;+ const backupFilePath = getBackupFileLocation(+ openedFile.path,+ openedFile.uuid,+ PlatformIO.getDirSeparator(),+ );+ const backupPath = extractContainingDirectoryPath(+ backupFilePath,+ PlatformIO.getDirSeparator(),+ );+ switchLocationTypeByID(openedFile.locationId)+ .then(() => {+ PlatformIO.listDirectoryPromise(backupPath, []).then((h) => {+ setRows(+ h.sort((a, b) => (getLmdt(a.name) < getLmdt(b.name) ? 1 : -1)),+ );return switchCurrentLocationType();});- },- );+ })+ .catch(() => {+ return switchCurrentLocationType();+ });+ });}}diff --git a/src/renderer/components/TagLibrary.tsx b/src/renderer/components/TagLibrary.tsxindex e5ea25372..ce089f599 100644--- a/src/renderer/components/TagLibrary.tsx+++ b/src/renderer/components/TagLibrary.tsx@@ -16,7 +16,7 @@**/-import React, { useCallback, useEffect, useRef, useState } from 'react';+import React, { useCallback, useState } from 'react';import { useSelector, useDispatch } from 'react-redux';import classNames from 'classnames';import Typography from '@mui/material/Typography';@@ -36,41 +36,23 @@ import TagLibraryMenu from './menus/TagLibraryMenu';import TagGroupMenu from './menus/TagGroupMenu';import {actions as SettingsActions,- getSaveTagInLocation,getTagColor,getTagGroupCollapsed,getTagTextColor,} from '../reducers/settings';-import { AppDispatch, isTagLibraryChanged } from '-/reducers/app';+import { AppDispatch } from '-/reducers/app';import SmartTags from '../reducers/smart-tags';import EditTagDialog from '-/components/dialogs/EditTagDialog';import { TS } from '-/tagspaces.namespace';import { getLocations } from '-/reducers/locations';-import { Pro } from '-/pro';import TagGroupTitleDnD from '-/components/TagGroupTitleDnD';-import {- addTag,- changeTagOrder,- createTagGroup,- deleteTag,- editTag,- editTagGroup,- getAllTags,- getTagLibrary,- importTagGroups,- moveTag,- moveTagGroup,- moveTagGroupDown,- moveTagGroupUp,- removeTagGroup,- sortTagGroup,-} from '-/services/taglibrary-utils';-import useFirstRender from '-/utils/useFirstRender';+import { getAllTags } from '-/services/taglibrary-utils';import { classes, SidePanel } from '-/components/SidePanels.css';import { useTranslation } from 'react-i18next';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';+import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';interface Props {style?: any;@@ -79,25 +61,28 @@ interface Props {function TagLibrary(props: Props) {const { t } = useTranslation();- const { addTags } = useTaggingActionsContext();+ const {+ addTags,+ createTagGroup,+ removeTagGroup,+ deleteTag,+ changeTagOrder,+ importTagGroups,+ moveTag,+ moveTagGroup,+ } = useTaggingActionsContext();const { selectedEntries } = useSelectedEntriesContext();const { switchLocationTypeByID, switchCurrentLocationType, readOnlyMode } =useCurrentLocationContext();+ const { tagGroups } = useEditedTagLibraryContext();const dispatch: AppDispatch = useDispatch();const tagBackgroundColor = useSelector(getTagColor);const tagTextColor = useSelector(getTagTextColor);const tagGroupCollapsed: Array<string> = useSelector(getTagGroupCollapsed);const locations: Array<TS.Location> = useSelector(getLocations);- const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);- const tagLibraryChanged = useSelector(isTagLibraryChanged);const toggleTagGroupDispatch = (uuid) =>dispatch(SettingsActions.toggleTagGroup(uuid));-- const [tagGroups, setTagGroups] =- useState<Array<TS.TagGroup>>(getTagLibrary());- // const tagLibrary: Array<TS.TagGroup> = getTagLibrary();- //const tagContainerRef = useRef<HTMLSpanElement>(null);const [tagGroupMenuAnchorEl, setTagGroupMenuAnchorEl] =useState<null | HTMLElement>(null);const [tagMenuAnchorEl, setTagMenuAnchorEl] = useState<null | HTMLElement>(@@ -107,7 +92,6 @@ function TagLibrary(props: Props) {useState<null | HTMLElement>(null);const [selectedTagGroupEntry, setSelectedTagGroupEntry] =useState<TS.TagGroup>(null);- // const [selectedTagEntry, setSelectedTagEntry] = useState<TagGroup>(null);const [selectedTag, setSelectedTag] = useState<TS.Tag>(null);const [isCreateTagGroupDialogOpened, setIsCreateTagGroupDialogOpened] =useState<boolean>(false);@@ -121,60 +105,7 @@ function TagLibrary(props: Props) {useState<boolean>(false);const [isDeleteTagDialogOpened, setIsDeleteTagDialogOpened] =useState<boolean>(false);- const firstRender = useFirstRender();-- useEffect(() => {- if (Pro && saveTagInLocation) {- refreshTagsFromLocation();- }- }, []);-- useEffect(() => {- if (!firstRender) {- setTagGroups(getTagLibrary());- }- }, [tagLibraryChanged]);-- const refreshTagsFromLocation = () => {- locations.map((location) =>- Pro.MetaOperations.getTagGroups(location.path)- .then((tg: Array<TS.TagGroup>) => {- if (tg && tg.length > 0) {- const newGroups = tg.map((group) => ({- ...group,- locationId: location.uuid,- }));- const oldGroups = getTagLibrary();- if (checkTagGroupModified(location.uuid, newGroups, oldGroups)) {- setTagGroups(importTagGroups(newGroups, oldGroups, false));- }- } /*else {- setTagGroups(getTagLibrary());- }*/- return true;- })- .catch((err) => {- console.log(err);- }),- );- };-- function checkTagGroupModified(- locationId: string,- newGroups: Array<TS.TagGroup>,- oldGroups: Array<TS.TagGroup>,- ) {- if (!oldGroups.some((group) => group.locationId === locationId)) {- return true;- }- return !oldGroups.some((group) =>- newGroups.some(- (newGroup) =>- newGroup.modified_date === group.modified_date &&- newGroup.locationId === group.locationId,- ),- );- }+ // const firstRender = useFirstRender();const isTagLibraryReadOnly =window.ExtTagLibrary && window.ExtTagLibrary.length > 0;@@ -259,7 +190,7 @@ function TagLibrary(props: Props) {index={index}tagGroup={tagGroup}moveTagGroup={(tagGroupUuid, position) => {- setTagGroups(moveTagGroup(tagGroupUuid, position, tagGroups));+ moveTagGroup(tagGroupUuid, position);}}handleTagGroupMenu={handleTagGroupMenu}toggleTagGroup={toggleTagGroupDispatch}@@ -307,30 +238,12 @@ function TagLibrary(props: Props) {tagTitle: string,fromTagGroupId: TS.Uuid,toTagGroupId: TS.Uuid,- ) =>- setTagGroups(- moveTag(- tagTitle,- fromTagGroupId,- toTagGroupId,- tagGroups,- ),- )- }+ ) => moveTag(tagTitle, fromTagGroupId, toTagGroupId)}changeTagOrder={(tagGroupUuid: TS.Uuid,fromIndex: number,toIndex: number,- ) =>- setTagGroups(- changeTagOrder(- tagGroupUuid,- fromIndex,- toIndex,- tagGroups,- ),- )- }+ ) => changeTagOrder(tagGroupUuid, fromIndex, toIndex)}selectedEntries={selectedEntries}/>);@@ -343,14 +256,7 @@ function TagLibrary(props: Props) {function confirmDeleteTag() {if (selectedTag && selectedTagGroupEntry) {- setTagGroups(- deleteTag(- selectedTag.title,- selectedTagGroupEntry.uuid,- tagGroups,- locations,- ),- );+ deleteTag(selectedTag.title, selectedTagGroupEntry.uuid);}}@@ -398,13 +304,7 @@ function TagLibrary(props: Props) {})}confirmCallback={(result) => {if (result && selectedTagGroupEntry) {- setTagGroups(- removeTagGroup(- selectedTagGroupEntry.uuid,- tagGroups,- locations,- ),- );+ removeTagGroup(selectedTagGroupEntry.uuid);}}}cancelDialogTID="cancelDeleteTagGroupDialog"@@ -420,14 +320,12 @@ function TagLibrary(props: Props) {(l) => l.uuid === entry.locationId,);if (location) {- switchLocationTypeByID(location.uuid).then(- (currentLocationId) => {- setTagGroups(createTagGroup(entry, tagGroups, location));- switchCurrentLocationType();- },- );+ switchLocationTypeByID(location.uuid).then(() => {+ createTagGroup(entry, location);+ switchCurrentLocationType();+ });} else {- setTagGroups(createTagGroup(entry, tagGroups));+ createTagGroup(entry);}}}color={tagBackgroundColor}@@ -438,9 +336,6 @@ function TagLibrary(props: Props) {<CreateTagsDialogopen={isCreateTagDialogOpened}onClose={() => setIsCreateTagDialogOpened(false)}- addTag={(tag: any, parentTagGroupUuid: TS.Uuid) =>- setTagGroups(addTag(tag, parentTagGroupUuid, tagGroups, locations))- }selectedTagGroupEntry={selectedTagGroupEntry}/>)}@@ -448,9 +343,6 @@ function TagLibrary(props: Props) {<EditTagGroupDialogopen={isEditTagGroupDialogOpened}onClose={() => setIsEditTagGroupDialogOpened(false)}- editTagGroup={(entry: TS.TagGroup) =>- setTagGroups(editTagGroup(entry, tagGroups, locations))- }selectedTagGroupEntry={selectedTagGroupEntry}/>)}@@ -464,28 +356,13 @@ function TagLibrary(props: Props) {showDeleteTagGroupDialog={showDeleteTagGroupDialog}handleCloseTagGroupMenu={() => setTagGroupMenuAnchorEl(null)}showEditTagGroupDialog={showEditTagGroupDialog}- moveTagGroupUp={(parentTagGroupUuid) =>- setTagGroups(moveTagGroupUp(parentTagGroupUuid, tagGroups))- }- moveTagGroupDown={(parentTagGroupUuid) =>- setTagGroups(moveTagGroupDown(parentTagGroupUuid, tagGroups))- }- sortTagGroup={(parentTagGroupUuid) =>- setTagGroups(sortTagGroup(parentTagGroupUuid, tagGroups))- }/>)}<TagLibraryMenuanchorEl={tagLibraryMenuAnchorEl}open={Boolean(tagLibraryMenuAnchorEl)}onClose={() => setTagLibraryMenuAnchorEl(null)}- tagGroups={tagGroups}- importTagGroups={(newGroups, replace) =>- setTagGroups(importTagGroups(newGroups, tagGroups, replace))- }showCreateTagGroupDialog={showCreateTagGroupDialog}- saveTagInLocation={saveTagInLocation}- refreshTagsFromLocation={refreshTagsFromLocation}/>{Boolean(tagMenuAnchorEl) && (<TagMenu@@ -502,15 +379,6 @@ function TagLibrary(props: Props) {<EditTagDialogopen={isEditTagDialogOpened}onClose={() => setIsEditTagDialogOpened(false)}- editTag={(- tag: TS.Tag,- parentTagGroupUuid: TS.Uuid,- origTitle: string,- ) =>- setTagGroups(- editTag(tag, parentTagGroupUuid, origTitle, tagGroups, locations),- )- }selectedTagGroupEntry={selectedTagGroupEntry}selectedTag={selectedTag}/>diff --git a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsxindex 0450c699b..d8d3fbf16 100644--- a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx+++ b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx@@ -58,7 +58,6 @@ function AddRemoveTagsDialog(props: Props) {const { selectedEntries } = useSelectedEntriesContext();const selected = props.selected ? props.selected : selectedEntries;const { addTags, removeTags, removeAllTags } = useTaggingActionsContext();- const { ignoreByWatcher, deignoreByWatcher } = useFSWatcherContext();const [newlyAddedTags, setNewlyAddedTags] = useState<Array<TS.Tag>>([]);const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {@@ -84,14 +83,7 @@ function AddRemoveTagsDialog(props: Props) {const addTagsAction = () => {if (selected && selected.length > 0) {const paths = selected.map((entry) => entry.path);- const metaFilePaths: string[] = paths.map((p) =>- getMetaFileLocationForFile(p, PlatformIO.getDirSeparator()),- );- // tmp fix; saving meta sidecar file is not ignored by watcher- ignoreByWatcher(...metaFilePaths);- addTags(paths, newlyAddedTags).then(() =>- deignoreByWatcher(...metaFilePaths),- );+ addTags(paths, newlyAddedTags);}onCloseDialog(true);};@@ -99,14 +91,7 @@ function AddRemoveTagsDialog(props: Props) {const removeTagsAction = () => {if (selected && selected.length > 0) {const paths = selected.map((entry) => entry.path);- const metaFilePaths: string[] = paths.map((p) =>- getMetaFileLocationForFile(p, PlatformIO.getDirSeparator()),- );- // tmp fix; saving meta sidecar file is not ignored by watcher- ignoreByWatcher(...metaFilePaths);- removeTags(paths, newlyAddedTags).then(() =>- deignoreByWatcher(...metaFilePaths),- );+ removeTags(paths, newlyAddedTags);}onCloseDialog(true);};@@ -114,12 +99,7 @@ function AddRemoveTagsDialog(props: Props) {const removeAllTagsAction = () => {if (selected && selected.length > 0) {const paths = selected.map((entry) => entry.path);- const metaFilePaths: string[] = paths.map((p) =>- getMetaFileLocationForFile(p, PlatformIO.getDirSeparator()),- );- // tmp fix; saving meta sidecar file is not ignored by watcher- ignoreByWatcher(...metaFilePaths);- removeAllTags(paths).then(() => deignoreByWatcher(...metaFilePaths));+ removeAllTags(paths);}onCloseDialog(true);};diff --git a/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsx b/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsxindex 864680339..860053a58 100644--- a/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsx+++ b/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsx@@ -32,8 +32,8 @@ import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import { getTagColor, getTagTextColor } from '-/reducers/settings';import { TS } from '-/tagspaces.namespace';import { getTagLibrary } from '-/services/taglibrary-utils';-import { actions as AppActions, AppDispatch } from '-/reducers/app';import { useTranslation } from 'react-i18next';+import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';interface Props {open: boolean;@@ -45,7 +45,8 @@ interface Props {function AddTagToTagGroupDialog(props: Props) {const { t } = useTranslation();- const dispatch: AppDispatch = useDispatch();+ const { addTag } = useTaggingActionsContext();+ //const dispatch: AppDispatch = useDispatch();const [tagGroup, setTagGroup] = useState<string>(undefined);const defaultBackgroundColor = useSelector(getTagColor);const defaultTextColor = useSelector(getTagTextColor);@@ -62,7 +63,8 @@ function AddTagToTagGroupDialog(props: Props) {if (!selectedTag.color) {selectedTag.color = defaultBackgroundColor;}- dispatch(AppActions.addTag(selectedTag, tagGroup));+ addTag(selectedTag, tagGroup);+ //dispatch(AppActions.addTag(selectedTag, tagGroup));props.onClose();};diff --git a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx b/src/renderer/components/dialogs/CreateEditLocationDialog.tsxindex c4e88d110..e6c25fe13 100644--- a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx+++ b/src/renderer/components/dialogs/CreateEditLocationDialog.tsx@@ -62,14 +62,11 @@ import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import InfoIcon from '-/components/InfoIcon';import { ProLabel, BetaLabel, ProTooltip } from '-/components/HelperComponents';import { getLocations } from '-/reducers/locations';-import { AppDispatch } from '-/reducers/app';import { getPersistTagsInSidecarFile, isDevMode } from '-/reducers/settings';import ConfirmDialog from '-/components/dialogs/ConfirmDialog';-import PlatformIO from '-/services/platform-facade';import WebdavForm from '-/components/dialogs/WebdavForm';import { useTheme } from '@mui/material/styles';import useMediaQuery from '@mui/material/useMediaQuery';-import { loadLocationDataPromise } from '-/services/utils-io';import { getUuid } from '@tagspaces/tagspaces-common/utils-io';import { ExpandIcon } from '-/components/CommonIcons';import MaxLoopsSelect from '-/components/dialogs/MaxLoopsSelect';@@ -77,6 +74,7 @@ import { useTranslation } from 'react-i18next';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';+import { useTagGroupsLocationContext } from '-/hooks/useTagGroupsLocationContext';const PREFIX = 'CreateEditLocationDialog';@@ -102,6 +100,7 @@ function CreateEditLocationDialog(props: Props) {const { showNotification } = useNotificationContext();const { createLocationIndex } = useLocationIndexContext();+ const { loadLocationDataPromise } = useTagGroupsLocationContext();const { addLocation, selectedLocation } = useCurrentLocationContext();const isPersistTagsInSidecar = useSelector(getPersistTagsInSidecarFile);const locations: Array<TS.Location> = useSelector(getLocations);diff --git a/src/renderer/components/dialogs/CreateTagsDialog.tsx b/src/renderer/components/dialogs/CreateTagsDialog.tsxindex fead3e09f..d6f929c11 100644--- a/src/renderer/components/dialogs/CreateTagsDialog.tsx+++ b/src/renderer/components/dialogs/CreateTagsDialog.tsx@@ -29,17 +29,18 @@ import useFirstRender from '-/utils/useFirstRender';import { TS } from '-/tagspaces.namespace';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import { useTranslation } from 'react-i18next';+import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';interface Props {open: boolean;onClose: () => void;- addTag: (tags: string, uuid: string) => void;selectedTagGroupEntry: TS.TagGroup;}function CreateTagsDialog(props: Props) {- const { open, onClose, addTag, selectedTagGroupEntry } = props;+ const { open, onClose, selectedTagGroupEntry } = props;const { t } = useTranslation();+ const { addTag } = useTaggingActionsContext();const [inputError, setInputError] = useState<boolean>(false);const [tagTitle, setTagTitle] = useState<string>('');diff --git a/src/renderer/components/dialogs/EditTagDialog.tsx b/src/renderer/components/dialogs/EditTagDialog.tsxindex d10202541..91bbee30d 100644--- a/src/renderer/components/dialogs/EditTagDialog.tsx+++ b/src/renderer/components/dialogs/EditTagDialog.tsx@@ -31,17 +31,18 @@ import TransparentBackground from '../TransparentBackground';import { TS } from '-/tagspaces.namespace';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import { useTranslation } from 'react-i18next';+import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';interface Props {open: boolean;onClose: () => void;- editTag: (tag: TS.Tag, tagGroupId: string, origTitle: string) => void;selectedTag: TS.Tag;selectedTagGroupEntry: TS.TagGroup;}function EditTagDialog(props: Props) {const { t } = useTranslation();+ const { editTag } = useTaggingActionsContext();const [displayColorPicker, setDisplayColorPicker] = useState<boolean>(false);const [displayTextColorPicker, setDisplayTextColorPicker] =useState<boolean>(false);@@ -75,13 +76,8 @@ function EditTagDialog(props: Props) {};const onConfirm = () => {- if (- !inputError &&- props.editTag &&- props.selectedTagGroupEntry &&- props.selectedTag- ) {- props.editTag(+ if (!inputError && props.selectedTagGroupEntry && props.selectedTag) {+ editTag({...props.selectedTag,title,diff --git a/src/renderer/components/dialogs/EditTagGroupDialog.tsx b/src/renderer/components/dialogs/EditTagGroupDialog.tsxindex 50e09bf30..80d35b1a2 100644--- a/src/renderer/components/dialogs/EditTagGroupDialog.tsx+++ b/src/renderer/components/dialogs/EditTagGroupDialog.tsx@@ -37,18 +37,20 @@ import { Pro } from '-/pro';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import { getSaveTagInLocation } from '-/reducers/settings';import { useTranslation } from 'react-i18next';+import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';const defaultTagGroupLocation = 'TAG_LIBRARY';interface Props {open: boolean;- editTagGroup: (tagGroup: TS.TagGroup) => void;selectedTagGroupEntry: TS.TagGroup;onClose: () => void;}function EditTagGroupDialog(props: Props) {- const { editTagGroup, selectedTagGroupEntry, open, onClose } = props;+ const { selectedTagGroupEntry, open, onClose } = props;++ const { updateTagGroup } = useTaggingActionsContext();const { t } = useTranslation();const locations: Array<TS.Location> = useSelector(getLocations);const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);@@ -108,7 +110,7 @@ function EditTagGroupDialog(props: Props) {);}}- editTagGroup({+ updateTagGroup({...selectedTagGroupEntry,title,color,diff --git a/src/renderer/components/dialogs/ImportExportTagGroupsDialog.tsx b/src/renderer/components/dialogs/ImportExportTagGroupsDialog.tsxindex 12ebc9cae..1c1dce943 100644--- a/src/renderer/components/dialogs/ImportExportTagGroupsDialog.tsx+++ b/src/renderer/components/dialogs/ImportExportTagGroupsDialog.tsx@@ -35,6 +35,7 @@ import { useTheme } from '@mui/material/styles';import useMediaQuery from '@mui/material/useMediaQuery';import { exportTagGroups } from '-/services/taglibrary-utils';import { useTranslation } from 'react-i18next';+import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';interface Props {open: boolean;@@ -42,11 +43,10 @@ interface Props {onClose: () => void;dialogModeImport: boolean;showNotification?: (text: string) => void;- importTagGroups: (taggroups: Array<TS.TagGroup>) => void;}function ImportExportTagGroupsDialog(props: Props) {- // const [selectedAll, setSelectedAll] = useState<boolean>(true);+ const { importTagGroups } = useTaggingActionsContext();const { t } = useTranslation();const selectedAll = useRef(true);const [tagGroupList, setTagGroupList] = useState<Array<any>>(@@ -84,7 +84,7 @@ function ImportExportTagGroupsDialog(props: Props) {const groupList = tagGroupList.filter((tagGroup) => tagGroup.selected);props.onClose();if (props.dialogModeImport) {- props.importTagGroups(groupList);+ importTagGroups(groupList);if (isFunc(showNotification)) {showNotification(t('core:successfullyImportedGroupTags'));}diff --git a/src/renderer/components/dialogs/settings/SettingsExtensions.tsx b/src/renderer/components/dialogs/settings/SettingsExtensions.tsxindex 1de646567..a042dff5d 100644--- a/src/renderer/components/dialogs/settings/SettingsExtensions.tsx+++ b/src/renderer/components/dialogs/settings/SettingsExtensions.tsx@@ -112,7 +112,8 @@ function SettingsExtensions() {.filter((ext) => !ext.extensionExternal).map((ext) => (<ListItem key={ext.extensionId} disablePadding>- {ext.extensionName} ({ext.version})+ {ext.extensionName}{' '}+ <small style={{ marginLeft: 5 }}>v{ext.version}</small></ListItem>))}</List>@@ -136,7 +137,8 @@ function SettingsExtensions() {.filter((ext) => ext.extensionExternal).map((ext) => (<ListItem key={ext.extensionId} disablePadding>- {ext.extensionName} ({ext.version})+ {ext.extensionName}{' '}+ <small style={{ marginLeft: 5 }}>v{ext.version}</small><Switchdata-tid="enableExtensionTID"name="enableExtension"diff --git a/src/renderer/components/dialogs/settings/SettingsFileTypes.tsx b/src/renderer/components/dialogs/settings/SettingsFileTypes.tsxindex 317fa278c..c28737086 100644--- a/src/renderer/components/dialogs/settings/SettingsFileTypes.tsx+++ b/src/renderer/components/dialogs/settings/SettingsFileTypes.tsx@@ -395,7 +395,10 @@ function SettingsFileTypes() {key={extension.extensionName}value={extension.extensionId}>- {extension.extensionName} ({extension.version})+ {extension.extensionName}{' '}+ <small style={{ marginLeft: 5 }}>+ v{extension.version}+ </small></MenuItem>),)}@@ -423,7 +426,8 @@ function SettingsFileTypes() {key={extension.extensionName}value={extension.extensionId}>- {extension.extensionName} ({extension.version})+ {extension.extensionName}+ <small style={{ marginLeft: 5 }}>v{extension.version}</small></MenuItem>))}</Select>diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsxindex 0520e1552..9a4dfdfa3 100644--- a/src/renderer/components/menus/FileMenu.tsx+++ b/src/renderer/components/menus/FileMenu.tsx@@ -42,11 +42,7 @@ import {extractTitle,} from '@tagspaces/tagspaces-common/paths';import PlatformIO from '-/services/platform-facade';-import {- setFolderBackgroundPromise,- getRelativeEntryPath,- toFsEntry,-} from '-/services/utils-io';+import { getRelativeEntryPath, toFsEntry } from '-/services/utils-io';import { getKeyBindingObject } from '-/reducers/settings';import { Pro } from '-/pro';import { useSelector } from 'react-redux';@@ -66,7 +62,6 @@ 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';import { TS } from '-/tagspaces.namespace';import { generateClipboardLink } from '-/utils/dom';@@ -108,14 +103,18 @@ function FileMenu(props: Props) {const keyBindings = useSelector(getKeyBindingObject);const { t } = useTranslation();const { selectedEntries } = useSelectedEntriesContext();- const { setBackgroundImageChange, setThumbnailImageChange } =- useEditedEntryMetaContext();+ const {+ setBackgroundImageChange,+ setThumbnailImageChange,+ openFileNatively,+ duplicateFile,+ setFolderBackgroundPromise,+ } = useIOActionsContext();const { openEntry } = useOpenedEntryContext();const { openDirectory, currentLocationPath } = useDirectoryContentContext();const { showNotification } = useNotificationContext();const { setFolderThumbnailPromise } = usePlatformFacadeContext();const { currentLocation, readOnlyMode } = useCurrentLocationContext();- const { openFileNatively, duplicateFile } = useIOActionsContext();function generateFileLink() {const entryPath = selectedEntries[0].path;diff --git a/src/renderer/components/menus/TagGroupMenu.tsx b/src/renderer/components/menus/TagGroupMenu.tsxindex 0facc1d4b..5a36a5839 100644--- a/src/renderer/components/menus/TagGroupMenu.tsx+++ b/src/renderer/components/menus/TagGroupMenu.tsx@@ -37,7 +37,6 @@ import { TS } from '-/tagspaces.namespace';import InfoIcon from '-/components/InfoIcon';import { useTranslation } from 'react-i18next';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';-import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';interface Props {@@ -49,9 +48,6 @@ interface Props {showCreateTagsDialog: () => void;showDeleteTagGroupDialog: () => void;showEditTagGroupDialog: () => void;- moveTagGroupUp: (tagGroupId: string) => void;- moveTagGroupDown: (tagGroupId: string) => void;- sortTagGroup: (tagGroupId: string) => void;handleCloseTagGroupMenu: () => void;}@@ -61,9 +57,6 @@ function TagGroupMenu(props: Props) {onClose,selectedTagGroupEntry,handleCloseTagGroupMenu,- moveTagGroupUp,- moveTagGroupDown,- sortTagGroup,anchorEl,showCreateTagsDialog,showEditTagGroupDialog,@@ -71,9 +64,13 @@ function TagGroupMenu(props: Props) {} = props;const { t } = useTranslation();- const { collectTagsFromLocation } = useTaggingActionsContext();+ const {+ collectTagsFromLocation,+ moveTagGroupUp,+ moveTagGroupDown,+ sortTagGroup,+ } = useTaggingActionsContext();const { setSearchQuery } = useDirectoryContentContext();- const dispatch: AppDispatch = useDispatch();const maxSearchResults = useSelector(getMaxSearchResults);function handleCollectTags() {@@ -83,7 +80,7 @@ function TagGroupMenu(props: Props) {collectTagsFromLocation(selectedTagGroupEntry);}handleCloseTagGroupMenu();- dispatch(AppActions.tagLibraryChanged());+ //dispatch(AppActions.tagLibraryChanged());}function moveTagGroupUpInt() {diff --git a/src/renderer/components/menus/TagLibraryMenu.tsx b/src/renderer/components/menus/TagLibraryMenu.tsxindex a70da68c8..ed3c1a024 100644--- a/src/renderer/components/menus/TagLibraryMenu.tsx+++ b/src/renderer/components/menus/TagLibraryMenu.tsx@@ -17,7 +17,6 @@*/import React, { useRef, useState } from 'react';-import { useDispatch } from 'react-redux';import ListItemText from '@mui/material/ListItemText';import ListItemIcon from '@mui/material/ListItemIcon';import Menu from '@mui/material/Menu';@@ -28,30 +27,32 @@ import AddIcon from '@mui/icons-material/Add';import ReloadIcon from '@mui/icons-material/Sync';import AppConfig from '-/AppConfig';import ImportExportTagGroupsDialog from '../dialogs/ImportExportTagGroupsDialog';-import { TS } from '-/tagspaces.namespace';import Links from 'assets/links';import { ProLabel, ProTooltip } from '-/components/HelperComponents';import { Pro } from '-/pro';import { openURLExternally } from '-/services/utils-io';-import { actions as AppActions, AppDispatch } from '-/reducers/app';import { useTranslation } from 'react-i18next';import { useNotificationContext } from '-/hooks/useNotificationContext';+import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';+import { useSelector } from 'react-redux';+import { getSaveTagInLocation } from '-/reducers/settings';+import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';interface Props {classes?: any;anchorEl: Element;- tagGroups: Array<Object>;open: boolean;onClose: () => void;- importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;showCreateTagGroupDialog: () => void;- saveTagInLocation: boolean;- 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);const tagGroupsImported = useRef([]);// const [tagGroups, setTagGroups] = useState(null);@@ -106,11 +107,8 @@ function TagLibraryMenu(props: Props) {<ImportExportTagGroupsDialogopen={isImportExportTagGroupDialogOpened}onClose={handleCloseDialogs}- tagGroups={- dialogModeImport ? tagGroupsImported.current : props.tagGroups- }+ tagGroups={dialogModeImport ? tagGroupsImported.current : tagGroups}dialogModeImport={dialogModeImport}- importTagGroups={props.importTagGroups}/>)}<Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}>@@ -131,10 +129,10 @@ function TagLibraryMenu(props: Props) {tooltip={t('core:enableTagsFromLocationHelp')}><MenuItem- disabled={!Pro || !props.saveTagInLocation}+ disabled={!Pro || !saveTagInLocation}data-tid="refreshTagGroups"onClick={() => {- props.refreshTagsFromLocation();+ refreshTagsFromLocation();props.onClose();}}>diff --git a/src/renderer/containers/Root.tsx b/src/renderer/containers/Root.tsxindex be494f28c..1c766deab 100644--- a/src/renderer/containers/Root.tsx+++ b/src/renderer/containers/Root.tsx@@ -40,6 +40,9 @@ import { EditedEntryContextProvider } from '-/hooks/EditedEntryContextProvider';import { HTML5Backend } from 'react-dnd-html5-backend';import { DndProvider } from 'react-dnd';import { EditedEntryMetaContextProvider } from '-/hooks/EditedEntryMetaContextProvider';+import { TagGroupsLocationContextProvider } from '-/hooks/TagGroupsLocationContextProvider';+import { EditedTagLibraryContextProvider } from '-/hooks/EditedTagLibraryContextProvider';+import { EditedKanBanMetaContextProvider } from '-/hooks/EditedKanBanMetaContextProvider';type RootType = {store: Store<{}>;@@ -65,25 +68,31 @@ export default function Root({ store, persistor }: RootType) {<CurrentLocationContextProvider><EditedEntryContextProvider><EditedEntryMetaContextProvider>- <SelectedEntryContextProvider>- <DirectoryContentContextProvider>- <FSWatcherContextProvider>- <PlatformFacadeContextProvider>- <LocationIndexContextProvider>- <OpenedEntryContextProvider>- <IOActionsContextProvider>- <TaggingActionsContextProvider>- <DndProvider backend={HTML5Backend}>- <MainPage />- </DndProvider>- </TaggingActionsContextProvider>- </IOActionsContextProvider>- </OpenedEntryContextProvider>- </LocationIndexContextProvider>- </PlatformFacadeContextProvider>- </FSWatcherContextProvider>- </DirectoryContentContextProvider>- </SelectedEntryContextProvider>+ <EditedTagLibraryContextProvider>+ <EditedKanBanMetaContextProvider>+ <SelectedEntryContextProvider>+ <DirectoryContentContextProvider>+ <FSWatcherContextProvider>+ <PlatformFacadeContextProvider>+ <LocationIndexContextProvider>+ <OpenedEntryContextProvider>+ <IOActionsContextProvider>+ <TagGroupsLocationContextProvider>+ <TaggingActionsContextProvider>+ <DndProvider backend={HTML5Backend}>+ <MainPage />+ </DndProvider>+ </TaggingActionsContextProvider>+ </TagGroupsLocationContextProvider>+ </IOActionsContextProvider>+ </OpenedEntryContextProvider>+ </LocationIndexContextProvider>+ </PlatformFacadeContextProvider>+ </FSWatcherContextProvider>+ </DirectoryContentContextProvider>+ </SelectedEntryContextProvider>+ </EditedKanBanMetaContextProvider>+ </EditedTagLibraryContextProvider></EditedEntryMetaContextProvider></EditedEntryContextProvider></CurrentLocationContextProvider>diff --git a/src/renderer/hooks/DescriptionContextProvider.tsx b/src/renderer/hooks/DescriptionContextProvider.tsxindex 8a652850e..5e9e55969 100644--- a/src/renderer/hooks/DescriptionContextProvider.tsx+++ b/src/renderer/hooks/DescriptionContextProvider.tsx@@ -30,7 +30,7 @@ import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { TS } from '-/tagspaces.namespace';-import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';+import { useIOActionsContext } from '-/hooks/useIOActionsContext';type DescriptionContextData = {description: string;@@ -63,7 +63,7 @@ export const DescriptionContextProvider = ({const { openedEntry } = useOpenedEntryContext();const { readOnlyMode } = useCurrentLocationContext();const { showNotification } = useNotificationContext();- const { setDescriptionChange } = useEditedEntryMetaContext();+ const { setDescriptionChange } = useIOActionsContext();//const description = useRef<string>(openedEntry.meta?.description);const lastOpenedFile = useRef<TS.OpenedEntry>(openedEntry);const isChanged = useRef<boolean>(false);diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex 16fc7fac0..7dde64bef 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -32,7 +32,6 @@ import {cleanTrailingDirSeparator,cleanFrontDirSeparator,extractContainingDirectoryPath,- extractFileName,extractParentDirectoryPath,} from '@tagspaces/tagspaces-common/paths';import PlatformIO from '-/services/platform-facade';@@ -63,6 +62,7 @@ import { defaultSettings as defaultListSettings } from '-/perspectives/list';import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';import { getDirMeta, loadCurrentDirMeta } from '-/services/meta-loader';import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';+import { useEditedKanBanMetaContext } from '-/hooks/useEditedKanBanMetaContext';type DirectoryContentContextData = {currentLocationPath: string;@@ -126,11 +126,6 @@ type DirectoryContentContextData = {findFromSavedSearch: (uuid: string) => void;getDefaultPerspectiveSettings: (perspective: string) => TS.FolderSettings;getPerspective: () => TS.PerspectiveType;- toggleDirVisibility: (- dir: TS.OrderVisibilitySettings,- parentDirPath?: string,- update?: boolean,- ) => Promise<TS.FileSystemEntryMeta>;};export const DirectoryContentContext =@@ -172,7 +167,6 @@ export const DirectoryContentContext =findFromSavedSearch: () => {},getDefaultPerspectiveSettings: undefined,getPerspective: undefined,- toggleDirVisibility: undefined,});export type DirectoryContentContextProviderProps = {@@ -193,6 +187,7 @@ export const DirectoryContentContextProvider = ({} = useCurrentLocationContext();const { actions } = useEditedEntryContext();const { metaActions, setReflectMetaActions } = useEditedEntryMetaContext();+ const { kanbanActions } = useEditedKanBanMetaContext();const { showNotification, hideNotifications } = useNotificationContext();const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();@@ -274,8 +269,23 @@ export const DirectoryContentContextProvider = ({}}, [metaActions]);+ useEffect(() => {+ if (kanbanActions && kanbanActions.length > 0) {+ for (const action of kanbanActions) {+ if (action.action === 'directoryVisibilityChange') {+ directoryMeta.current = action.meta;+ currentDirectoryDirs.current = [+ ...directoryMeta.current.customOrder.folders,+ ];+ forceUpdate();+ }+ }+ }+ }, [kanbanActions]);+useEffect(() => {reflectActions(actions).catch(console.error);+ reflectSelection(actions);}, [actions]);const reflectActions = async (actions) => {@@ -296,8 +306,8 @@ export const DirectoryContentContextProvider = ({...action.entry,};}- // update ordered entries (KanBan)- if (Pro && Pro.MetaOperations && action.oldEntryPath) {+ // update ordered entries (KanBan) todo find better place for this+ /*if (Pro && Pro.MetaOperations && action.oldEntryPath) {const dirPath = extractContainingDirectoryPath(action.entry.path,PlatformIO.getDirSeparator(),@@ -312,12 +322,13 @@ export const DirectoryContentContextProvider = ({PlatformIO.getDirSeparator(),);const dirMeta: TS.FileSystemEntryMeta =- await Pro.MetaOperations.reflectOrderEntryRenamed(+ await Pro.MetaOperations.getOrderEntryRenamed(dirPath,oldName,action.entry.name,);if (dirMeta) {+ await saveMetaDataPromise(dirPath, dirMeta);directoryMeta.current = { ...dirMeta };if (directoryMeta.current.customOrder) {if (directoryMeta.current.customOrder.files) {@@ -333,7 +344,7 @@ export const DirectoryContentContextProvider = ({}}}- }+ }*/if (cleanTrailingDirSeparator(currentDirectoryPath.current) ===cleanTrailingDirSeparator(action.entry.path)@@ -356,6 +367,50 @@ export const DirectoryContentContextProvider = ({}};+ function reflectSelection(actions) {+ let updated = false;+ if (actions && actions.length > 0) {+ let selected = [];+ for (const action of actions) {+ if (action.action === 'add') {+ if (+ currentDirectoryEntries.current.some(+ (entry) => entry.path === action.entry.path,+ )+ ) {+ if (selectedEntries.length > 0) {+ selected = [...selectedEntries, action.entry];+ } else {+ selected.push(action.entry);+ }+ updated = true;+ }+ } else if (action.action === 'delete') {+ let index = selectedEntries.findIndex(+ (e) => e.path === action.entry.path,+ );+ if (index !== -1) {+ selectedEntries.splice(index, 1);+ selected = [...selectedEntries];+ updated = true;+ }+ } else if (action.action === 'update') {+ let index = selectedEntries.findIndex(+ (e) => e.path === action.oldEntryPath,+ );+ if (index !== -1) {+ selectedEntries[index] = action.entry;+ selected = [...selectedEntries];+ updated = true;+ }+ }+ }+ if (updated) {+ setSelectedEntries(selected);+ }+ }+ }+async function reflectAddAction(entry: TS.FileSystemEntry) {const entryExist = currentDirectoryEntries.current.some((e) => e.path === entry.path,@@ -375,14 +430,14 @@ export const DirectoryContentContextProvider = ({) === cleanTrailingDirSeparator(cleanFrontDirSeparator(dirPath))) {currentDirectoryEntries.current.push(entry);- // reflect add KanBan folders visibility- if (!entry.isFile) {+ // reflect add KanBan folders visibility todo move in IOActionContext+ /*if (!entry.isFile) {await toggleDirVisibility({ name: entry.name, uuid: entry.uuid },dirPath,false,);- }+ }*/}}}@@ -1004,7 +1059,7 @@ export const DirectoryContentContextProvider = ({});}- function toggleDirVisibility(+ /*function toggleDirVisibility(dir: TS.OrderVisibilitySettings,parentDirPath: string = undefined,update: boolean = true,@@ -1029,7 +1084,7 @@ export const DirectoryContentContextProvider = ({return meta;});}- }+ }*/const context = useMemo(() => {return {@@ -1070,7 +1125,6 @@ export const DirectoryContentContextProvider = ({exitSearchMode,findFromSavedSearch,getDefaultPerspectiveSettings,- toggleDirVisibility,};}, [currentLocation,diff --git a/src/renderer/hooks/EditedEntryMetaContextProvider.tsx b/src/renderer/hooks/EditedEntryMetaContextProvider.tsxindex b3e5f30e0..a1191a0dd 100644--- a/src/renderer/hooks/EditedEntryMetaContextProvider.tsx+++ b/src/renderer/hooks/EditedEntryMetaContextProvider.tsx@@ -17,52 +17,17 @@*/import React, { createContext, useMemo, useReducer, useRef } from 'react';-import {- getBgndFileLocationForDirectory,- getThumbFileLocationForDirectory,-} from '@tagspaces/tagspaces-common/paths';import { TS } from '-/tagspaces.namespace';-import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';-import { saveFsEntryMeta } from '-/utils/metaoperations';-import PlatformIO from '-/services/platform-facade';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) => void;};export const EditedEntryMetaContext = createContext<EditedEntryMetaContextData>({metaActions: undefined,setReflectMetaActions: undefined,- setAutoSave: undefined,- setDescriptionChange: undefined,- saveDirectoryPerspective: undefined,- setBackgroundImageChange: undefined,- setBackgroundColorChange: undefined,- setThumbnailImageChange: undefined,},);@@ -73,8 +38,6 @@ export type EditedEntryMetaContextProviderProps = {export const EditedEntryMetaContextProvider = ({children,}: EditedEntryMetaContextProviderProps) => {- const { switchLocationTypeByID, switchCurrentLocationType } =- useCurrentLocationContext();const metaActions = useRef<TS.EditMetaAction[]>(undefined);const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);@@ -84,164 +47,10 @@ export const EditedEntryMetaContextProvider = ({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: { ...(entry.meta && 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: { ...(entry.meta && 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: { ...(entry.meta && entry.meta), ...meta },- },- };- setReflectMetaActions(action);- return true;- }- return false;- },- );- }-- function setBackgroundImageChange(entry: TS.FileSystemEntry) {- if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {- // reload cache- const folderBgndPath = getBgndFileLocationForDirectory(- entry.path,- PlatformIO.getDirSeparator(),- );- PlatformIO.generateURLforPath(folderBgndPath, 604800);- }- const action: TS.EditMetaAction = {- action: 'bgdImgChange',- entry: {- ...entry,- meta: {- ...(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: { ...(entry.meta && entry.meta), ...meta },- },- };- setReflectMetaActions(action);- return true;- }- return false;- });- }-- function setThumbnailImageChange(entry: TS.FileSystemEntry) {- if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {- // reload cache- const folderThumbPath = getThumbFileLocationForDirectory(- entry.path,- PlatformIO.getDirSeparator(),- );- PlatformIO.generateURLforPath(folderThumbPath, 604800);- }- const action: TS.EditMetaAction = {- action: 'thumbChange',- entry: {- ...entry,- meta: { ...entry.meta, lastUpdated: new Date().getTime() },- },- };- setReflectMetaActions(action);- }-- 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]);diff --git a/src/renderer/hooks/EditedKanBanMetaContextProvider.tsx b/src/renderer/hooks/EditedKanBanMetaContextProvider.tsxnew file mode 100644index 000000000..154594298--- /dev/null+++ b/src/renderer/hooks/EditedKanBanMetaContextProvider.tsx@@ -0,0 +1,61 @@+/**+ * 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';++type EditedKanBanMetaContextData = {+ kanbanActions: TS.KanBanMetaActions[];+ setReflectKanBanActions: (...actionsArray: TS.KanBanMetaActions[]) => void;+};++export const EditedKanBanMetaContext =+ createContext<EditedKanBanMetaContextData>({+ kanbanActions: undefined,+ setReflectKanBanActions: undefined,+ });++export type EditedKanBanMetaContextProviderProps = {+ children: React.ReactNode;+};++export const EditedKanBanMetaContextProvider = ({+ children,+}: EditedKanBanMetaContextProviderProps) => {+ const metaActions = useRef<TS.KanBanMetaActions[]>(undefined);++ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);++ function setReflectKanBanActions(...actionsArray: TS.KanBanMetaActions[]) {+ metaActions.current = actionsArray;+ forceUpdate();+ }++ const context = useMemo(() => {+ return {+ kanbanActions: metaActions.current,+ setReflectKanBanActions,+ };+ }, [metaActions.current]);++ return (+ <EditedKanBanMetaContext.Provider value={context}>+ {children}+ </EditedKanBanMetaContext.Provider>+ );+};diff --git a/src/renderer/hooks/EditedTagLibraryContextProvider.tsx b/src/renderer/hooks/EditedTagLibraryContextProvider.tsxnew file mode 100644index 000000000..59d2459ff--- /dev/null+++ b/src/renderer/hooks/EditedTagLibraryContextProvider.tsx@@ -0,0 +1,62 @@+/**+ * 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 { getTagLibrary } from '-/services/taglibrary-utils';++type EditedTagLibraryContextData = {+ tagGroups: TS.TagGroup[];+ reflectTagLibraryChanged: (tg: TS.TagGroup[]) => void;+};++export const EditedTagLibraryContext =+ createContext<EditedTagLibraryContextData>({+ tagGroups: undefined,+ reflectTagLibraryChanged: undefined,+ });++export type EditedTagLibraryContextProviderProps = {+ children: React.ReactNode;+};++export const EditedTagLibraryContextProvider = ({+ children,+}: EditedTagLibraryContextProviderProps) => {+ const tagGroups = useRef<TS.TagGroup[]>(getTagLibrary());++ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);++ function reflectTagLibraryChanged(tg: TS.TagGroup[]) {+ tagGroups.current = tg;+ forceUpdate();+ }++ const context = useMemo(() => {+ return {+ tagGroups: tagGroups.current,+ reflectTagLibraryChanged,+ };+ }, [tagGroups.current]);++ return (+ <EditedTagLibraryContext.Provider value={context}>+ {children}+ </EditedTagLibraryContext.Provider>+ );+};diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsxindex 7bca23429..ef97533d0 100644--- a/src/renderer/hooks/FSWatcherContextProvider.tsx+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx@@ -30,6 +30,7 @@ import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { toFsEntry } from '-/services/utils-io';import { Changed } from '../../main/chokidarWatcher';import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';+import { TS } from '-/tagspaces.namespace';type FSWatcherContextData = {ignored: string[];@@ -65,10 +66,11 @@ export const FSWatcherContextProvider = ({currentDirectoryPath,perspective,} = useDirectoryContentContext();- const { reflectDeleteEntries, reflectAddEntry, reflectUpdateMeta } =- useEditedEntryContext();+ const { setReflectActions, reflectUpdateMeta } = useEditedEntryContext();const ignored = useRef<string[]>([]);const watchingFolderPath = useRef<string>(undefined);+ let timer; // Timer variable to delay batch execution+ const actionsQueue: TS.EditAction[] = [];useEffect(() => {if (@@ -93,6 +95,14 @@ export const FSWatcherContextProvider = ({PlatformIO.watchFolder(locationPath, depth);}+ function executeBatchActions() {+ if (actionsQueue.length > 0) {+ setReflectActions(...actionsQueue);+ // Clear the actions queue after executing batch changes+ actionsQueue.length = 0;+ }+ }+const folderChanged = useMemo(() => {return (event, path): void => {console.log(`File ${path} has been ${event}`);@@ -114,6 +124,14 @@ export const FSWatcherContextProvider = ({return;}}+ // Clear existing timer+ clearTimeout(timer);++ // Set timer to delay batch execution+ timer = setTimeout(() => {+ // Execute batch changes after 1 second delay+ executeBatchActions();+ }, 1000);switch (event) {case 'unlink':@@ -122,17 +140,31 @@ export const FSWatcherContextProvider = ({//currentDirectoryEntries.some((entry) => path === entry.path) &&!path.includes(AppConfig.metaFolder)) {- reflectDeleteEntries(toFsEntry(path, false));+ actionsQueue.push({+ action: 'delete',+ entry: toFsEntry(path, false),+ });+ //reflectDeleteEntries(toFsEntry(path, false));}break;case 'add':if (!path.includes(AppConfig.metaFolder)) {- reflectAddEntry(toFsEntry(path, true));+ actionsQueue.push({+ action: 'add',+ entry: toFsEntry(path, true),+ open: false,+ });+ // reflectAddEntry(toFsEntry(path, true));}break;case 'addDir':if (!path.includes(AppConfig.metaFolder)) {- reflectAddEntry(toFsEntry(path, false));+ actionsQueue.push({+ action: 'add',+ entry: toFsEntry(path, false),+ open: false,+ });+ //reflectAddEntry(toFsEntry(path, false));}break;case 'change':diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsxindex d2ab63d0c..7a7a4d15b 100644--- a/src/renderer/hooks/IOActionsContextProvider.tsx+++ b/src/renderer/hooks/IOActionsContextProvider.tsx@@ -16,7 +16,7 @@**/-import React, { createContext, useMemo } from 'react';+import React, { createContext, useEffect, useMemo } from 'react';import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';import { useTranslation } from 'react-i18next';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';@@ -29,27 +29,39 @@ import {getBackupFileLocation,getMetaDirectoryPath,getMetaFileLocationForFile,+ getMetaFileLocationForDir,getThumbFileLocationForFile,+ getBgndFileLocationForDirectory,+ getThumbFileLocationForDirectory,joinPaths,normalizePath,extractTags,+ cleanTrailingDirSeparator,+ cleanFrontDirSeparator,} from '@tagspaces/tagspaces-common/paths';+import { getUuid } from '@tagspaces/tagspaces-common/utils-io';import PlatformIO from '-/services/platform-facade';import { actions as AppActions, AppDispatch } from '-/reducers/app';import { useDispatch, useSelector } from 'react-redux';import {+ cleanMetaData,executePromisesInBatches,generateFileName,getAllPropertiesPromise,getThumbPath,loadFileMetaDataPromise,+ loadMetaDataPromise,+ mergeFsEntryMeta,toFsEntry,} from '-/services/utils-io';import { TS } from '-/tagspaces.namespace';import { Progress } from 'aws-sdk/clients/s3';import AppConfig from '-/AppConfig';-import { generateThumbnailPromise } from '-/services/thumbsgenerator';-import { base64ToArrayBuffer } from '-/utils/dom';+import {+ generateImageThumbnail,+ generateThumbnailPromise,+} from '-/services/thumbsgenerator';+import { base64ToBlob } from '-/utils/dom';import {enhanceEntry,loadJSONString,@@ -61,6 +73,10 @@ import {} from '-/reducers/settings';import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';+import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';+import { Pro } from '-/pro';+import { useEditedKanBanMetaContext } from '-/hooks/useEditedKanBanMetaContext';type IOActionsContextData = {createDirectory: (directoryPath: string) => Promise<boolean>;@@ -118,6 +134,51 @@ type IOActionsContextData = {) => Promise<boolean>;openFileNatively: (selectedFile?: string) => void;duplicateFile: (selectedFilePath: string) => void;+ saveMetaDataPromise: (+ path: string,+ metaData: any,+ ) => Promise<TS.FileSystemEntryMeta>;+ getMetadataID: (path: string, id: string) => Promise<string>;+ createFsEntryMeta: (path: string, props?: any) => Promise<string>;+ saveFsEntryMeta: (path: string, meta: any) => Promise<TS.FileSystemEntryMeta>;+ savePerspective: (+ path: string,+ perspective: TS.PerspectiveType,+ ) => Promise<TS.FileSystemEntryMeta>;+ removeFolderCustomSettings: (+ path: string,+ perspective: string,+ ) => Promise<TS.FileSystemEntryMeta>;+ 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) => void;+ setFolderBackgroundPromise: (+ filePath: string,+ directoryPath: string,+ ) => Promise<string>;+ toggleDirVisibility: (+ dir: TS.OrderVisibilitySettings,+ parentDirPath?,+ ) => void;};export const IOActionsContext = createContext<IOActionsContextData>({@@ -136,6 +197,20 @@ export const IOActionsContext = createContext<IOActionsContextData>({renameFile: undefined,openFileNatively: undefined,duplicateFile: undefined,+ saveMetaDataPromise: undefined,+ getMetadataID: undefined,+ createFsEntryMeta: undefined,+ saveFsEntryMeta: undefined,+ savePerspective: undefined,+ removeFolderCustomSettings: undefined,+ setAutoSave: undefined,+ setDescriptionChange: undefined,+ saveDirectoryPerspective: undefined,+ setBackgroundImageChange: undefined,+ setBackgroundColorChange: undefined,+ setThumbnailImageChange: undefined,+ setFolderBackgroundPromise: undefined,+ toggleDirVisibility: undefined,});export type IOActionsContextProviderProps = {@@ -161,16 +236,47 @@ export const IOActionsContextProvider = ({copyDirectoryPromise,moveDirectoryPromise,saveFilePromise,+ saveTextFilePromise,saveBinaryFilePromise,deleteEntriesPromise,} = usePlatformFacadeContext();- const { setReflectActions } = useEditedEntryContext();+ const { actions, setReflectActions } = useEditedEntryContext();+ const { setReflectMetaActions } = useEditedEntryMetaContext();+ const { setReflectKanBanActions } = useEditedKanBanMetaContext();const { currentDirectoryPath, openDirectory } = useDirectoryContentContext();+ const { switchLocationTypeByID, switchCurrentLocationType } =+ useCurrentLocationContext();const warningOpeningFilesExternally = useSelector(getWarningOpeningFilesExternally,);const prefixTagContainer = useSelector(getPrefixTagContainer);+ useEffect(() => {+ if (actions && actions.length > 0) {+ for (const action of actions) {+ if (action.action === 'add') {+ // reflect visibility change on new KanBan column add+ if (!action.entry.isFile) {+ const dirPath = extractContainingDirectoryPath(+ action.entry.path,+ PlatformIO.getDirSeparator(),+ );+ if (+ cleanTrailingDirSeparator(+ cleanFrontDirSeparator(currentDirectoryPath),+ ) === cleanTrailingDirSeparator(cleanFrontDirSeparator(dirPath))+ ) {+ toggleDirVisibility(+ { name: action.entry.name, uuid: action.entry.uuid },+ dirPath,+ );+ }+ }+ }+ }+ }+ }, [actions]);+function createDirectory(directoryPath: string) {return createDirectoryPromise(directoryPath).then((result) => {@@ -414,10 +520,7 @@ export const IOActionsContextProvider = ({fsEntryMeta.id,PlatformIO.getDirSeparator(),);- return PlatformIO.moveDirectoryPromise(- { path: backupDir },- newBackupDir,- )+ return moveDirectoryPromise({ path: backupDir }, newBackupDir).then(() => {console.log('Moving revisions successful from ' +@@ -607,7 +710,7 @@ export const IOActionsContextProvider = ({).then((dataURL) => {if (dataURL && dataURL.length > 6) {const baseString = dataURL.split(',').pop();- const fileContent = base64ToArrayBuffer(baseString);+ const fileContent = base64ToBlob(baseString);return saveBinaryFilePromise({path: getThumbFileLocationForFile(@@ -713,13 +816,13 @@ export const IOActionsContextProvider = ({.then((dataURL) => {if (dataURL && dataURL.length > 6) {const baseString = dataURL.split(',').pop();- const fileContent = base64ToArrayBuffer(baseString);+ const fileContent = base64ToBlob(baseString);const thumbPath = getThumbFileLocationForFile(fileTargetPath,PlatformIO.getDirSeparator(),false,);- return PlatformIO.saveBinaryFilePromise(+ return saveBinaryFilePromise({ path: thumbPath },fileContent,true,@@ -893,7 +996,7 @@ export const IOActionsContextProvider = ({return generateThumbnailPromise(job[3], 0).then((dataURL) => {if (dataURL && dataURL.length > 6) {const baseString = dataURL.split(',').pop();- const fileContent = base64ToArrayBuffer(baseString);+ const fileContent = base64ToBlob(baseString);return uploadFile(filePath,fileType,@@ -1169,6 +1272,440 @@ export const IOActionsContextProvider = ({showNotification('Unable to duplicate, no file selected');}+ /**+ * @param path+ * @param metaData - this will override existing meta data+ */+ async function saveMetaDataPromise(+ path: string,+ metaData: any,+ ): Promise<TS.FileSystemEntryMeta> {+ const entryProperties = await PlatformIO.getPropertiesPromise(path);+ const cleanedMetaData = cleanMetaData(metaData);+ if (entryProperties) {+ let metaFilePath;+ if (entryProperties.isFile) {+ metaFilePath = getMetaFileLocationForFile(+ path,+ PlatformIO.getDirSeparator(),+ );+ // check and create meta folder if not exist+ const metaFolder = getMetaDirectoryPath(+ extractContainingDirectoryPath(path, PlatformIO.getDirSeparator()),+ PlatformIO.getDirSeparator(),+ );+ const metaExist = await PlatformIO.getPropertiesPromise(metaFolder);+ if (!metaExist) {+ await PlatformIO.createDirectoryPromise(metaFolder);+ }+ } else {+ // check and create meta folder if not exist+ // todo not need to check if folder exist first createDirectoryPromise() recursively will skip creation of existing folders https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback+ const metaDirectoryPath = getMetaDirectoryPath(+ path,+ PlatformIO.getDirSeparator(),+ );+ const metaDirectoryProperties =+ await PlatformIO.getPropertiesPromise(metaDirectoryPath);+ if (!metaDirectoryProperties) {+ await PlatformIO.createDirectoryPromise(metaDirectoryPath);+ }++ if (!cleanedMetaData.id) {+ // add id for directories+ cleanedMetaData.id = getUuid();+ }++ metaFilePath = getMetaFileLocationForDir(+ path,+ PlatformIO.getDirSeparator(),+ );+ }+ const meta = mergeFsEntryMeta(cleanedMetaData);+ const content = JSON.stringify(meta);+ return saveTextFilePromise({ path: metaFilePath }, content, true).then(+ () => meta,+ );+ }+ return Promise.reject(new Error('file not found' + path));+ }++ /**+ * @param path+ * @param id FileSystemEntry.uuid+ */+ function getMetadataID(path: string, id: string): Promise<string> {+ return loadMetaDataPromise(path)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ if (fsEntryMeta.id) {+ return fsEntryMeta.id;+ } else {+ return createFsEntryMeta(path, { ...fsEntryMeta, id: id });+ }+ })+ .catch(() => {+ return createFsEntryMeta(path, { id: id });+ });+ }++ function switchLocationAndSaveMetaData(+ 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;+ }),+ );+ }++ function createFsEntryMeta(path: string, props: any = {}): Promise<string> {+ const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta(props);+ return saveMetaDataPromise(path, newFsEntryMeta)+ .then(() => newFsEntryMeta.id)+ .catch((error) => {+ console.log(+ 'Error saveMetaDataPromise for ' ++ path ++ ' orphan id: ' ++ newFsEntryMeta.id,+ error,+ );+ return newFsEntryMeta.id;+ });+ }++ function saveFsEntryMeta(+ path: string,+ meta: any,+ ): Promise<TS.FileSystemEntryMeta> {+ return loadMetaDataPromise(path)+ .then((fsEntryMeta) => {+ return saveMetaDataPromise(path, {+ ...fsEntryMeta,+ ...meta,+ lastUpdated: new Date().getTime(),+ });+ })+ .catch(() => {+ return saveMetaDataPromise(path, mergeFsEntryMeta(meta));+ });+ }++ function savePerspective(+ path: string,+ perspective: TS.PerspectiveType,+ ): Promise<TS.FileSystemEntryMeta> {+ return new Promise((resolve, reject) => {+ loadMetaDataPromise(path)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ let updatedFsEntryMeta: TS.FileSystemEntryMeta;+ if (perspective && perspective !== 'unspecified') {+ updatedFsEntryMeta = {+ ...fsEntryMeta,+ perspective,+ };+ } else {+ const { perspective: remove, ...rest } = fsEntryMeta;+ updatedFsEntryMeta = rest;+ }+ saveMetaDataPromise(path, updatedFsEntryMeta)+ .then(() => {+ resolve(updatedFsEntryMeta);+ return true;+ })+ .catch((err) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + err,+ );+ reject();+ });+ return true;+ })+ .catch(() => {+ const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({+ perspective,+ });+ saveMetaDataPromise(path, newFsEntryMeta)+ .then(() => {+ resolve(newFsEntryMeta);+ return true;+ })+ .catch((error) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + error,+ );+ reject();+ });+ });+ });+ }++ function removeFolderCustomSettings(+ path: string,+ perspective: string,+ ): Promise<TS.FileSystemEntryMeta> {+ return new Promise((resolve, reject) => {+ loadMetaDataPromise(path, true)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ let updatedFsEntryMeta: TS.FileSystemEntryMeta = {+ ...(fsEntryMeta && fsEntryMeta),+ perspectiveSettings: {+ ...(fsEntryMeta &&+ fsEntryMeta.perspectiveSettings &&+ fsEntryMeta.perspectiveSettings),+ [perspective]: undefined,+ },+ };++ saveMetaDataPromise(path, updatedFsEntryMeta)+ .then(() => {+ resolve(updatedFsEntryMeta);+ return true;+ })+ .catch((err) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + err,+ );+ reject();+ });+ return true;+ })+ .catch(() => {+ const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({+ perspectiveSettings: {+ [perspective]: undefined,+ },+ });+ saveMetaDataPromise(path, newFsEntryMeta)+ .then(() => {+ resolve(newFsEntryMeta);+ return true;+ })+ .catch((error) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + error,+ );+ reject();+ });+ });+ });+ }++ function setAutoSave(+ entry: TS.FileSystemEntry,+ autoSave: boolean,+ locationId = undefined,+ ) {+ return switchLocationAndSaveMetaData(+ entry.path,+ { autoSave },+ locationId,+ ).then((meta) => {+ if (meta) {+ const action: TS.EditMetaAction = {+ action: 'autoSaveChange',+ entry: {+ ...entry,+ meta: { ...(entry.meta && entry.meta), ...meta },+ },+ };+ setReflectMetaActions(action);+ return true;+ }+ return false;+ });+ }++ function saveDirectoryPerspective(+ entry: TS.FileSystemEntry,+ perspective: TS.PerspectiveType,+ locationId = undefined,+ ): Promise<boolean> {+ return switchLocationAndSaveMetaData(+ entry.path,+ { perspective },+ locationId,+ ).then((meta) => {+ if (meta) {+ const action: TS.EditMetaAction = {+ action: 'perspectiveChange',+ entry: {+ ...entry,+ meta: { ...(entry.meta && entry.meta), ...meta },+ },+ };+ setReflectMetaActions(action);+ return true;+ }+ return false;+ });+ }++ function setDescriptionChange(+ entry: TS.FileSystemEntry,+ description: string,+ locationId = undefined,+ ): Promise<boolean> {+ return switchLocationAndSaveMetaData(+ entry.path,+ { description },+ locationId,+ ).then((meta) => {+ if (meta) {+ const action: TS.EditMetaAction = {+ action: 'descriptionChange',+ entry: {+ ...entry,+ meta: { ...(entry.meta && entry.meta), ...meta },+ },+ };+ setReflectMetaActions(action);+ return true;+ }+ return false;+ });+ }++ function setBackgroundImageChange(entry: TS.FileSystemEntry) {+ if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {+ // reload cache+ const folderBgndPath = getBgndFileLocationForDirectory(+ entry.path,+ PlatformIO.getDirSeparator(),+ );+ PlatformIO.generateURLforPath(folderBgndPath, 604800);+ }+ const action: TS.EditMetaAction = {+ action: 'bgdImgChange',+ entry: {+ ...entry,+ meta: {+ ...(entry.meta && entry.meta),+ lastUpdated: new Date().getTime(),+ },+ },+ };+ setReflectMetaActions(action);+ }++ function setBackgroundColorChange(+ entry: TS.FileSystemEntry,+ color: string,+ locationId = undefined,+ ): Promise<boolean> {+ return switchLocationAndSaveMetaData(+ entry.path,+ { color },+ locationId,+ ).then((meta) => {+ if (meta) {+ const action: TS.EditMetaAction = {+ action: 'bgdColorChange',+ entry: {+ ...entry,+ meta: { ...(entry.meta && entry.meta), ...meta },+ },+ };+ setReflectMetaActions(action);+ return true;+ }+ return false;+ });+ }++ function setThumbnailImageChange(entry: TS.FileSystemEntry) {+ if (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) {+ // reload cache+ const folderThumbPath = getThumbFileLocationForDirectory(+ entry.path,+ PlatformIO.getDirSeparator(),+ );+ PlatformIO.generateURLforPath(folderThumbPath, 604800);+ }+ const action: TS.EditMetaAction = {+ action: 'thumbChange',+ entry: {+ ...entry,+ meta: { ...entry.meta, lastUpdated: new Date().getTime() },+ },+ };+ setReflectMetaActions(action);+ }++ /**+ * @param filePath+ * @param directoryPath+ * return Promise<directoryPath> of directory in order to open Folder properties next+ */+ function setFolderBackgroundPromise(+ filePath: string,+ directoryPath: string,+ ): Promise<string> {+ const folderBgndPath = getBgndFileLocationForDirectory(+ directoryPath,+ PlatformIO.getDirSeparator(),+ );++ return generateImageThumbnail(filePath, AppConfig.maxBgndSize) // 4K -> 3840, 2K -> 2560+ .then((base64Image) => {+ if (base64Image) {+ const data = base64ToBlob(base64Image.split(',').pop());+ return saveBinaryFilePromise({ path: folderBgndPath }, data, true)+ .then(() => {+ // props.setLastBackgroundImageChange(new Date().getTime());+ return directoryPath;+ })+ .catch((error) => {+ console.log('Save to file failed ', error);+ return Promise.reject(error);+ });+ }+ })+ .catch((error) => {+ console.log('Background generation failed ', error);+ return Promise.reject(error);+ });+ }++ function toggleDirVisibility(+ dir: TS.OrderVisibilitySettings,+ parentDirPath: string = undefined,+ ) {+ if (Pro && Pro.MetaOperations) {+ const currentDirPath = parentDirPath+ ? parentDirPath+ : currentDirectoryPath;+ Pro.MetaOperations.toggleDirectoryVisibility(currentDirPath, dir).then(+ (updatedFsEntryMeta) => {+ if (updatedFsEntryMeta) {+ saveMetaDataPromise(currentDirPath, updatedFsEntryMeta)+ .then(() => {+ const action: TS.KanBanMetaActions = {+ action: 'directoryVisibilityChange',+ meta: updatedFsEntryMeta,+ };+ setReflectKanBanActions(action);+ })+ .catch((err) => {+ console.warn(+ 'Error adding dirs for ' + currentDirPath + ' with ' + err,+ );+ });+ }+ },+ );+ }+ }+const context = useMemo(() => {return {createDirectory,@@ -1186,6 +1723,20 @@ export const IOActionsContextProvider = ({renameFile,openFileNatively,duplicateFile,+ saveMetaDataPromise,+ getMetadataID,+ createFsEntryMeta,+ saveFsEntryMeta,+ savePerspective,+ removeFolderCustomSettings,+ setAutoSave,+ setDescriptionChange,+ saveDirectoryPerspective,+ setBackgroundImageChange,+ setBackgroundColorChange,+ setThumbnailImageChange,+ setFolderBackgroundPromise,+ toggleDirVisibility,};}, [warningOpeningFilesExternally, currentDirectoryPath]);diff --git a/src/renderer/hooks/LocationIndexContextProvider.tsx b/src/renderer/hooks/LocationIndexContextProvider.tsxindex 9f6af10b4..6ee364730 100644--- a/src/renderer/hooks/LocationIndexContextProvider.tsx+++ b/src/renderer/hooks/LocationIndexContextProvider.tsx@@ -35,6 +35,7 @@ import {} from '-/services/utils-io';import { getEnableWS } from '-/reducers/settings';import { locationType } from '@tagspaces/tagspaces-common/misc';+import { getMetaIndexFilePath } from '@tagspaces/tagspaces-indexer';import PlatformIO from '-/services/platform-facade';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { getLocations } from '-/reducers/locations';@@ -47,6 +48,7 @@ import {import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';+import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';type LocationIndexContextData = {index: TS.FileSystemEntry[];@@ -90,6 +92,7 @@ export const LocationIndexContextProvider = ({const { t } = useTranslation();const { currentLocation, getLocationPath } = useCurrentLocationContext();+ const { ignoreByWatcher, deignoreByWatcher } = useFSWatcherContext();const { setSearchResults, appendSearchResults, updateCurrentDirEntries } =useDirectoryContentContext();const { actions } = useEditedEntryContext();@@ -206,6 +209,38 @@ export const LocationIndexContextProvider = ({forceUpdate();}+ function createDirectoryIndexWrapper(+ param: string | any,+ extractText = false,+ ignorePatterns: Array<string> = [],+ enableWS = true,+ // disableIndexing = true,+ ): Promise<any> {+ const indexFilePath = getMetaIndexFilePath(param.path);+ return switchLocationTypeByID(param.locationID)+ .then(() => {+ ignoreByWatcher(indexFilePath);+ return createDirectoryIndex(+ param,+ extractText,+ ignorePatterns,+ enableWS,+ isWalking,+ );+ })+ .then((index) =>+ switchCurrentLocationType().then(() => {+ deignoreByWatcher(indexFilePath);+ return index;+ }),+ )+ .catch((err) => {+ //lastError.current = err;+ console.warn('Error loading text content ' + err);+ return false; //switchCurrentLocationType();+ });+ }+function createLocationIndex(location: TS.Location): Promise<boolean> {if (location) {return getLocationPath(location).then((locationPath) => {@@ -239,25 +274,6 @@ export const LocationIndexContextProvider = ({return Promise.resolve(false);}- function createDirectoryIndexWrapper(- param: string | any,- extractText = false,- ignorePatterns: Array<string> = [],- enableWS = true,- // disableIndexing = true,- ): Promise<any> {- return switchLocationTypeByID(param.locationID)- .then(() =>- createDirectoryIndex(param, extractText, ignorePatterns, enableWS),- )- .then((index) => switchCurrentLocationType().then(() => index))- .catch((err) => {- //lastError.current = err;- console.warn('Error loading text content ' + err);- return false; //switchCurrentLocationType();- });- }-async function createLocationsIndexes(extractText = true): Promise<boolean> {for (let location of allLocations) {try {@@ -433,7 +449,7 @@ export const LocationIndexContextProvider = ({indexAge > maxIndexAge))) {console.log('Start creating index for : ' + currentPath);- const newIndex = await createDirectoryIndex(+ const newIndex = await createDirectoryIndexWrapper({path: currentPath,locationID: currentLocation.uuid,@@ -504,7 +520,7 @@ export const LocationIndexContextProvider = ({// || (!location.disableIndexing && !indexExist)) {console.log('Creating index for : ' + nextPath);- directoryIndex = await createDirectoryIndex(+ directoryIndex = await createDirectoryIndexWrapper({path: nextPath,locationID: location.uuid,@@ -513,7 +529,6 @@ export const LocationIndexContextProvider = ({location.fullTextIndex,location.ignorePatternPaths,enableWS,- isWalking,);}return getSearchResults(directoryIndex, searchQuery).then(diff --git a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsxindex 8c2dba1c2..e4f062740 100644--- a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx+++ b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx@@ -25,9 +25,8 @@ import React, {} from 'react';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { TS } from '-/tagspaces.namespace';-import { PerspectiveIDs } from '-/perspectives';import { Pro } from '-/pro';-import { removeFolderCustomSettings } from '-/utils/metaoperations';+import { useIOActionsContext } from '-/hooks/useIOActionsContext';type PerspectiveSettingsContextData = {orderBy: boolean;@@ -89,6 +88,8 @@ export const PerspectiveSettingsContextProvider = ({getDefaultPerspectiveSettings,getPerspective,} = useDirectoryContentContext();+ const { removeFolderCustomSettings, saveMetaDataPromise } =+ useIOActionsContext();const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);const settings = useRef<TS.FolderSettings>(getSettings(getPerspective(), directoryMeta),@@ -161,12 +162,13 @@ export const PerspectiveSettingsContextProvider = ({isDefaultSetting = !haveLocalSetting();}if (Pro && !isDefaultSetting) {- Pro.MetaOperations.savePerspectiveSettings(+ Pro.MetaOperations.setPerspectiveSettings(currentDirectoryPath,getPerspective(),settings.current,- ).then((fsEntryMeta: TS.FileSystemEntryMeta) => {- setDirectoryMeta(fsEntryMeta);+ ).then((updatedFsEntryMeta: TS.FileSystemEntryMeta) => {+ saveMetaDataPromise(currentDirectoryPath, updatedFsEntryMeta);+ setDirectoryMeta(updatedFsEntryMeta);});} else {const defaultSettings = getDefaultPerspectiveSettings(getPerspective());diff --git a/src/renderer/hooks/PlatformFacadeContextProvider.tsx b/src/renderer/hooks/PlatformFacadeContextProvider.tsxindex 72c0713d9..4138284ef 100644--- a/src/renderer/hooks/PlatformFacadeContextProvider.tsx+++ b/src/renderer/hooks/PlatformFacadeContextProvider.tsx@@ -29,8 +29,7 @@ import {normalizePath,} from '@tagspaces/tagspaces-common/paths';import { useTranslation } from 'react-i18next';-import { AppDispatch } from '-/reducers/app';-import { useDispatch, useSelector } from 'react-redux';+import { useSelector } from 'react-redux';import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';import {executePromisesInBatches,@@ -154,7 +153,6 @@ export const PlatformFacadeContextProvider = ({const { ignoreByWatcher, deignoreByWatcher, ignored } = useFSWatcherContext(); //watcherconst { t } = useTranslation();- const dispatch: AppDispatch = useDispatch();const useTrashCan = useSelector(getUseTrashCan);function createDirectoryPromise(path: string): Promise<any> {diff --git a/src/renderer/hooks/SelectedEntryContextProvider.tsx b/src/renderer/hooks/SelectedEntryContextProvider.tsxindex 6fead7f9f..71a2e5723 100644--- a/src/renderer/hooks/SelectedEntryContextProvider.tsx+++ b/src/renderer/hooks/SelectedEntryContextProvider.tsx@@ -50,7 +50,6 @@ export const SelectedEntryContextProvider = ({children,}: SelectedEntryContextProviderProps) => {const { currentLocation } = useCurrentLocationContext();- const { actions } = useEditedEntryContext();const selectedEntries = useRef<TS.FileSystemEntry[]>([]);const firstRender = useFirstRender();const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);@@ -61,35 +60,6 @@ export const SelectedEntryContextProvider = ({}}, [currentLocation]);- useEffect(() => {- if (actions && actions.length > 0) {- let selected = [...selectedEntries.current];- for (const action of actions) {- if (action.action === 'add') {- selected.push(action.entry);- } else if (action.action === 'delete') {- let index = selectedEntries.current.findIndex(- (e) => e.path === action.entry.path,- );- if (index !== -1) {- selectedEntries.current.splice(index, 1);- selected = [...selectedEntries.current];- }- } else if (action.action === 'update') {- let index = selectedEntries.current.findIndex(- (e) => e.path === action.oldEntryPath,- );- if (index !== -1) {- selectedEntries.current[index] = action.entry;- selected = [...selectedEntries.current];- }- }- }- selectedEntries.current = selected;- forceUpdate();- }- }, [actions]);-//const lastSelectedEntry = useRef<TS.FileSystemEntry>(undefined);/*function getLastSelectedEntry() {diff --git a/src/renderer/hooks/TagGroupsLocationContextProvider.tsx b/src/renderer/hooks/TagGroupsLocationContextProvider.tsxnew file mode 100644index 000000000..3a6970a36--- /dev/null+++ b/src/renderer/hooks/TagGroupsLocationContextProvider.tsx@@ -0,0 +1,410 @@+/**+ * 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 } from 'react';+import { TS } from '-/tagspaces.namespace';+import {+ getDescriptionPreview,+ loadJSONFile,+ mergeFsEntryMeta,+} from '-/services/utils-io';+import {+ getMetaDirectoryPath,+ getMetaFileLocationForDir,+} from '@tagspaces/tagspaces-common/paths';+import PlatformIO from '-/services/platform-facade';+import AppConfig from '-/AppConfig';+import versionMeta from '-/version.json';+import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';+import { useSelector } from 'react-redux';+import { getSaveTagInLocation } from '-/reducers/settings';++type TagGroupsLocationContextData = {+ getTagGroups: (path: string) => Promise<TS.TagGroup[]>;+ createLocationTagGroup: (+ path: string,+ tagGroup: TS.TagGroup,+ ) => Promise<TS.FileSystemEntryMeta>;+ editLocationTagGroup: (+ path: string,+ tagGroup: TS.TagGroup,+ replaceTags?,+ ) => Promise<TS.FileSystemEntryMeta>;+ removeLocationTagGroup: (+ path: string,+ tagGroupUuid: string,+ ) => Promise<TS.FileSystemEntryMeta>;+ mergeLocationTagGroup: (+ path: string,+ tagGroup: TS.TagGroup,+ ) => Promise<TS.FileSystemEntryMeta>;+ loadLocationDataPromise: (+ path: string,+ metaFile?,+ ) => Promise<TS.FileSystemEntryMeta>;+};++export const TagGroupsLocationContext =+ createContext<TagGroupsLocationContextData>({+ getTagGroups: undefined,+ createLocationTagGroup: undefined,+ editLocationTagGroup: undefined,+ removeLocationTagGroup: undefined,+ mergeLocationTagGroup: undefined,+ loadLocationDataPromise: undefined,+ });++export type TagGroupsLocationContextProviderProps = {+ children: React.ReactNode;+};++export const TagGroupsLocationContextProvider = ({+ children,+}: TagGroupsLocationContextProviderProps) => {+ const { createDirectoryPromise, saveTextFilePromise } =+ usePlatformFacadeContext();++ const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);++ /*useEffect(() => {+ if (currentLocation) {+ getTagGroups(currentLocation.path).then((groups) => {+ if (groups && groups.length > 0) {+ tagGroups.current = groups.map((group) => ({+ ...group,+ locationID: currentLocation.uuid,+ }));+ }+ });+ }+ }, [currentLocation]);*/++ function getTagGroups(path: string): Promise<TS.TagGroup[]> {+ return loadLocationDataPromise(path).then(+ (fsEntryMeta: TS.FileSystemEntryMeta) => {+ if (fsEntryMeta) {+ return fsEntryMeta.tagGroups;+ }+ return undefined;+ },+ );+ }++ async function loadLocationDataPromise(+ path: string,+ metaFile = AppConfig.folderLocationsFile,+ ): Promise<TS.FileSystemEntryMeta> {+ if (saveTagInLocation) {+ const entryProperties = await PlatformIO.getPropertiesPromise(path);+ if (!entryProperties.isFile) {+ const metaFilePath = getMetaFileLocationForDir(+ path,+ PlatformIO.getDirSeparator(),+ metaFile,+ );+ const metaData = await loadJSONFile(metaFilePath);+ if (metaData) {+ return {+ ...metaData,+ description: getDescriptionPreview(metaData.description, 200),+ };+ }+ }+ }+ return Promise.resolve(undefined);+ }++ function createLocationTagGroup(+ path: string,+ tagGroup: TS.TagGroup,+ ): Promise<TS.FileSystemEntryMeta> {+ if (!saveTagInLocation) {+ return Promise.resolve(undefined);+ }+ return loadLocationDataPromise(path)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ let tagGroups;+ if (+ fsEntryMeta &&+ fsEntryMeta.tagGroups &&+ fsEntryMeta.tagGroups.length > 0+ ) {+ tagGroups = [+ ...fsEntryMeta.tagGroups.filter((tg) => tg.uuid !== tagGroup.uuid),+ tagGroup,+ ];+ //tagGroups = [...fsEntryMeta.tagGroups, tagGroup];+ } else {+ tagGroups = [tagGroup];+ }+ const updatedEntryMeta: TS.FileSystemEntryMeta = {+ ...(fsEntryMeta && fsEntryMeta),+ tagGroups,+ };+ return saveLocationDataPromise(path, updatedEntryMeta)+ .then(() => {+ return updatedEntryMeta;+ })+ .catch((err) => {+ return Promise.reject(err);+ });+ })+ .catch(() => {+ const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({+ tagGroups: [tagGroup],+ });+ return saveLocationDataPromise(path, newFsEntryMeta)+ .then(() => {+ return newFsEntryMeta;+ })+ .catch((err) => {+ return Promise.reject(err);+ });+ });+ }++ function editLocationTagGroup(+ path: string,+ tagGroup: TS.TagGroup,+ replaceTags = false,+ ): Promise<TS.FileSystemEntryMeta> {+ if (!saveTagInLocation) {+ return Promise.resolve(undefined);+ }+ return new Promise((resolve, reject) => {+ loadLocationDataPromise(path)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ const oldTagGroup = fsEntryMeta.tagGroups.find(+ (group) => group.uuid === tagGroup.uuid,+ );++ let tagGroups;+ if (!oldTagGroup) {+ // add new tag group+ tagGroups = [...fsEntryMeta.tagGroups, tagGroup];+ } else {+ let tags = tagGroup.children;+ if (!replaceTags) {+ oldTagGroup.children.forEach((oldTag) => {+ // filter out duplicated tags+ tags = tags.filter((t) => t.title !== oldTag.title);+ });+ tags = [...oldTagGroup.children, ...tags];+ }++ const newTagGroup = {+ ...tagGroup,+ children: tags,+ };+ if (fsEntryMeta.tagGroups && fsEntryMeta.tagGroups.length > 0) {+ tagGroups = [+ ...fsEntryMeta.tagGroups.filter(+ (group) => group.uuid !== tagGroup.uuid,+ ),+ newTagGroup,+ ];+ } else {+ tagGroups = [newTagGroup];+ }+ }+ const updatedEntryMeta: TS.FileSystemEntryMeta = {+ ...fsEntryMeta,+ tagGroups,+ };+ saveLocationDataPromise(path, updatedEntryMeta)+ .then(() => {+ resolve(updatedEntryMeta);+ return true;+ })+ .catch((err) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + err,+ );+ reject();+ });+ return true;+ })+ .catch(() => {+ const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({+ tagGroups: [tagGroup],+ });+ saveLocationDataPromise(path, newFsEntryMeta)+ .then(() => {+ resolve(newFsEntryMeta);+ return true;+ })+ .catch((error) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + error,+ );+ reject();+ });+ });+ });+ }++ function removeLocationTagGroup(+ path: string,+ tagGroupUuid: string,+ ): Promise<TS.FileSystemEntryMeta> {+ if (!saveTagInLocation) {+ return Promise.resolve(undefined);+ }+ return new Promise((resolve, reject) => {+ loadLocationDataPromise(path)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ const tagGroups = fsEntryMeta.tagGroups.filter(+ (group) => group.uuid !== tagGroupUuid,+ );+ const updatedEntryMeta: TS.FileSystemEntryMeta = {+ ...fsEntryMeta,+ tagGroups,+ };+ saveLocationDataPromise(path, updatedEntryMeta)+ .then(() => {+ resolve(updatedEntryMeta);+ return true;+ })+ .catch((err) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + err,+ );+ reject();+ });+ return true;+ })+ .catch((err) => {+ console.log(err);+ });+ });+ }++ function mergeLocationTagGroup(+ path: string,+ tagGroup: TS.TagGroup,+ ): Promise<TS.FileSystemEntryMeta> {+ if (!saveTagInLocation) {+ return Promise.resolve(undefined);+ }+ return new Promise((resolve, reject) => {+ loadLocationDataPromise(path)+ .then((fsEntryMeta: TS.FileSystemEntryMeta) => {+ const oldTagGroup = fsEntryMeta.tagGroups.find(+ (group) => group.uuid === tagGroup.uuid,+ );+ const newTagGroup = { ...tagGroup, children: oldTagGroup.children };+ let tagGroups;+ if (fsEntryMeta.tagGroups && fsEntryMeta.tagGroups.length > 0) {+ tagGroups = [...fsEntryMeta.tagGroups, newTagGroup];+ } else {+ tagGroups = [newTagGroup];+ }+ const updatedEntryMeta: TS.FileSystemEntryMeta = {+ ...fsEntryMeta,+ tagGroups,+ };+ saveLocationDataPromise(path, updatedEntryMeta)+ .then(() => {+ resolve(updatedEntryMeta);+ return true;+ })+ .catch((err) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + err,+ );+ reject();+ });+ return true;+ })+ .catch(() => {+ const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({+ tagGroups: [tagGroup],+ });+ saveLocationDataPromise(path, newFsEntryMeta)+ .then(() => {+ resolve(newFsEntryMeta);+ return true;+ })+ .catch((error) => {+ console.warn(+ 'Error adding perspective for ' + path + ' with ' + error,+ );+ reject();+ });+ });+ });+ }++ async function saveLocationDataPromise(+ path: string,+ metaData: any,+ ): Promise<any> {+ if (!saveTagInLocation) {+ return Promise.resolve(undefined);+ }+ const entryProperties = await PlatformIO.getPropertiesPromise(path);+ if (entryProperties) {+ let metaFilePath;+ if (!entryProperties.isFile) {+ // check and create meta folder if not exist+ // todo not need to check if folder exist first createDirectoryPromise() recursively will skip creation of existing folders https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback+ const metaDirectoryPath = getMetaDirectoryPath(+ path,+ PlatformIO.getDirSeparator(),+ );+ const metaDirectoryProperties =+ await PlatformIO.getPropertiesPromise(metaDirectoryPath);+ if (!metaDirectoryProperties) {+ await createDirectoryPromise(metaDirectoryPath);+ }++ metaFilePath = getMetaFileLocationForDir(+ path,+ PlatformIO.getDirSeparator(),+ AppConfig.folderLocationsFile,+ );+ }+ const content = JSON.stringify({+ ...metaData,+ appName: versionMeta.name,+ appVersion: versionMeta.version,+ lastUpdated: new Date().toJSON(),+ });+ return saveTextFilePromise({ path: metaFilePath }, content, true);+ }+ return Promise.reject(new Error('file not found' + path));+ }++ const context = useMemo(() => {+ return {+ //locationTagGroups: tagGroups.current,+ getTagGroups,+ createLocationTagGroup,+ editLocationTagGroup,+ removeLocationTagGroup,+ mergeLocationTagGroup,+ loadLocationDataPromise,+ };+ }, [saveTagInLocation]);++ return (+ <TagGroupsLocationContext.Provider value={context}>+ {children}+ </TagGroupsLocationContext.Provider>+ );+};diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsxindex b01829504..e9584f43e 100644--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx@@ -16,7 +16,7 @@**/-import React, { createContext, useMemo } from 'react';+import React, { createContext, useEffect, useMemo } from 'react';import { useDispatch, useSelector } from 'react-redux';import { actions as AppActions, AppDispatch } from '-/reducers/app';import mgrs from 'mgrs';@@ -24,13 +24,17 @@ import { Pro } from '-/pro';import { useTranslation } from 'react-i18next';import { TS } from '-/tagspaces.namespace';import OpenLocationCode from 'open-location-code-typescript';-import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';-import { getTagLibrary, mergeTagGroup } from '-/services/taglibrary-utils';+import {+ immutablySwapItems,+ formatDateTime4Tag,+} from '@tagspaces/tagspaces-common/misc';+import { getTagLibrary, setTagLibrary } from '-/services/taglibrary-utils';import { isGeoTag } from '-/utils/geo';import {getAddTagsToLibrary,getGeoTaggingFormat,getPrefixTagContainer,+ getSaveTagInLocation,getTagColor,getTagDelimiter,getTagTextColor,@@ -42,13 +46,14 @@ import {loadDirMetaDataPromise,loadFileMetaDataPromise,loadMetaDataPromise,- saveMetaDataPromise,+ parseNewTags,} from '-/services/utils-io';import {extractContainingDirectoryPath,extractFileName,extractTags,} from '@tagspaces/tagspaces-common/paths';+import { getUuid } from '@tagspaces/tagspaces-common/utils-io';import { getLocations } from '-/reducers/locations';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';@@ -56,6 +61,9 @@ import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';import { useIOActionsContext } from '-/hooks/useIOActionsContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';+import { useTagGroupsLocationContext } from '-/hooks/useTagGroupsLocationContext';+import AppConfig from '-/AppConfig';+import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';type extractOptions = {EXIFGeo?: boolean;@@ -78,6 +86,36 @@ type TaggingActionsContextData = {removeTagsFromEntry: (path: string, tags?: Array<TS.Tag>) => Promise<string>;removeAllTags: (paths: Array<string>) => Promise<boolean>;collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;+ createTagGroup: (+ entry: TS.TagGroup,+ location?: TS.Location,+ ) => Promise<boolean>;+ mergeTagGroup: (entry: TS.TagGroup) => void;+ removeTagGroup: (parentTagGroupUuid: TS.Uuid) => void;+ addTag: (tag: any, parentTagGroupUuid: TS.Uuid) => void;+ editTag: (+ tag: TS.Tag,+ parentTagGroupUuid: TS.Uuid,+ origTitle: string,+ ) => void;+ deleteTag: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => void;+ moveTag: (+ tagTitle: string,+ fromTagGroupId: TS.Uuid,+ toTagGroupId: TS.Uuid,+ ) => void;+ changeTagOrder: (+ tagGroupUuid: TS.Uuid,+ fromIndex: number,+ toIndex: number,+ ) => void;+ moveTagGroupUp: (parentTagGroupUuid: TS.Uuid) => void;+ 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;};export const TaggingActionsContext = createContext<TaggingActionsContextData>({@@ -90,6 +128,21 @@ export const TaggingActionsContext = createContext<TaggingActionsContextData>({removeTagsFromEntry: undefined,removeAllTags: undefined,collectTagsFromLocation: undefined,+ createTagGroup: undefined,+ mergeTagGroup: undefined,+ removeTagGroup: undefined,+ addTag: undefined,+ editTag: undefined,+ deleteTag: undefined,+ moveTag: undefined,+ changeTagOrder: undefined,+ moveTagGroupUp: undefined,+ moveTagGroupDown: undefined,+ moveTagGroup: undefined,+ sortTagGroup: undefined,+ updateTagGroup: undefined,+ importTagGroups: undefined,+ refreshTagsFromLocation: undefined,});export type TaggingActionsContextProviderProps = {@@ -100,10 +153,19 @@ export const TaggingActionsContextProvider = ({children,}: TaggingActionsContextProviderProps) => {const { t } = useTranslation();- const { persistTagsInSidecarFile } = useCurrentLocationContext();+ const { currentLocation, persistTagsInSidecarFile } =+ useCurrentLocationContext();+ const { tagGroups, reflectTagLibraryChanged } = useEditedTagLibraryContext();+ const {+ getTagGroups,+ createLocationTagGroup,+ editLocationTagGroup,+ removeLocationTagGroup,+ mergeLocationTagGroup,+ } = useTagGroupsLocationContext();const { currentDirectoryEntries } = useDirectoryContentContext();const { getIndex } = useLocationIndexContext();- const { renameFile } = useIOActionsContext();+ const { renameFile, saveMetaDataPromise } = useIOActionsContext();const { reflectUpdateMeta, setReflectActions } = useEditedEntryContext();const { showNotification, hideNotifications } = useNotificationContext();const dispatch: AppDispatch = useDispatch();@@ -114,6 +176,37 @@ export const TaggingActionsContextProvider = ({const tagDelimiter: string = useSelector(getTagDelimiter);const prefixTagContainer: boolean = useSelector(getPrefixTagContainer);const locations: TS.Location[] = useSelector(getLocations);+ const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);++ useEffect(() => {+ if (Pro && saveTagInLocation) {+ refreshTagsFromLocation();+ }+ }, [saveTagInLocation, currentLocation]);++ function refreshTagsFromLocation() {+ if (currentLocation) {+ getTagGroups(currentLocation.path).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 = {@@ -293,8 +386,8 @@ export const TaggingActionsContextProvider = ({created_date: new Date().getTime(),modified_date: new Date().getTime(),};- mergeTagGroup(tagGroup, getTagLibrary());- dispatch(AppActions.tagLibraryChanged());+ mergeTagGroup(tagGroup);+ //dispatch(AppActions.tagLibraryChanged());}}@@ -687,8 +780,8 @@ export const TaggingActionsContextProvider = ({created_date: new Date().getTime(),modified_date: new Date().getTime(),};- mergeTagGroup(tagGroup, getTagLibrary());- dispatch(AppActions.tagLibraryChanged());+ mergeTagGroup(tagGroup);+ // dispatch(AppActions.tagLibraryChanged());}}}@@ -876,7 +969,7 @@ export const TaggingActionsContextProvider = ({children: uniqueTags,modified_date: new Date().getTime(),};- mergeTagGroup(changedTagGroup, getTagLibrary(), locations);+ mergeTagGroup(changedTagGroup);// dispatch(TagLibraryActions.mergeTagGroup(changedTagGroup));}}@@ -908,6 +1001,439 @@ export const TaggingActionsContextProvider = ({return uniqueTags;}+ function saveTagLibrary(tg: TS.TagGroup[]) {+ reflectTagLibraryChanged(setTagLibrary(tg));+ }++ function saveTags(tags: TS.Tag[], indexForEditing: number) {+ if (indexForEditing >= 0) {+ /*const taggroupTags = tagGroups[indexForEditing].children;+ if (+ !taggroupTags.some((tag) => tags.some((t) => t.title === tag.title))+ ) {*/+ saveTagLibrary([+ ...tagGroups.slice(0, indexForEditing),+ {+ ...tagGroups[indexForEditing],+ children: tags,+ },+ ...tagGroups.slice(indexForEditing + 1),+ ]);+ }+ }++ function updateTagGroup(entry: TS.TagGroup) {+ let indexForEditing = tagGroups.findIndex(+ (tagGroup) => tagGroup.uuid === entry.uuid,+ );++ if (indexForEditing >= 0) {+ const modifiedEntry = {+ ...entry,+ ...(!entry.created_date && { created_date: new Date().getTime() }),+ ...(!entry.modified_date && { modified_date: new Date().getTime() }),+ };++ if (Pro && entry.locationId) {+ const location: TS.Location = locations.find(+ (l) => l.uuid === entry.locationId,+ );+ if (location) {+ editLocationTagGroup(location.path, modifiedEntry);+ }+ }++ return saveTagLibrary([+ ...tagGroups.slice(0, indexForEditing),+ modifiedEntry,+ ...tagGroups.slice(indexForEditing + 1),+ ]);+ }+ }++ /*function saveTagInt(+ newTag: TS.Tag,+ parentTagGroupUuid: TS.Uuid+ ) {+ let indexForEditing = tagGroups.findIndex(+ (tagGroup) => tagGroup.uuid === parentTagGroupUuid,+ );++ if (indexForEditing >= 0) {+ const taggroupTags = tagGroups[indexForEditing].children;+ if (!taggroupTags.some((tag) => tag.title === newTag.title)) {+ return saveTagLibrary([+ ...tagGroups.slice(0, indexForEditing),+ {+ ...tagGroups[indexForEditing],+ children: [...taggroupTags, newTag],+ },+ ...tagGroups.slice(indexForEditing + 1),+ ]);+ }+ }+ return tagGroups;+ }*/++ function createTagGroup(+ entry: TS.TagGroup,+ location?: TS.Location,+ ): Promise<boolean> {+ const newEntry = {+ ...entry,+ created_date: new Date().getTime(),+ modified_date: new Date().getTime(),+ };+ saveTagLibrary([...tagGroups, newEntry]);+ if (Pro && location) {+ return createLocationTagGroup(location.path, newEntry).then(() => true);+ }+ return Promise.resolve(true);+ }++ function mergeTagGroup(entry: TS.TagGroup) {+ if (Pro && entry.locationId && locations) {+ const location: TS.Location = locations.find(+ (l) => l.uuid === entry.locationId,+ );+ if (location) {+ mergeLocationTagGroup(location.path, entry);+ }+ }+ const indexForEditing = tagGroups.findIndex(+ (obj) => obj.uuid === entry.uuid,+ );+ if (indexForEditing > -1) {+ const tags = [...tagGroups[indexForEditing].children, ...entry.children];+ tags.splice(0, tags.length - AppConfig.maxCollectedTag);+ saveTagLibrary([+ ...tagGroups.slice(0, indexForEditing),+ {+ uuid: entry.uuid,+ title: entry.title,+ children: tags,+ created_date: entry.created_date,+ modified_date: new Date().getTime(),+ },+ ...tagGroups.slice(indexForEditing + 1),+ ]);+ } else {+ saveTagLibrary([+ ...tagGroups,+ {+ uuid: entry.uuid || getUuid(),+ title: entry.title,+ color: entry.color,+ textcolor: entry.textcolor,+ children: entry.children,+ created_date: new Date().getTime(),+ modified_date: new Date().getTime(),+ },+ ]);+ }+ }++ function removeTagGroup(parentTagGroupUuid: TS.Uuid) {+ const indexForRemoving = tagGroups.findIndex(+ (t) => t.uuid === parentTagGroupUuid,+ );+ if (indexForRemoving >= 0) {+ const tagGroup: TS.TagGroup = tagGroups[indexForRemoving];+ if (Pro && tagGroup && tagGroup.locationId) {+ const location: TS.Location = locations.find(+ (l) => l.uuid === tagGroup.locationId,+ );+ if (location) {+ removeLocationTagGroup(location.path, parentTagGroupUuid);+ }+ }++ saveTagLibrary([+ ...tagGroups.slice(0, indexForRemoving),+ ...tagGroups.slice(indexForRemoving + 1),+ ]);+ }+ }++ function addTag(tag: any, parentTagGroupUuid: TS.Uuid) {+ const tgIndex = tagGroups.findIndex(+ (tagGroup) => tagGroup.uuid === parentTagGroupUuid,+ );+ if (tgIndex > -1) {+ const tagGroup = tagGroups[tgIndex];+ let newTags: Array<TS.Tag>;+ if (typeof tag === 'object' && tag !== null) {+ if (tagGroup.children.some((t) => t.title === tag.title)) {+ // tag exist+ return;+ }+ const tagObject: TS.Tag = {+ ...tag,+ textcolor: tag.textcolor, // || tagTextColor,+ color: tag.color, // || tagBackgroundColor+ };+ newTags = [tagObject];+ //tagGroupsReturn = saveTagInt(tagObject, parentTagGroupUuid, tagGroups);+ } else {+ const newTagGroup = {+ ...tagGroup,+ color: tagGroup.color, // ? tagGroup.color : tagBackgroundColor,+ textcolor: tagGroup.textcolor, // ? tagGroup.textcolor : tagTextColor+ };+ newTags = parseNewTags(tag, newTagGroup);+ }+ saveTags(newTags, tgIndex);++ if (Pro && tagGroup && tagGroup.locationId) {+ const location: TS.Location = locations.find(+ (l) => l.uuid === tagGroup.locationId,+ );+ if (location) {+ tagGroup.children = newTags;+ editLocationTagGroup(location.path, tagGroup);+ }+ }+ }+ }++ function editTag(+ tag: TS.Tag,+ parentTagGroupUuid: TS.Uuid,+ origTitle: string,+ ) {+ const indexForEditing = tagGroups.findIndex(+ (t) => t.uuid === parentTagGroupUuid,+ );++ if (indexForEditing > -1) {+ const tagGroup: TS.TagGroup = tagGroups[indexForEditing];+ const newTagGroup: TS.TagGroup = {+ ...tagGroup,+ modified_date: new Date().getTime(),+ children: tagGroup.children.map((t) => {+ if (t.title === origTitle) {+ return tag;+ }+ return t;+ }),+ };++ if (Pro && tagGroup && tagGroup.locationId) {+ const location: TS.Location = locations.find(+ (l) => l.uuid === tagGroup.locationId,+ );+ if (location) {+ editLocationTagGroup(location.path, newTagGroup, true);+ }+ }+ updateTagGroup(newTagGroup);+ }+ }++ function deleteTag(tagTitle: string, parentTagGroupUuid: TS.Uuid) {+ const tagGroup: TS.TagGroup = tagGroups.find(+ (t) => t.uuid === parentTagGroupUuid,+ );++ const tagIndexForRemoving = tagGroup.children.findIndex(+ (tag) => tag.title === tagTitle,+ );+ if (tagIndexForRemoving >= 0) {+ const editedTagGroup: TS.TagGroup = {+ ...tagGroup,+ modified_date: new Date().getTime(),+ children: [+ ...tagGroup.children.slice(0, tagIndexForRemoving),+ ...tagGroup.children.slice(tagIndexForRemoving + 1),+ ],+ };++ if (Pro && tagGroup.locationId) {+ const location: TS.Location = locations.find(+ (l) => l.uuid === tagGroup.locationId,+ );+ if (location) {+ editLocationTagGroup(location.path, editedTagGroup, true);+ }+ }+ updateTagGroup(editedTagGroup);+ }+ }++ function moveTag(+ tagTitle: string,+ fromTagGroupId: TS.Uuid,+ toTagGroupId: TS.Uuid,+ ) {+ let tagIndexForRemoving = -1;+ let indexFromGroup = -1;+ let indexToGroup = -1;+ tagGroups.forEach((tagGroup, index) => {+ if (tagGroup.uuid === fromTagGroupId) {+ indexFromGroup = index;+ }+ if (tagGroup.uuid === toTagGroupId) {+ indexToGroup = index;+ }+ });+ if (indexFromGroup >= 0 && tagGroups[indexFromGroup].children) {+ tagIndexForRemoving = tagGroups[indexFromGroup].children.findIndex(+ (tag) => tag.title === tagTitle,+ );+ }+ if (indexToGroup >= 0 && indexToGroup >= 0 && tagIndexForRemoving >= 0) {+ const newTagLibrary = [...tagGroups];+ const tag = {+ ...tagGroups[indexFromGroup].children[tagIndexForRemoving],+ };+ const found = newTagLibrary[indexToGroup].children.find(+ (t) => t.title === tag.title,+ );+ if (!found) {+ newTagLibrary[indexToGroup].children.push(tag);+ newTagLibrary[indexFromGroup].children = [+ ...newTagLibrary[indexFromGroup].children.slice(+ 0,+ tagIndexForRemoving,+ ),+ ...newTagLibrary[indexFromGroup].children.slice(+ tagIndexForRemoving + 1,+ ),+ ];+ return saveTagLibrary(newTagLibrary);+ }+ console.warn(+ 'Tag with this title already exists in the target tag group',+ );+ }+ }++ function changeTagOrder(+ tagGroupUuid: TS.Uuid,+ fromIndex: number,+ toIndex: number,+ ) {+ const indexFromGroup = tagGroups.findIndex(+ (tagGroup) => tagGroup.uuid === tagGroupUuid,+ );++ if (indexFromGroup > -1) {+ const newTagLibrary = [...tagGroups];+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#swapping_variables+ [+ newTagLibrary[indexFromGroup].children[fromIndex],+ newTagLibrary[indexFromGroup].children[toIndex],+ ] = [+ newTagLibrary[indexFromGroup].children[toIndex],+ newTagLibrary[indexFromGroup].children[fromIndex],+ ];++ saveTagLibrary(newTagLibrary);+ }+ }++ function moveTagGroupUp(parentTagGroupUuid: TS.Uuid) {+ let indexForUpdating = tagGroups.findIndex(+ (t) => t.uuid === parentTagGroupUuid,+ );+ if (indexForUpdating > 0) {+ const secondIndex = indexForUpdating - 1;+ return saveTagLibrary(+ immutablySwapItems(tagGroups, indexForUpdating, secondIndex),+ );+ }+ return tagGroups;+ }++ function moveTagGroupDown(parentTagGroupUuid: TS.Uuid) {+ let indexForUpdating = tagGroups.findIndex(+ (t) => t.uuid === parentTagGroupUuid,+ );+ if (indexForUpdating >= 0 && indexForUpdating < tagGroups.length - 1) {+ const secondIndex = indexForUpdating + 1;+ return saveTagLibrary(+ immutablySwapItems(tagGroups, indexForUpdating, secondIndex),+ );+ }+ return tagGroups;+ }++ function moveTagGroup(tagGroupUuid: TS.Uuid, position: number) {+ let indexForUpdating = tagGroups.findIndex((t) => t.uuid === tagGroupUuid);+ if (indexForUpdating > -1 && indexForUpdating !== position) {+ const tagGroupsReturn = Array.from(tagGroups);+ const [removed] = tagGroupsReturn.splice(indexForUpdating, 1);+ tagGroupsReturn.splice(position, 0, removed);+ saveTagLibrary(tagGroupsReturn);+ }+ }++ function sortTagGroup(parentTagGroupUuid: TS.Uuid) {+ let indexForUpdating = tagGroups.findIndex(+ (t) => t.uuid === parentTagGroupUuid,+ );+ if (indexForUpdating > -1) {+ saveTagLibrary([+ ...tagGroups.slice(0, indexForUpdating),+ {+ ...tagGroups[indexForUpdating],+ children: tagGroups[indexForUpdating].children.sort((a, b) =>+ a.title > b.title ? 1 : a.title < b.title ? -1 : 0,+ ),+ },+ ...tagGroups.slice(indexForUpdating + 1),+ ]);+ }+ }++ function importTagGroups(newEntries: Array<TS.TagGroup>, replace = false) {+ const arr = replace ? [] : [...tagGroups];+ // console.log(arr);+ // @ts-ignore+ if (newEntries[0] && newEntries[0].key) {+ // TODO test this migration+ newEntries.forEach((newTg: TS.TagGroup, index) => {+ // migration of old tag groups 2.9 or less in the new version 3.0-present+ // @ts-ignore+ if (newTg.key === tagGroups.uuid || newTg.key !== tagGroups.uuid) {+ newTg = {+ title: newTg.title,+ // @ts-ignore+ uuid: newTg.key,+ children: newTg.children,+ };+ const tagsArr = [];+ newTg.children.forEach((tag) => {+ tagsArr.push(tag);+ newTg.children = tagsArr;+ arr.push(newTg);+ });+ }+ });+ } else {+ newEntries.forEach((tagGroup) => {+ const index = arr.findIndex((obj) => obj.uuid === tagGroup.uuid);+ if (index > -1) {+ tagGroup.children.forEach((tag) => {+ const stateTag = arr[index].children.find(+ (obj) => obj.title === tag.title,+ );+ if (stateTag === undefined) {+ arr[index].children.push(tag);+ }+ });+ if (tagGroup.locationId) {+ arr[index].locationId = tagGroup.locationId;+ }+ } else {+ arr.push(tagGroup);+ }+ });+ }++ saveTagLibrary(arr);+ }+const context = useMemo(() => {return {extractContent,@@ -919,8 +1445,29 @@ export const TaggingActionsContextProvider = ({removeTagsFromEntry,removeAllTags,collectTagsFromLocation,+ createTagGroup,+ mergeTagGroup,+ removeTagGroup,+ addTag,+ editTag,+ deleteTag,+ moveTag,+ changeTagOrder,+ moveTagGroupUp,+ moveTagGroupDown,+ moveTagGroup,+ sortTagGroup,+ updateTagGroup,+ importTagGroups,+ refreshTagsFromLocation,};- }, [persistTagsInSidecarFile, addTagsToLibrary, currentDirectoryEntries]);+ }, [+ tagGroups,+ persistTagsInSidecarFile,+ addTagsToLibrary,+ currentDirectoryEntries,+ saveTagInLocation,+ ]);return (<TaggingActionsContext.Provider value={context}>diff --git a/src/renderer/hooks/ThumbGenerationContextProvider.tsx b/src/renderer/hooks/ThumbGenerationContextProvider.tsxindex dc5125266..8185eb99b 100644--- a/src/renderer/hooks/ThumbGenerationContextProvider.tsx+++ b/src/renderer/hooks/ThumbGenerationContextProvider.tsx@@ -18,6 +18,12 @@import React, { createContext, useEffect, useMemo, useRef } from 'react';import { useSelector } from 'react-redux';+import {+ extractContainingDirectoryPath,+ extractFileName,+ normalizePath,+ getMetaDirectoryPath,+} from '@tagspaces/tagspaces-common/paths';import {getEnableWS,getShowUnixHiddenEntries,@@ -27,7 +33,7 @@ import PlatformIO from '-/services/platform-facade';import { TS } from '-/tagspaces.namespace';import AppConfig from '-/AppConfig';import {- getThumbnailURLPromise,+ generateThumbnailPromise,supportedContainers,supportedImgs,supportedMisc,@@ -39,6 +45,8 @@ import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { loadCurrentDirMeta } from '-/services/meta-loader';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';+import { base64ToBlob } from '-/utils/dom';+import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';type ThumbGenerationContextData = {generateThumbnails: (dirEntries: TS.FileSystemEntry[]) => Promise<boolean>;@@ -63,6 +71,7 @@ export const ThumbGenerationContextProvider = ({updateCurrentDirEntries,} = useDirectoryContentContext();const { currentLocation } = useCurrentLocationContext();+ const { saveBinaryFilePromise } = usePlatformFacadeContext();const { pageFiles, page } = usePaginationContext();const { setGeneratingThumbs } = useNotificationContext();const useGenerateThumbnails = useSelector(getUseGenerateThumbnails);@@ -251,6 +260,160 @@ export const ThumbGenerationContextProvider = ({});}+ function getThumbnailURLPromise(+ filePath: string,+ ): Promise<{ filePath: string; tmbPath?: string }> {+ return PlatformIO.getPropertiesPromise(filePath)+ .then((origStats) => {+ const thumbFilePath = getThumbFileLocation(filePath);+ return PlatformIO.getPropertiesPromise(thumbFilePath)+ .then((stats) => {+ if (stats) {+ // Thumbnail exists+ if (origStats.lmdt > stats.lmdt) {+ // Checking if is up to date+ return createThumbnailPromise(+ filePath,+ origStats.size,+ thumbFilePath,+ origStats.isFile,+ )+ .then((tmbPath) => ({ filePath, tmbPath }))+ .catch((err) => {+ console.warn('Thumb generation failed ' + err);+ return Promise.resolve({+ filePath,+ tmbPath: thumbFilePath,+ });+ });+ } else {+ // Tmb up to date+ return Promise.resolve({ filePath, tmbPath: thumbFilePath });+ }+ } else {+ // Thumbnail does not exists+ return createThumbnailPromise(+ filePath,+ origStats.size,+ thumbFilePath,+ origStats.isFile,+ )+ .then((tmbPath) => {+ if (tmbPath !== undefined) {+ return { filePath, tmbPath };+ } else {+ return { filePath };+ }+ })+ .catch((err) => {+ console.warn('Thumb generation failed ' + err);+ return Promise.resolve({ filePath });+ });+ }+ })+ .catch((err) => {+ console.warn('Error getting tmb properties ' + err);+ return Promise.resolve({ filePath });+ });+ })+ .catch((err) => {+ console.warn('Error getting file properties ' + err);+ return Promise.resolve({ filePath });+ });+ }++ function getThumbFileLocation(filePath: string) {+ const containingFolder = extractContainingDirectoryPath(+ filePath,+ PlatformIO.getDirSeparator(),+ );+ const metaFolder = getMetaDirectoryPath(+ containingFolder,+ PlatformIO.getDirSeparator(),+ );+ return (+ metaFolder ++ PlatformIO.getDirSeparator() ++ extractFileName(filePath, PlatformIO.getDirSeparator()) ++ AppConfig.thumbFileExt+ );+ }++ function createThumbnailPromise(+ filePath: string,+ fileSize: number,+ thumbFilePath: string,+ isFile: boolean,+ ): Promise<string | undefined> {+ const metaDirectory = extractContainingDirectoryPath(+ thumbFilePath,+ PlatformIO.getDirSeparator(),+ );+ const fileDirectory = isFile+ ? extractContainingDirectoryPath(filePath, PlatformIO.getDirSeparator())+ : filePath;+ const normalizedFileDirectory = normalizePath(fileDirectory);+ if (normalizedFileDirectory.endsWith(AppConfig.metaFolder)) {+ return Promise.resolve(undefined); // prevent creating thumbs in meta/.ts folder+ }+ return PlatformIO.checkDirExist(metaDirectory).then((exist) => {+ if (!exist) {+ return PlatformIO.createDirectoryPromise(metaDirectory).then(() => {+ return createThumbnailSavePromise(filePath, fileSize, thumbFilePath);+ });+ } else {+ return createThumbnailSavePromise(filePath, fileSize, thumbFilePath);+ }+ });+ }++ function createThumbnailSavePromise(+ filePath: string,+ fileSize: number,+ thumbFilePath: string,+ ): Promise<string | undefined> {+ return generateThumbnailPromise(filePath, fileSize)+ .then((dataURL) => {+ if (dataURL && dataURL.length) {+ return saveThumbnailPromise(thumbFilePath, dataURL)+ .then(() => thumbFilePath)+ .catch((err) => {+ console.warn('Thumb saving failed ' + err + ' for ' + filePath);+ return Promise.resolve(undefined);+ });+ }+ return undefined; // thumbFilePath;+ })+ .catch((err) => {+ console.warn('Thumb generation failed ' + err + ' for ' + filePath);+ return Promise.resolve(undefined);+ });+ }++ function saveThumbnailPromise(filePath, dataURL) {+ if (!dataURL || dataURL.length < 7) {+ // data:,+ return Promise.reject(new Error('Invalid dataURL'));+ }+ const baseString = dataURL.split(',').pop();+ const content = base64ToBlob(baseString);+ return saveBinaryFilePromise(+ { path: filePath },+ content, //PlatformIO.isMinio() ? content : content.buffer,+ true,+ )+ .then(() => filePath)+ .catch((error) => {+ console.warn(+ 'Saving thumbnail for ' ++ filePath ++ ' failed with ' ++ JSON.stringify(error),+ );+ return Promise.reject(new Error('Saving tmb failed for: ' + filePath));+ });+ }+const context = useMemo(() => {return {generateThumbnails,diff --git a/src/renderer/hooks/useEditedKanBanMetaContext.tsx b/src/renderer/hooks/useEditedKanBanMetaContext.tsxnew file mode 100644index 000000000..39741f796--- /dev/null+++ b/src/renderer/hooks/useEditedKanBanMetaContext.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 { EditedKanBanMetaContext } from '-/hooks/EditedKanBanMetaContextProvider';++export const useEditedKanBanMetaContext = () =>+ useContext(EditedKanBanMetaContext);diff --git a/src/renderer/hooks/useEditedTagLibraryContext.tsx b/src/renderer/hooks/useEditedTagLibraryContext.tsxnew file mode 100644index 000000000..e75109c44--- /dev/null+++ b/src/renderer/hooks/useEditedTagLibraryContext.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 { EditedTagLibraryContext } from './EditedTagLibraryContextProvider';++export const useEditedTagLibraryContext = () =>+ useContext(EditedTagLibraryContext);diff --git a/src/renderer/hooks/useTagGroupsLocationContext.tsx b/src/renderer/hooks/useTagGroupsLocationContext.tsxnew file mode 100644index 000000000..b229c9fbd--- /dev/null+++ b/src/renderer/hooks/useTagGroupsLocationContext.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 { TagGroupsLocationContext } from './TagGroupsLocationContextProvider';++export const useTagGroupsLocationContext = () =>+ useContext(TagGroupsLocationContext);diff --git a/src/renderer/perspectives/grid/components/GridCell.tsx b/src/renderer/perspectives/grid/components/GridCell.tsxindex c983d1a32..b54ac7663 100644--- a/src/renderer/perspectives/grid/components/GridCell.tsx+++ b/src/renderer/perspectives/grid/components/GridCell.tsx@@ -134,14 +134,13 @@ function GridCell(props: Props) {usePerspectiveSettingsContext();const { metaActions } = useEditedEntryMetaContext();const { selectedEntries, selectEntry } = useSelectedEntriesContext();- const { addTags, editTagForEntry } = useTaggingActionsContext();+ const { addTags, addTag, editTagForEntry } = useTaggingActionsContext();const { readOnlyMode } = useCurrentLocationContext();const supportedFileTypes = useSelector(getSupportedFileTypes);const reorderTags: boolean = useSelector(isReorderTags);const locations: Array<TS.Location> = useSelector(getLocations);//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>(@@ -196,7 +195,7 @@ function GridCell(props: Props) {};const handleAddTag = (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => {- dispatch(AppActions.addTag(tag, parentTagGroupUuid));+ addTag(tag, parentTagGroupUuid);};// remove isNewFile on Cell click it will open file in editModediff --git a/src/renderer/perspectives/list/components/RowCell.tsx b/src/renderer/perspectives/list/components/RowCell.tsxindex 827cd45ba..a43d902ea 100644--- a/src/renderer/perspectives/list/components/RowCell.tsx+++ b/src/renderer/perspectives/list/components/RowCell.tsx@@ -134,11 +134,10 @@ function RowCell(props: Props) {const { selectedEntries, selectEntry } = useSelectedEntriesContext();const { entrySize, showTags, thumbnailMode } =usePerspectiveSettingsContext();- const { addTags, editTagForEntry } = useTaggingActionsContext();+ const { addTags, addTag, editTagForEntry } = useTaggingActionsContext();const { readOnlyMode } = useCurrentLocationContext();const supportedFileTypes = useSelector(getSupportedFileTypes);const reorderTags: boolean = useSelector(isReorderTags);- const dispatch: AppDispatch = useDispatch();// You can use the dispatch function to dispatch actionsconst handleEditTag = (path: string, tag: TS.Tag, newTagTitle?: string) => {@@ -149,7 +148,7 @@ function RowCell(props: Props) {};const handleAddTag = (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => {- dispatch(AppActions.addTag(tag, parentTagGroupUuid));+ addTag(tag, parentTagGroupUuid);};// remove isNewFile on Cell click it will open file in editModediff --git a/src/renderer/reducers/app.ts b/src/renderer/reducers/app.tsindex 673c8b3e7..f689daa3c 100644--- a/src/renderer/reducers/app.ts+++ b/src/renderer/reducers/app.ts@@ -19,9 +19,8 @@import AppConfig from '-/AppConfig';import { getURLParameter } from '-/utils/dom';import PlatformIO from '../services/platform-facade';-import { mergeByProp, toFsEntry } from '-/services/utils-io';+import { mergeByProp } from '-/services/utils-io';import i18n from '../services/i18n';-import { actions as tagLibraryActions } from './taglibrary';import {actions as SettingsActions,getCheckForUpdateOnStartup,@@ -29,11 +28,6 @@ import {isGlobalKeyBindingEnabled,} from '-/reducers/settings';import { TS } from '-/tagspaces.namespace';-import {- addTag,- getTagLibrary,- setTagLibrary,-} from '-/services/taglibrary-utils';import { getProTeaserSlideIndex } from '-/content/ProTeaserSlides';import { extensionsFound } from '-/extension-config';@@ -70,7 +64,7 @@ export const types = {SET_CURRENLOCATIONID: 'APP/SET_CURRENLOCATIONID',//SET_LAST_SELECTED_ENTRY: 'APP/SET_LAST_SELECTED_ENTRY',//SET_SELECTED_ENTRIES: 'APP/SET_SELECTED_ENTRIES',- SET_TAG_LIBRARY_CHANGED: 'APP/SET_TAG_LIBRARY_CHANGED',+ //SET_TAG_LIBRARY_CHANGED: 'APP/SET_TAG_LIBRARY_CHANGED',SET_FILEDRAGGED: 'APP/SET_FILEDRAGGED',TOGGLE_EDIT_TAG_DIALOG: 'APP/TOGGLE_EDIT_TAG_DIALOG',TOGGLE_ABOUT_DIALOG: 'APP/TOGGLE_ABOUT_DIALOG',@@ -303,9 +297,9 @@ export default (state: any = initialState, action: any) => {}return state;}*/- case types.SET_TAG_LIBRARY_CHANGED: {+ /*case types.SET_TAG_LIBRARY_CHANGED: {return { ...state, tagLibraryChanged: !state.tagLibraryChanged };- }+ }*/case types.TOGGLE_EDIT_TAG_DIALOG: {return {...state,@@ -654,7 +648,7 @@ export const actions = {initApp: () => (dispatch: (action) => void, getState: () => any) => {disableBackGestureMac();// migrate TagLibrary from redux state- const { taglibrary } = getState();+ /*const { taglibrary } = getState();if (taglibrary && taglibrary.length > 0) {try {setTagLibrary(taglibrary);@@ -662,7 +656,7 @@ export const actions = {} catch (e) {console.log('migrate TagLibrary failed', e);}- }+ }*/dispatch(SettingsActions.setZoomRestoreApp());dispatch(SettingsActions.upgradeSettings()); // TODO call this only on app version update@@ -853,7 +847,7 @@ export const actions = {type: types.SET_SELECTED_ENTRIES,selectedEntries}),*/- addTag:+ /*addTag:(tag: any, parentTagGroupUuid: TS.Uuid) =>(dispatch: (action) => void, getState: () => any) => {const { locations } = getState();@@ -862,7 +856,7 @@ export const actions = {},tagLibraryChanged: () => ({type: types.SET_TAG_LIBRARY_CHANGED,- }),+ }),*//*openDirectory: (directoryPath: string) => () => {PlatformIO.openDirectory(directoryPath);},*/diff --git a/src/renderer/reducers/index.ts b/src/renderer/reducers/index.tsindex 6224ec613..c5b332762 100644--- a/src/renderer/reducers/index.ts+++ b/src/renderer/reducers/index.ts@@ -23,7 +23,7 @@ import AppConfig from '-/AppConfig';import settings from './settings';import app from './app';import locations from './locations';-import taglibrary from './taglibrary';+//import taglibrary from './taglibrary';import searches from './searches';const externalLocations = window.ExtLocations || false;@@ -110,7 +110,7 @@ const rootReducer = persistCombineReducers(rootPersistConfig, {settings,app,locations: externalLocations ? () => externalLocations : locations,- taglibrary, // externalTagLibrary ? () => externalTagLibrary : taglibrary,+ // taglibrary, // externalTagLibrary ? () => externalTagLibrary : taglibrary,searches: externalSearches ? () => externalSearches : searches,});diff --git a/src/renderer/reducers/taglibrary.ts b/src/renderer/reducers/taglibrary.tsindex 4905ce12d..0464b389b 100644--- a/src/renderer/reducers/taglibrary.ts+++ b/src/renderer/reducers/taglibrary.ts@@ -1,4 +1,5 @@-/**+/*+/!*** TagSpaces - universal file and folder organizer* Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)*@@ -14,7 +15,7 @@* 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 {immutablySwapItems,formatDateTime4Tag,@@ -207,76 +208,6 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {}return state;}- /* case types.UPDATE_TAG: {- let tagIndexForUpdating = -1;- let tagGroupIndexForUpdating = -1;- state.forEach((tagGroup, index) => {- if (tagGroup.uuid === action.uuid) {- tagGroup.children.forEach((tag, tagIndex) => {- if (tag.title === action.origTitle) {- tagIndexForUpdating = tagIndex;- tagGroupIndexForUpdating = index;- }- });- }- });- if (tagIndexForUpdating >= 0) {- const modifiedEntry = extend({ created_date: new Date() }, action.tag, {- modified_date: new Date()- });- return [- ...state.slice(0, tagGroupIndexForUpdating),- {- ...state[tagGroupIndexForUpdating],- children: [- ...state[tagGroupIndexForUpdating].children.slice(- 0,- tagIndexForUpdating- ),- modifiedEntry,- ...state[tagGroupIndexForUpdating].children.slice(- tagIndexForUpdating + 1- )- ]- },- ...state.slice(tagGroupIndexForUpdating + 1)- ];- }- return state;- } */- /* case types.REMOVE_TAG: {- let tagIndexForRemoving = -1;- let tagGroupIndexForEditing = -1;- state.forEach((tagGroup, index) => {- if (tagGroup.uuid === action.uuid) {- tagGroup.children.forEach((tag, tagIndex) => {- if (tag.title === action.tagTitle) {- tagIndexForRemoving = tagIndex;- tagGroupIndexForEditing = index;- }- });- }- });- if (tagIndexForRemoving >= 0) {- return [- ...state.slice(0, tagGroupIndexForEditing),- {- ...state[tagGroupIndexForEditing],- children: [- ...state[tagGroupIndexForEditing].children.slice(- 0,- tagIndexForRemoving- ),- ...state[tagGroupIndexForEditing].children.slice(- tagIndexForRemoving + 1- )- ]- },- ...state.slice(tagGroupIndexForEditing + 1)- ];- }- return state;- } */case types.MOVE_TAG_GROUP_DOWN: {let indexForUpdating = -1;state.forEach((tagGroup, index) => {@@ -519,13 +450,9 @@ export const actions = {type: types.REMOVE_TAGGROUP,uuid: parentTagGroupUuid,}),- /* addTagGroup: (entry: TS.TagGroup) => ({- type: types.ADD_TAGGROUP,- entry- }), */- /**+ /!*** @deprecated use /services/taglibrary-utils/mergeTagGroup instead- */+ *!/mergeTagGroup:(entry: TS.TagGroup) =>(dispatch: (actions: Object) => void, getState: () => any) => {@@ -626,16 +553,6 @@ export const actions = {}dispatch(actions.editTagGroupInt(newTagGroup));},- /* editTagInt: (- tag: TS.Tag,- parentTagGroupUuid: TS.Uuid,- origTitle: string- ) => ({- type: types.UPDATE_TAG,- tag,- uuid: parentTagGroupUuid,- origTitle- }), */deleteTag:(tagTitle: string, parentTagGroupUuid: TS.Uuid) =>(dispatch: (actions: Object) => void, getState: () => any) => {@@ -673,11 +590,6 @@ export const actions = {dispatch(actions.editTagGroupInt(editedTagGroup));}},- /* deleteTagInt: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => ({- type: types.REMOVE_TAG,- tagTitle,- uuid: parentTagGroupUuid- }), */moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => ({type: types.MOVE_TAG_GROUP,uuid: tagGroupUuid,@@ -720,22 +632,6 @@ export const actions = {entries,replace,}),- /**- * GraphQL API return TagGroup Tags array like String- * This migrate tagGroups model to children []- * @param entries- */- /* addTagGroups: (entries: Array<any>) => (- dispatch: (actions: Object) => void- ) => {- if (entries && entries.length > 0) {- const tagGroups: Array<TagGroup> = entries.map(tagGroup => {- const { children, ...tagGroupProps } = tagGroup;- return { children: JSON.parse(children), ...tagGroupProps };- });- dispatch(actions.importTagGroups(tagGroups, true));- }- }, */};// Selectors@@ -754,3 +650,4 @@ export const getAllTags = (state: any) => {a.title > b.title ? 1 : a.title < b.title ? -1 : 0,);};+*/diff --git a/src/renderer/services/taglibrary-utils.ts b/src/renderer/services/taglibrary-utils.tsindex 59eb276a2..f1be13419 100644--- a/src/renderer/services/taglibrary-utils.ts+++ b/src/renderer/services/taglibrary-utils.ts@@ -1,19 +1,15 @@import { TS } from '-/tagspaces.namespace';-import { Pro } from '-/pro';import {formatDateTime4Tag,- immutablySwapItems,prepareTagGroupForExport,} from '@tagspaces/tagspaces-common/misc';import versionMeta from '-/version.json';-import { getUuid } from '@tagspaces/tagspaces-common/utils-io';-import { parseNewTags, saveAsTextFile } from '-/services/utils-io';-import AppConfig from '-/AppConfig';+import { saveAsTextFile } from '-/services/utils-io';import defaultTagLibrary from '../reducers/taglibrary-default';export const tagLibraryKey = 'tsTagLibrary';-export function getTagLibrary(): Array<TS.TagGroup> {+export function getTagLibrary(): TS.TagGroup[] {if (window.ExtTagLibrary) {return window.ExtTagLibrary;}@@ -51,155 +47,6 @@ export function getAllTags(tagGroups?: Array<TS.TagGroup>) {);}-export function removeTagGroup(- parentTagGroupUuid: TS.Uuid,- tagGroups: Array<TS.TagGroup>,- locations: Array<TS.Location>,-): Array<TS.TagGroup> {- const indexForRemoving = tagGroups.findIndex(- (t) => t.uuid === parentTagGroupUuid,- );- if (indexForRemoving >= 0) {- const tagGroup: TS.TagGroup = tagGroups[indexForRemoving];- if (Pro && tagGroup && tagGroup.locationId) {- const location: TS.Location = locations.find(- (l) => l.uuid === tagGroup.locationId,- );- if (location) {- Pro.MetaOperations.removeTagGroup(location.path, parentTagGroupUuid);- }- }-- return setTagLibrary([- ...tagGroups.slice(0, indexForRemoving),- ...tagGroups.slice(indexForRemoving + 1),- ]);- }-- return tagGroups;-}--export function moveTagGroupUp(- parentTagGroupUuid: TS.Uuid,- tagGroups: Array<TS.TagGroup>,-): Array<TS.TagGroup> {- let indexForUpdating = tagGroups.findIndex(- (t) => t.uuid === parentTagGroupUuid,- );- if (indexForUpdating > 0) {- const secondIndex = indexForUpdating - 1;- return setTagLibrary(- immutablySwapItems(tagGroups, indexForUpdating, secondIndex),- );- }- return tagGroups;-}--export function moveTagGroupDown(- parentTagGroupUuid: TS.Uuid,- tagGroups: Array<TS.TagGroup>,-): Array<TS.TagGroup> {- let indexForUpdating = tagGroups.findIndex(- (t) => t.uuid === parentTagGroupUuid,- );- if (indexForUpdating >= 0 && indexForUpdating < tagGroups.length - 1) {- const secondIndex = indexForUpdating + 1;- return setTagLibrary(- immutablySwapItems(tagGroups, indexForUpdating, secondIndex),- );- }- return tagGroups;-}--export function moveTagGroup(- tagGroupUuid: TS.Uuid,- position: number,- tagGroups: Array<TS.TagGroup>,-): Array<TS.TagGroup> {- let indexForUpdating = tagGroups.findIndex((t) => t.uuid === tagGroupUuid);- if (indexForUpdating > -1 && indexForUpdating !== position) {- const tagGroupsReturn = Array.from(tagGroups);- const [removed] = tagGroupsReturn.splice(indexForUpdating, 1);- tagGroupsReturn.splice(position, 0, removed);- return setTagLibrary(tagGroupsReturn);- }- return tagGroups;-}--export function sortTagGroup(- parentTagGroupUuid: TS.Uuid,- tagGroups: Array<TS.TagGroup>,-): Array<TS.TagGroup> {- let indexForUpdating = tagGroups.findIndex(- (t) => t.uuid === parentTagGroupUuid,- );- if (indexForUpdating > -1) {- return setTagLibrary([- ...tagGroups.slice(0, indexForUpdating),- {- ...tagGroups[indexForUpdating],- children: tagGroups[indexForUpdating].children.sort((a, b) =>- a.title > b.title ? 1 : a.title < b.title ? -1 : 0,- ),- },- ...tagGroups.slice(indexForUpdating + 1),- ]);- }- return tagGroups;-}--export function importTagGroups(- newEntries: Array<TS.TagGroup>,- tagGroups: Array<TS.TagGroup>,- replace = false,-): Array<TS.TagGroup> {- const arr = replace ? [] : [...tagGroups];- // console.log(arr);- // @ts-ignore- if (newEntries[0] && newEntries[0].key) {- // TODO test this migration- newEntries.forEach((newTg: TS.TagGroup, index) => {- // migration of old tag groups 2.9 or less in the new version 3.0-present- // @ts-ignore- if (newTg.key === tagGroups.uuid || newTg.key !== tagGroups.uuid) {- newTg = {- title: newTg.title,- // @ts-ignore- uuid: newTg.key,- children: newTg.children,- };- const tagsArr = [];- newTg.children.forEach((tag) => {- tagsArr.push(tag);- newTg.children = tagsArr;- arr.push(newTg);- });- }- });- } else {- newEntries.forEach((tagGroup) => {- const index = arr.findIndex((obj) => obj.uuid === tagGroup.uuid);- if (index > -1) {- tagGroup.children.forEach((tag) => {- const stateTag = arr[index].children.find(- (obj) => obj.title === tag.title,- );- if (stateTag === undefined) {- arr[index].children.push(tag);- }- });- if (tagGroup.locationId) {- arr[index].locationId = tagGroup.locationId;- }- } else {- arr.push(tagGroup);- }- });- }-- return setTagLibrary(arr);-}-export function exportTagGroups(entry: Array<TS.TagGroup>,settingsVersion = 3,@@ -232,343 +79,6 @@ export function exportTagGroups(console.log('Tag library exported...');}-export function createTagGroup(- entry: TS.TagGroup,- tagGroups: Array<TS.TagGroup>,- location?: TS.Location,-): Array<TS.TagGroup> {- const newEntry = {- ...entry,- created_date: new Date().getTime(),- modified_date: new Date().getTime(),- };- if (Pro && location) {- Pro.MetaOperations.createTagGroup(location.path, newEntry);- }- return setTagLibrary([...tagGroups, newEntry]);-}--export function editTag(- tag: TS.Tag,- parentTagGroupUuid: TS.Uuid,- origTitle: string,- tagGroups: Array<TS.TagGroup>,- locations: Array<TS.Location>,-): Array<TS.TagGroup> {- const indexForEditing = tagGroups.findIndex(- (t) => t.uuid === parentTagGroupUuid,- );-- if (indexForEditing > -1) {- const tagGroup: TS.TagGroup = tagGroups[indexForEditing];- const newTagGroup: TS.TagGroup = {- ...tagGroup,- modified_date: new Date().getTime(),- children: tagGroup.children.map((t) => {- if (t.title === origTitle) {- return tag;- }- return t;- }),- };-- if (Pro && tagGroup && tagGroup.locationId) {- const location: TS.Location = locations.find(- (l) => l.uuid === tagGroup.locationId,- );- if (location) {- Pro.MetaOperations.editTagGroup(location.path, newTagGroup, true);- }- }- return updateTagGroup(newTagGroup, tagGroups);- }- return tagGroups;-}--export function moveTag(- tagTitle: string,- fromTagGroupId: TS.Uuid,- toTagGroupId: TS.Uuid,- tagGroups: Array<TS.TagGroup>,-) {- let tagIndexForRemoving = -1;- let indexFromGroup = -1;- let indexToGroup = -1;- tagGroups.forEach((tagGroup, index) => {- if (tagGroup.uuid === fromTagGroupId) {- indexFromGroup = index;- }- if (tagGroup.uuid === toTagGroupId) {- indexToGroup = index;- }- });- if (indexFromGroup >= 0 && tagGroups[indexFromGroup].children) {- tagIndexForRemoving = tagGroups[indexFromGroup].children.findIndex(- (tag) => tag.title === tagTitle,- );- }- if (indexToGroup >= 0 && indexToGroup >= 0 && tagIndexForRemoving >= 0) {- const newTagLibrary = [...tagGroups];- const tag = { ...tagGroups[indexFromGroup].children[tagIndexForRemoving] };- const found = newTagLibrary[indexToGroup].children.find(- (t) => t.title === tag.title,- );- if (!found) {- newTagLibrary[indexToGroup].children.push(tag);- newTagLibrary[indexFromGroup].children = [- ...newTagLibrary[indexFromGroup].children.slice(0, tagIndexForRemoving),- ...newTagLibrary[indexFromGroup].children.slice(- tagIndexForRemoving + 1,- ),- ];- return setTagLibrary(newTagLibrary);- }- console.warn('Tag with this title already exists in the target tag group');- }- return tagGroups;-}--export function changeTagOrder(- tagGroupUuid: TS.Uuid,- fromIndex: number,- toIndex: number,- tagGroups: Array<TS.TagGroup>,-) {- const indexFromGroup = tagGroups.findIndex(- (tagGroup) => tagGroup.uuid === tagGroupUuid,- );-- if (indexFromGroup > -1) {- const newTagLibrary = [...tagGroups];- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#swapping_variables- [- newTagLibrary[indexFromGroup].children[fromIndex],- newTagLibrary[indexFromGroup].children[toIndex],- ] = [- newTagLibrary[indexFromGroup].children[toIndex],- newTagLibrary[indexFromGroup].children[fromIndex],- ];-- return setTagLibrary(newTagLibrary);- }- return tagGroups;-}--export function editTagGroup(- entry: TS.TagGroup,- tagGroups: Array<TS.TagGroup>,- locations: Array<TS.Location>,-) {- const editedTagGroup = {- ...entry,- modified_date: new Date().getTime(),- };-- if (Pro && entry.locationId) {- const location: TS.Location = locations.find(- (l) => l.uuid === entry.locationId,- );- if (location) {- Pro.MetaOperations.editTagGroup(location.path, editedTagGroup);- }- }- return updateTagGroup(editedTagGroup, tagGroups);-}--export function deleteTag(- tagTitle: string,- parentTagGroupUuid: TS.Uuid,- tagGroups: Array<TS.TagGroup>,- locations: Array<TS.Location>,-) {- const tagGroup: TS.TagGroup = tagGroups.find(- (t) => t.uuid === parentTagGroupUuid,- );-- const tagIndexForRemoving = tagGroup.children.findIndex(- (tag) => tag.title === tagTitle,- );- if (tagIndexForRemoving >= 0) {- const editedTagGroup: TS.TagGroup = {- ...tagGroup,- modified_date: new Date().getTime(),- children: [- ...tagGroup.children.slice(0, tagIndexForRemoving),- ...tagGroup.children.slice(tagIndexForRemoving + 1),- ],- };-- if (Pro && tagGroup.locationId) {- const location: TS.Location = locations.find(- (l) => l.uuid === tagGroup.locationId,- );- if (location) {- Pro.MetaOperations.editTagGroup(location.path, editedTagGroup, true);- }- }- return updateTagGroup(editedTagGroup, tagGroups);- }- return tagGroups;-}--export function addTag(- tag: any,- parentTagGroupUuid: TS.Uuid,- tagGroups: Array<TS.TagGroup>,- locations: Array<TS.Location>,-) {- // const { tagTextColor, tagBackgroundColor } = settings;- let tagGroupsReturn = tagGroups;- const tagGroup: TS.TagGroup = tagGroups.find(- (t) => t.uuid === parentTagGroupUuid,- );-- let newTags: Array<TS.Tag>;- if (typeof tag === 'object' && tag !== null) {- if (tagGroup.children.some((t) => t.title === tag.title)) {- // tag exist- return;- }- const tagObject: TS.Tag = {- ...tag,- textcolor: tag.textcolor, // || tagTextColor,- color: tag.color, // || tagBackgroundColor- };- newTags = [tagObject];- tagGroupsReturn = addTagInt(tagObject, parentTagGroupUuid, tagGroups);- } else {- const newTagGroup = {- ...tagGroup,- color: tagGroup.color, // ? tagGroup.color : tagBackgroundColor,- textcolor: tagGroup.textcolor, // ? tagGroup.textcolor : tagTextColor- };- newTags = parseNewTags(tag, newTagGroup);- tagGroupsReturn = addTags(newTags, newTagGroup, tagGroups);- }-- if (Pro && tagGroup && tagGroup.locationId) {- // const { locations } = getState();- const location: TS.Location = locations.find(- (l) => l.uuid === tagGroup.locationId,- );- if (location) {- tagGroup.children = newTags;- Pro.MetaOperations.editTagGroup(location.path, tagGroup);- }- }- return tagGroupsReturn;-}--export function mergeTagGroup(- entry: TS.TagGroup,- tagGroups: Array<TS.TagGroup>,- locations?: Array<TS.Location>,-) {- if (Pro && entry.locationId && locations) {- const location: TS.Location = locations.find(- (l) => l.uuid === entry.locationId,- );- if (location) {- Pro.MetaOperations.mergeTagGroup(location.path, entry);- }- }- const indexForEditing = tagGroups.findIndex((obj) => obj.uuid === entry.uuid);- if (indexForEditing > -1) {- const tags = [...tagGroups[indexForEditing].children, ...entry.children];- tags.splice(0, tags.length - AppConfig.maxCollectedTag);- return setTagLibrary([- ...tagGroups.slice(0, indexForEditing),- {- uuid: entry.uuid,- title: entry.title,- children: tags,- created_date: entry.created_date,- modified_date: new Date().getTime(),- },- ...tagGroups.slice(indexForEditing + 1),- ]);- }- return setTagLibrary([- ...tagGroups,- {- uuid: entry.uuid || getUuid(),- title: entry.title,- color: entry.color,- textcolor: entry.textcolor,- children: entry.children,- created_date: new Date().getTime(),- modified_date: new Date().getTime(),- },- ]);-}--function addTags(- tags: Array<TS.Tag>,- tagGroup: TS.TagGroup,- tagGroups: Array<TS.TagGroup>,-) {- let indexForEditing = tagGroups.findIndex((tg) => tg.uuid === tagGroup.uuid);- if (indexForEditing >= 0) {- return setTagLibrary([- ...tagGroups.slice(0, indexForEditing),- {- ...tagGroups[indexForEditing],- children: tags,- },- ...tagGroups.slice(indexForEditing + 1),- ]);- }- return tagGroups;-}--function addTagInt(- newTag: TS.Tag,- parentTagGroupUuid: TS.Uuid,- tagGroups: Array<TS.TagGroup>,-) {- let indexForEditing = tagGroups.findIndex(- (tagGroup) => tagGroup.uuid === parentTagGroupUuid,- );-- if (indexForEditing >= 0) {- const taggroupTags = tagGroups[indexForEditing].children;- if (!taggroupTags.some((tag) => tag.title === newTag.title)) {- return setTagLibrary([- ...tagGroups.slice(0, indexForEditing),- {- ...tagGroups[indexForEditing],- children: [...taggroupTags, newTag],- },- ...tagGroups.slice(indexForEditing + 1),- ]);- }- }- return tagGroups;-}--function updateTagGroup(- entry: TS.TagGroup,- tagGroups: Array<TS.TagGroup>,-): Array<TS.TagGroup> {- let indexForEditing = tagGroups.findIndex(- (tagGroup) => tagGroup.uuid === entry.uuid,- );-- if (indexForEditing >= 0) {- const modifiedEntry = {- ...entry,- ...(!entry.created_date && { created_date: new Date().getTime() }),- ...(!entry.modified_date && { modified_date: new Date().getTime() }),- };- return setTagLibrary([- ...tagGroups.slice(0, indexForEditing),- modifiedEntry,- ...tagGroups.slice(indexForEditing + 1),- ]);- }- return tagGroups;-}-/*** get tagColor used to show color of the filename tags*/diff --git a/src/renderer/services/thumbsgenerator.ts b/src/renderer/services/thumbsgenerator.tsindex c85896c4a..e0d505f5a 100644--- a/src/renderer/services/thumbsgenerator.ts+++ b/src/renderer/services/thumbsgenerator.ts@@ -16,17 +16,11 @@**/-// import EXIF from 'exif-js';import {extractFileExtension,- extractContainingDirectoryPath,- extractFileName,- normalizePath,- getMetaDirectoryPath,encodeFileName,} from '@tagspaces/tagspaces-common/paths';import AppConfig from '-/AppConfig';-import { base64ToBlob } from '-/utils/dom';import PlatformIO from '../services/platform-facade';import { Pro } from '../pro';import { FileTypeGroups } from '-/services/search';@@ -100,181 +94,6 @@ export const supportedVideos = [];const maxFileSize = 30 * 1024 * 1024; // 30 MB-function saveThumbnailPromise(filePath, dataURL) {- if (!dataURL || dataURL.length < 7) {- // data:,- return Promise.reject(new Error('Invalid dataURL'));- }- const baseString = dataURL.split(',').pop();- const content = base64ToBlob(baseString);- return PlatformIO.saveBinaryFilePromise(- { path: filePath },- content, //PlatformIO.isMinio() ? content : content.buffer,- true,- )- .then(() => filePath)- .catch((error) => {- console.warn(- 'Saving thumbnail for ' +- filePath +- ' failed with ' +- JSON.stringify(error),- );- return Promise.reject(new Error('Saving tmb failed for: ' + filePath));- });-}--function getThumbFileLocation(filePath: string) {- const containingFolder = extractContainingDirectoryPath(- filePath,- PlatformIO.getDirSeparator(),- );- const metaFolder = getMetaDirectoryPath(- containingFolder,- PlatformIO.getDirSeparator(),- );- return (- metaFolder +- PlatformIO.getDirSeparator() +- extractFileName(filePath, PlatformIO.getDirSeparator()) +- AppConfig.thumbFileExt- );-}--export function getThumbnailURLPromise(- filePath: string,-): Promise<{ filePath: string; tmbPath?: string }> {- return PlatformIO.getPropertiesPromise(filePath)- .then((origStats) => {- const thumbFilePath = getThumbFileLocation(filePath);- return PlatformIO.getPropertiesPromise(thumbFilePath)- .then((stats) => {- if (stats) {- // Thumbnail exists- if (origStats.lmdt > stats.lmdt) {- // Checking if is up to date- return createThumbnailPromise(- filePath,- origStats.size,- thumbFilePath,- origStats.isFile,- )- .then((tmbPath) => ({ filePath, tmbPath }))- .catch((err) => {- console.warn('Thumb generation failed ' + err);- return Promise.resolve({ filePath, tmbPath: thumbFilePath });- });- } else {- // Tmb up to date- return Promise.resolve({ filePath, tmbPath: thumbFilePath });- }- } else {- // Thumbnail does not exists- return createThumbnailPromise(- filePath,- origStats.size,- thumbFilePath,- origStats.isFile,- )- .then((tmbPath) => {- if (tmbPath !== undefined) {- return { filePath, tmbPath };- } else {- return { filePath };- }- })- .catch((err) => {- console.warn('Thumb generation failed ' + err);- return Promise.resolve({ filePath });- });- }- })- .catch((err) => {- console.warn('Error getting tmb properties ' + err);- return Promise.resolve({ filePath });- });- })- .catch((err) => {- console.warn('Error getting file properties ' + err);- return Promise.resolve({ filePath });- });-}--/*export function replaceThumbnailURLPromise(- filePath: string,- thumbFilePath: string-): Promise<any> {- return PlatformIO.getPropertiesPromise(filePath)- .then(origStats =>- createThumbnailPromise(- filePath,- origStats.size,- thumbFilePath,- origStats.isFile- )- .then(tmbPath => ({ filePath, tmbPath }))- .catch(err => {- console.warn('Thumb generation failed ' + err);- return { filePath, tmbPath: thumbFilePath };- })- )- .catch(err => {- console.warn('Error getting file properties ' + err);- return { filePath };- });-}*/--export function createThumbnailPromise(- filePath: string,- fileSize: number,- thumbFilePath: string,- isFile: boolean,-): Promise<string | undefined> {- const metaDirectory = extractContainingDirectoryPath(- thumbFilePath,- PlatformIO.getDirSeparator(),- );- const fileDirectory = isFile- ? extractContainingDirectoryPath(filePath, PlatformIO.getDirSeparator())- : filePath;- const normalizedFileDirectory = normalizePath(fileDirectory);- if (normalizedFileDirectory.endsWith(AppConfig.metaFolder)) {- return Promise.resolve(undefined); // prevent creating thumbs in meta/.ts folder- }- return PlatformIO.checkDirExist(metaDirectory).then((exist) => {- if (!exist) {- return PlatformIO.createDirectoryPromise(metaDirectory).then(() => {- return createThumbnailSavePromise(filePath, fileSize, thumbFilePath);- });- } else {- return createThumbnailSavePromise(filePath, fileSize, thumbFilePath);- }- });-}--function createThumbnailSavePromise(- filePath: string,- fileSize: number,- thumbFilePath: string,-): Promise<string | undefined> {- return generateThumbnailPromise(filePath, fileSize)- .then((dataURL) => {- if (dataURL && dataURL.length) {- return saveThumbnailPromise(thumbFilePath, dataURL)- .then(() => thumbFilePath)- .catch((err) => {- console.warn('Thumb saving failed ' + err + ' for ' + filePath);- return Promise.resolve(undefined);- });- }- return undefined; // thumbFilePath;- })- .catch((err) => {- console.warn('Thumb generation failed ' + err + ' for ' + filePath);- return Promise.resolve(undefined);- });-}-/*** return thumbFilePath: Promise<string> or empty sting on error or not supported*/@@ -284,9 +103,10 @@ export function generateThumbnailPromise(fileURL: string, fileSize: number) {PlatformIO.getDirSeparator(),).toLowerCase();- const fileURLEscaped = /^https?:\/\//.test(fileURL)- ? fileURL- : encodeFileName(fileURL, PlatformIO.getDirSeparator());+ const fileURLEscaped =+ /^https?:\/\//.test(fileURL) || AppConfig.isElectron+ ? fileURL+ : encodeFileName(fileURL, PlatformIO.getDirSeparator());if (supportedImgs.indexOf(ext) >= 0) {if (Pro && ext === 'tga') {diff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.tsindex fdaa50f69..17492b8c3 100644--- a/src/renderer/services/utils-io.ts+++ b/src/renderer/services/utils-io.ts@@ -13,7 +13,6 @@** 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 { getUuid } from '@tagspaces/tagspaces-common/utils-io';@@ -34,7 +33,6 @@ import {getMetaDirectoryPath,getMetaFileLocationForFile,getMetaFileLocationForDir,- extractContainingDirectoryPath,extractDirectoryName,extractFileName,normalizePath,@@ -48,8 +46,6 @@ import AppConfig from '-/AppConfig';import PlatformIO from './platform-facade';import versionMeta from '../version.json';import { TS } from '-/tagspaces.namespace';-import { generateImageThumbnail } from '-/services/thumbsgenerator';-import { base64ToArrayBuffer } from '-/utils/dom';import { Pro } from '-/pro';import { supportedFileTypes } from '-/extension-config';import { getEnhancedDir, getEnhancedFile } from '-/services/meta-loader';@@ -933,28 +929,6 @@ export function parseNewTags(tagsInput: string, tagGroup: TS.TagGroup) {}}-export async function loadLocationDataPromise(- path: string,- metaFile = AppConfig.folderLocationsFile,-): Promise<TS.FileSystemEntryMeta> {- const entryProperties = await PlatformIO.getPropertiesPromise(path);- if (!entryProperties.isFile) {- const metaFilePath = getMetaFileLocationForDir(- path,- PlatformIO.getDirSeparator(),- metaFile,- );- const metaData = await loadJSONFile(metaFilePath);- if (metaData) {- return {- ...metaData,- description: getDescriptionPreview(metaData.description, 200),- };- }- }- return undefined;-}-/*** if you have entryProperties.isFile prefer to use loadFileMetaDataPromise/loadDirMetaDataPromise* @param path@@ -1127,146 +1101,6 @@ export function cleanMetaData(return cleanedMeta;}-export async function saveLocationDataPromise(- path: string,- metaData: any,-): Promise<any> {- const entryProperties = await PlatformIO.getPropertiesPromise(path);- if (entryProperties) {- let metaFilePath;- if (!entryProperties.isFile) {- // check and create meta folder if not exist- // todo not need to check if folder exist first createDirectoryPromise() recursively will skip creation of existing folders https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback- const metaDirectoryPath = getMetaDirectoryPath(- path,- PlatformIO.getDirSeparator(),- );- const metaDirectoryProperties =- await PlatformIO.getPropertiesPromise(metaDirectoryPath);- if (!metaDirectoryProperties) {- await PlatformIO.createDirectoryPromise(metaDirectoryPath);- }-- metaFilePath = getMetaFileLocationForDir(- path,- PlatformIO.getDirSeparator(),- AppConfig.folderLocationsFile,- );- }- const content = JSON.stringify({- ...metaData,- appName: versionMeta.name,- appVersion: versionMeta.version,- lastUpdated: new Date().toJSON(),- });- return PlatformIO.saveTextFilePromise(- { path: metaFilePath },- content,- true,- );- }- 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<TS.FileSystemEntryMeta> {- const entryProperties = await PlatformIO.getPropertiesPromise(path);- const cleanedMetaData = cleanMetaData(metaData);- if (entryProperties) {- let metaFilePath;- if (entryProperties.isFile) {- metaFilePath = getMetaFileLocationForFile(- path,- PlatformIO.getDirSeparator(),- );- // check and create meta folder if not exist- const metaFolder = getMetaDirectoryPath(- extractContainingDirectoryPath(path, PlatformIO.getDirSeparator()),- PlatformIO.getDirSeparator(),- );- const metaExist = await PlatformIO.getPropertiesPromise(metaFolder);- if (!metaExist) {- await PlatformIO.createDirectoryPromise(metaFolder);- }- } else {- // check and create meta folder if not exist- // todo not need to check if folder exist first createDirectoryPromise() recursively will skip creation of existing folders https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback- const metaDirectoryPath = getMetaDirectoryPath(- path,- PlatformIO.getDirSeparator(),- );- const metaDirectoryProperties =- await PlatformIO.getPropertiesPromise(metaDirectoryPath);- if (!metaDirectoryProperties) {- await PlatformIO.createDirectoryPromise(metaDirectoryPath);- }-- if (!cleanedMetaData.id) {- // add id for directories- cleanedMetaData.id = getUuid();- }-- metaFilePath = getMetaFileLocationForDir(- path,- PlatformIO.getDirSeparator(),- );- }- 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));-}--/**- * @param filePath- * @param directoryPath- * return Promise<directoryPath> of directory in order to open Folder properties next- */-export function setFolderBackgroundPromise(- filePath: string,- directoryPath: string,-): Promise<string> {- const folderBgndPath = getBgndFileLocationForDirectory(- directoryPath,- PlatformIO.getDirSeparator(),- );-- return generateImageThumbnail(filePath, AppConfig.maxBgndSize) // 4K -> 3840, 2K -> 2560- .then((base64Image) => {- if (base64Image) {- const data = base64ToArrayBuffer(base64Image.split(',').pop());- return PlatformIO.saveBinaryFilePromise(- { path: folderBgndPath },- data,- true,- )- .then(() => {- // props.setLastBackgroundImageChange(new Date().getTime());- return directoryPath;- })- .catch((error) => {- console.log('Save to file failed ', error);- return Promise.reject(error);- });- }- })- .catch((error) => {- console.log('Background generation failed ', error);- return Promise.reject(error);- });-}-export function findBackgroundColorForFolder(fsEntry: TS.FileSystemEntry) {if (!fsEntry.isFile) {if (fsEntry.meta && fsEntry.meta.color) {@@ -1660,14 +1494,20 @@ export function mergeFsEntryMeta(props: any = {}): TS.FileSystemEntryMeta {}export function toFsEntry(path: string, isFile: boolean): TS.FileSystemEntry {+ const name = isFile+ ? extractFileName(path, PlatformIO.getDirSeparator())+ : extractDirectoryName(path, PlatformIO.getDirSeparator());+ const tags = extractTagsAsObjects(+ name,+ AppConfig.tagDelimiter,+ PlatformIO.getDirSeparator(),+ );return {uuid: getUuid(),- name: isFile- ? extractFileName(path, PlatformIO.getDirSeparator())- : extractDirectoryName(path, PlatformIO.getDirSeparator()),+ name,isFile,extension: extractFileExtension(path, PlatformIO.getDirSeparator()),- tags: [],+ tags,size: 0,lmdt: new Date().getTime(),path,@@ -1693,24 +1533,6 @@ export function toFsEntry(path: string, isFile: boolean): TS.FileSystemEntry {};}*/-export function createFsEntryMeta(- path: string,- props: any = {},-): Promise<string> {- const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta(props);- return saveMetaDataPromise(path, newFsEntryMeta)- .then(() => newFsEntryMeta.id)- .catch((error) => {- console.log(- 'Error saveMetaDataPromise for ' +- path +- ' orphan id: ' +- newFsEntryMeta.id,- error,- );- return newFsEntryMeta.id;- });-}export function getDefaultViewer(fileType) {const type = supportedFileTypes.find((fType) => fType.type === fileType);if (type) {diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.tsindex efd1848ef..6944d3a4b 100644--- a/src/renderer/tagspaces.namespace.d.ts+++ b/src/renderer/tagspaces.namespace.d.ts@@ -120,6 +120,11 @@ export namespace TS {entry: TS.FileSystemEntry;}+ interface KanBanMetaActions {+ action: 'directoryVisibilityChange';+ meta: TS.FileSystemEntryMeta;+ }+interface Tag {title?: string;/**diff --git a/src/renderer/utils/HandleAuth.tsx b/src/renderer/utils/HandleAuth.tsxindex 1da19cda1..cf2b76cf5 100644--- a/src/renderer/utils/HandleAuth.tsx+++ b/src/renderer/utils/HandleAuth.tsx@@ -6,21 +6,16 @@ import {} from '@aws-amplify/ui-components';import { API, Auth } from 'aws-amplify';import { bindActionCreators } from 'redux';-import { connect } from 'react-redux';-import { actions as LocationActions } from '-/reducers/locations';-// import { actions as TagGroupActions } from '-/reducers/taglibrary';-import { actions as AppActions } from '-/reducers/app';-import { TS } from '-/tagspaces.namespace';-import { importTagGroups } from '-/services/taglibrary-utils';+import { useDispatch } from 'react-redux';+import { actions as AppActions, AppDispatch } from '-/reducers/app';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';+import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';-interface Props {- loggedIn: (user: CognitoUserInterface) => void;- initApp: () => void;-}-function HandleAuth(props: Props) {+function HandleAuth() {const username = useRef(undefined);const { addLocations } = useCurrentLocationContext();+ const { importTagGroups } = useTaggingActionsContext();+ const dispatch: AppDispatch = useDispatch();React.useEffect(() => {onAuthUIStateChange((nextAuthState, authData) => {@@ -54,15 +49,14 @@ function HandleAuth(props: Props) {.catch((e) => {console.log(e);});- props.initApp();+ dispatch(AppActions.initApp());}// @ts-ignoreusername.current = authData.username;- // @ts-ignore- props.loggedIn(authData);+ dispatch(AppActions.loggedIn(authData));} else if (nextAuthState === AuthState.SignedOut) {username.current = undefined;- props.loggedIn(undefined);+ dispatch(AppActions.loggedIn(undefined));}});}, []);@@ -101,33 +95,23 @@ function HandleAuth(props: Props) {}};- const fetchTenant = () =>+ const fetchTenant = (): Promise<string | undefined> =>// get the access token of the signed in userAuth.currentSession().then((session) => {const accessToken = session.getAccessToken();const cognitogroups = accessToken.payload['cognito:groups'];if (cognitogroups) {- return cognitogroups[0];+ return cognitogroups[0] as string;}return undefined;}).catch((e) => {console.log(e);+ return undefined;});return null;}-function mapDispatchToProps(dispatch) {- return bindActionCreators(- {- loggedIn: AppActions.loggedIn,- initApp: AppActions.initApp,- // importTagGroups: TagGroupActions.importTagGroups- },- dispatch,- );-}--export default connect(undefined, mapDispatchToProps)(React.memo(HandleAuth));+export default HandleAuth;diff --git a/src/renderer/utils/dom.ts b/src/renderer/utils/dom.tsindex 1bab399fa..68acc3bfc 100644--- a/src/renderer/utils/dom.ts+++ b/src/renderer/utils/dom.ts@@ -112,7 +112,7 @@ export function arrayBufferToDataURL(arrayBuffer: any, mime: string) {export function dataURLtoBlob(dataURI) {const arr = dataURI.split(',');const mime = arr[0].match(/:(.*?);/)[1];- const arrBuff = base64ToArrayBuffer(arr[1]);+ const arrBuff = base64ToBlob(arr[1]).buffer;return new window.Blob([arrBuff], { type: mime });}@@ -120,14 +120,14 @@ export function dataURLtoBlob(dataURI) {* @deprecated use base64ToBlob instead* @param base64*/-export function base64ToArrayBuffer(base64) {+/*export function base64ToArrayBuffer(base64) {const bstr = window.atob(base64);const bytes = new Uint8Array(bstr.length);for (let i = 0; i < bstr.length; i += 1) {bytes[i] = bstr.charCodeAt(i);}return bytes.buffer;-}+}*//*** @param base64diff --git a/src/renderer/utils/metaoperations.ts b/src/renderer/utils/metaoperations.tsdeleted file mode 100644index bcc44970b..000000000--- a/src/renderer/utils/metaoperations.ts+++ /dev/null@@ -1,136 +0,0 @@-import {- loadMetaDataPromise,- mergeFsEntryMeta,- saveMetaDataPromise,-} 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,- perspective: TS.PerspectiveType,-): Promise<TS.FileSystemEntryMeta> {- return new Promise((resolve, reject) => {- loadMetaDataPromise(path)- .then((fsEntryMeta: TS.FileSystemEntryMeta) => {- let updatedFsEntryMeta: TS.FileSystemEntryMeta;- if (perspective && perspective !== 'unspecified') {- updatedFsEntryMeta = {- ...fsEntryMeta,- perspective,- };- } else {- const { perspective: remove, ...rest } = fsEntryMeta;- updatedFsEntryMeta = rest;- }- saveMetaDataPromise(path, updatedFsEntryMeta)- .then(() => {- resolve(updatedFsEntryMeta);- return true;- })- .catch((err) => {- console.warn(- 'Error adding perspective for ' + path + ' with ' + err,- );- reject();- });- return true;- })- .catch(() => {- const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({- perspective,- });- saveMetaDataPromise(path, newFsEntryMeta)- .then(() => {- resolve(newFsEntryMeta);- return true;- })- .catch((error) => {- console.warn(- 'Error adding perspective for ' + path + ' with ' + error,- );- reject();- });- });- });-}--export function removeFolderCustomSettings(- path: string,- perspective: string,-): Promise<TS.FileSystemEntryMeta> {- return new Promise((resolve, reject) => {- loadMetaDataPromise(path, true)- .then((fsEntryMeta: TS.FileSystemEntryMeta) => {- let updatedFsEntryMeta: TS.FileSystemEntryMeta = {- ...fsEntryMeta,- perspectiveSettings: {- ...fsEntryMeta.perspectiveSettings,- [perspective]: undefined,- },- };-- saveMetaDataPromise(path, updatedFsEntryMeta)- .then(() => {- resolve(updatedFsEntryMeta);- return true;- })- .catch((err) => {- console.warn(- 'Error adding perspective for ' + path + ' with ' + err,- );- reject();- });- return true;- })- .catch(() => {- const newFsEntryMeta: TS.FileSystemEntryMeta = mergeFsEntryMeta({- perspectiveSettings: {- [perspective]: undefined,- },- });- saveMetaDataPromise(path, newFsEntryMeta)- .then(() => {- resolve(newFsEntryMeta);- return true;- })- .catch((error) => {- console.warn(- 'Error adding perspective for ' + path + ' with ' + error,- );- reject();- });- });- });-}diff --git a/tests/e2e/tag.helpers.js b/tests/e2e/tag.helpers.jsindex 38573bd2b..87a655438 100644--- a/tests/e2e/tag.helpers.js+++ b/tests/e2e/tag.helpers.js@@ -1,4 +1,4 @@-import { clickOn, setInputKeys } from './general.helpers';+import { clickOn, expectElementExist, setInputKeys } from './general.helpers';export const testTagName = 'testTag';export const newTagName = 'newTagName';@@ -21,6 +21,21 @@ export async function createTagGroup(tagGroupName, locationName = undefined) {}await clickOn('[data-tid=createTagGroupConfirmButton]');}+ await expectElementExist(+ '[data-tid=tagLibraryTagGroupTitle_' + testGroup + ']',+ true,+ );+}++export async function deleteTagGroup(tagGroupName) {+ await clickOn('[data-tid=tagLibrary]');+ await clickOn('[data-tid=tagLibraryMoreButton_' + tagGroupName + ']');+ await clickOn('[data-tid=deleteTagGroup]');+ await clickOn('[data-tid=confirmDeleteTagGroupDialog]');+ await expectElementExist(+ '[data-tid=tagLibraryTagGroupTitle_' + tagGroupName + ']',+ false,+ );}export async function addTags(arrTags) {diff --git a/tests/e2e/tag.pw.e2e.js b/tests/e2e/tag.pw.e2e.jsindex bc757e8c5..ed112e01b 100644--- a/tests/e2e/tag.pw.e2e.js+++ b/tests/e2e/tag.pw.e2e.js@@ -22,6 +22,7 @@ import {addTags,arrTags,createTagGroup,+ deleteTagGroup,editedGroupName,newTagName,tagMenu,@@ -54,25 +55,12 @@ test.beforeEach(async () => {test.describe('TST04 - Testing the tag library:', () => {test('TST0401 - Should create a tag group [web,minio,electron]', async () => {await createTagGroup(testGroup);- await expectElementExist(- '[data-tid=tagLibraryTagGroupTitle_' + testGroup + ']',- true,- );+ await deleteTagGroup(testGroup);});test('TST0402 - Should delete tag group [web,minio,electron]', async () => {await createTagGroup(testGroup);- await expectElementExist(- '[data-tid=tagLibraryTagGroupTitle_' + testGroup + ']',- true,- );- await clickOn('[data-tid=tagLibraryMoreButton_' + testGroup + ']');- await clickOn('[data-tid=deleteTagGroup]');- await clickOn('[data-tid=confirmDeleteTagGroupDialog]');- await expectElementExist(- '[data-tid=tagLibraryTagGroupTitle_' + testGroup + ']',- false,- );+ await deleteTagGroup(testGroup);});test('TST0403 - Rename tag group [web,minio,electron]', async () => {@@ -85,6 +73,7 @@ test.describe('TST04 - Testing the tag library:', () => {'[data-tid=tagLibraryTagGroupTitle_' + editedGroupName + ']',true,);+ await deleteTagGroup(editedGroupName);});test.skip('TST0404 - Change default tag group tag colors [web,minio,electron]', async () => {@@ -113,6 +102,7 @@ test.describe('TST04 - Testing the tag library:', () => {const hex = rgb2hex(colorStyle); //color.value);expect(hex.hex).toBe('#000000'); //'rgb(0,0,0)');await clickOn('[data-tid=editTagGroupConfirmButton]');+ await deleteTagGroup(testGroup);});test('TST0405 - Should add tag to a tag group [web,minio,electron]', async () => {@@ -123,6 +113,7 @@ test.describe('TST04 - Testing the tag library:', () => {'[data-tid=tagContainer_' + newTagName + ']',true,);+ await deleteTagGroup(testGroup);});test.skip('TST0406 - Import tag groups [manual]', async () => {});@@ -137,6 +128,7 @@ test.describe('TST04 - Testing the tag library:', () => {true,);}+ await deleteTagGroup(testGroup);});test('TST0407 - Should rename tag [web,minio,electron]', async () => {@@ -272,6 +264,8 @@ test.describe('TST04 - Testing the tag library:', () => {await clickOn('[data-tid=locationManager]');await clickOn('[data-tid=location_' + defaultLocationName + ']');await expectMetaFilesExist(['tsl.json'], true);+ // cleanup+ await deleteTagGroup(testGroup);});test('TST0420 - Load tag groups from location [web,minio,electron, _pro]', async () => {