TagSpaces is an offline, open source, document manager with tagging support
Extract tag library from redux v2 (#1814)
Stanimir4e495375a105
diff --git a/app/components/TagContainer.tsx b/app/components/TagContainer.tsxindex 7dc7fa20e..bdc8c1e85 100644--- a/app/components/TagContainer.tsx+++ b/app/components/TagContainer.tsx@@ -25,16 +25,16 @@ import DateIcon from '@mui/icons-material/DateRange';import RemoveTagIcon from '@mui/icons-material/Close';import Tooltip from '-/components/Tooltip';import { formatDateTime } from '@tagspaces/tagspaces-common/misc';-import { getAllTags, getTagColors } from '-/reducers/taglibrary';import { getTagColor, getTagTextColor } from '-/reducers/settings';import { isGeoTag } from '-/utils/geo';import { isDateTimeTag, convertToDateTime, convertToDate } from '-/utils/dates';import { TS } from '-/tagspaces.namespace';+// import { getAllTags, getTagColors } from '-/services/taglibrary-utils';interface Props {tag: TS.Tag;isReadOnlyMode?: boolean;- allTags?: Array<TS.Tag>;+ // allTags?: Array<TS.Tag>;defaultTextColor?: string;defaultBackgroundColor?: string;tagGroup?: TS.TagGroup;@@ -50,7 +50,11 @@ interface Props {entryPath?: string;deleteIcon?: Object;addTags?: (paths: Array<string>, tags: Array<TS.Tag>) => void;- moveTag?: () => void;+ moveTag?: (+ tagTitle: string,+ fromTagGroupId: TS.Uuid,+ toTagGroupId: TS.Uuid+ ) => void;selectedEntries?: Array<TS.FileSystemEntry>;reorderTags?: boolean;}@@ -64,7 +68,7 @@ function TagContainer(props: Props) {defaultBackgroundColor,tagGroup,entryPath,- allTags,+ // allTags,handleRemoveTag,handleTagMenu,selectedEntries,@@ -83,10 +87,10 @@ function TagContainer(props: Props) {isTagDate = !isTagGeo && isDateTimeTag(title);}- const tagColors = getTagColors(allTags, title);- const textColor = tag.textcolor || tagColors.textcolor || defaultTextColor;+ // const tagColors = getTagColors(getAllTags(), title);+ const textColor = tag.textcolor || defaultTextColor; // || tagColors.textcolorconst backgroundColor =- tag.color || tagColors.color || defaultBackgroundColor;+ tag.color || defaultBackgroundColor; // || tagColors.colorlet tid = 'tagContainer_';if (title && title.length > 0) {@@ -263,7 +267,7 @@ function TagContainer(props: Props) {function mapStateToProps(state) {return {- allTags: getAllTags(state),+ // allTags: getAllTags(state),defaultBackgroundColor: getTagColor(state),defaultTextColor: getTagTextColor(state)// selectedEntries: getSelectedEntries(state)diff --git a/app/components/TagContainerDnd.tsx b/app/components/TagContainerDnd.tsxindex 5eba127be..7332685e0 100644--- a/app/components/TagContainerDnd.tsx+++ b/app/components/TagContainerDnd.tsx@@ -199,7 +199,11 @@ interface Props {entryPath?: string;addTags?: (paths: Array<string>, tags: Array<TS.Tag>) => void;addTag?: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => void;- moveTag?: () => void;+ moveTag?: (+ tagTitle: string,+ fromTagGroupId: TS.Uuid,+ toTagGroupId: TS.Uuid+ ) => void;changeTagOrder?: (tagGroupUuid: TS.Uuid,fromIndex: number,diff --git a/app/components/TagLibrary.tsx b/app/components/TagLibrary.tsxindex 690caaecf..fff2adbbd 100644--- a/app/components/TagLibrary.tsx+++ b/app/components/TagLibrary.tsx@@ -37,14 +37,9 @@ import TagGroupContainer from './TagGroupContainer';import TagMenu from './menus/TagMenu';import TagLibraryMenu from './menus/TagLibraryMenu';import TagGroupMenu from './menus/TagGroupMenu';-import {- actions as TagLibraryActions,- getAllTags,- getTagGroups-} from '../reducers/taglibrary';import TaggingActions from '../reducers/tagging-actions';import i18n from '../services/i18n';-import {+import settings, {actions as SettingsActions,getCurrentLanguage,getTagColor,@@ -53,14 +48,33 @@ import {import {actions as AppActions,getSelectedEntries,- isReadOnlyMode+ isReadOnlyMode,+ isTagLibraryChanged} 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 locations, { getLocations } from '-/reducers/locations';import { Pro } from '-/pro';import TagGroupTitleDnD from '-/components/TagGroupTitleDnD';+import {+ addTag,+ changeTagOrder,+ createTagGroup,+ deleteTag,+ editTag,+ editTagGroup,+ exportTagGroups,+ getAllTags,+ getTagLibrary,+ importTagGroups,+ moveTag,+ moveTagGroup,+ moveTagGroupDown,+ moveTagGroupUp,+ removeTagGroup,+ sortTagGroup+} from '-/services/taglibrary-utils';interface Props {classes?: any;@@ -68,29 +82,30 @@ interface Props {isReadOnly: boolean;tagTextColor: string;tagBackgroundColor: string;- tagGroups: Array<TS.TagGroup>;- allTags: Array<TS.Tag>;+ //tagGroups: Array<TS.TagGroup>;+ //allTags: Array<TS.Tag>;openURLExternally: (path: string) => void;toggleTagGroup: (uuid: string) => void;- removeTagGroup: (uuid: string) => void;- moveTagGroupUp: (uuid: string) => void;- moveTagGroupDown: (uuid: string) => void;- sortTagGroup: (uuid: string) => void;+ settingsVersion: number;+ // removeTagGroup: (uuid: string) => void;+ // moveTagGroupUp: (uuid: string) => void;+ // moveTagGroupDown: (uuid: string) => void;+ // sortTagGroup: (uuid: string) => void;collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;addTags: () => void;- importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;- exportTagGroups: () => void;- createTagGroup: () => void;- addTag: () => void;- moveTag: () => void;- changeTagOrder: (+ // importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;+ // exportTagGroups: () => void;+ // createTagGroup: () => void;+ // addTag: () => void;+ // moveTag: () => void;+ /*changeTagOrder: (tagGroupUuid: TS.Uuid,fromIndex: number,toIndex: number- ) => void;- editTagGroup: () => void;- editTag: () => void;- deleteTag: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => void;+ ) => void;*/+ // editTagGroup: () => void;+ // editTag: () => void;+ // deleteTag: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => void;showNotification: (text: string,notificationType?: string, // NotificationTypes@@ -100,11 +115,16 @@ interface Props {tagGroupCollapsed: Array<string>;locations: Array<TS.Location>;saveTagInLocation: boolean;- moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => void;+ // moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => void;reduceHeightBy: number;+ isTagLibraryChanged: boolean;}function TagLibrary(props: Props) {+ const [tagGroups, setTagGroups] = useState<Array<TS.TagGroup>>(+ getTagLibrary()+ );+ // const tagLibrary: Array<TS.TagGroup> = getTagLibrary();const tagContainerRef = useRef<HTMLSpanElement>(null);const [tagGroupMenuAnchorEl,@@ -149,16 +169,22 @@ function TagLibrary(props: Props) {}}, []);+ useEffect(() => {+ setTagGroups(getTagLibrary());+ }, [props.isTagLibraryChanged]);+const refreshTagsFromLocation = () => {props.locations.map(location =>Pro.MetaOperations.getTagGroups(location.path)- .then((tagGroups: Array<TS.TagGroup>) => {- if (tagGroups && tagGroups.length > 0) {- const newGroups = tagGroups.map(group => ({+ .then((tg: Array<TS.TagGroup>) => {+ if (tg && tg.length > 0) {+ const newGroups = tg.map(group => ({...group,locationId: location.uuid}));- props.importTagGroups(newGroups, false);+ setTagGroups(importTagGroups(newGroups, tg, false));+ } else {+ setTagGroups(getTagLibrary());}return true;})@@ -251,7 +277,9 @@ function TagLibrary(props: Props) {index={index}classes={classes}tagGroup={tagGroup}- moveTagGroup={props.moveTagGroup}+ moveTagGroup={(tagGroupUuid, position) => {+ setTagGroups(moveTagGroup(tagGroupUuid, position, tagGroups));+ }}handleTagGroupMenu={handleTagGroupMenu}toggleTagGroup={props.toggleTagGroup}locations={props.locations}@@ -273,7 +301,18 @@ function TagLibrary(props: Props) {tagGroup={tagGroup}handleTagMenu={handleTagMenuCallback}addTags={props.addTags}- moveTag={props.moveTag}+ /*moveTag={(+ tagTitle: string,+ fromTagGroupId: TS.Uuid,+ toTagGroupId: TS.Uuid+ ) =>+ moveTag(+ tagTitle,+ fromTagGroupId,+ toTagGroupId,+ tagGroups+ )+ }*/selectedEntries={props.selectedEntries}/>);@@ -287,8 +326,34 @@ function TagLibrary(props: Props) {tagGroup={tagGroup}handleTagMenu={handleTagMenuCallback}addTags={props.addTags}- moveTag={props.moveTag}- changeTagOrder={props.changeTagOrder}+ moveTag={(+ tagTitle: string,+ fromTagGroupId: TS.Uuid,+ toTagGroupId: TS.Uuid+ ) =>+ setTagGroups(+ moveTag(+ tagTitle,+ fromTagGroupId,+ toTagGroupId,+ tagGroups+ )+ )+ }+ changeTagOrder={(+ tagGroupUuid: TS.Uuid,+ fromIndex: number,+ toIndex: number+ ) =>+ setTagGroups(+ changeTagOrder(+ tagGroupUuid,+ fromIndex,+ toIndex,+ tagGroups+ )+ )+ }selectedEntries={props.selectedEntries}/>);@@ -301,19 +366,26 @@ function TagLibrary(props: Props) {function confirmDeleteTag() {if (selectedTag && selectedTagGroupEntry) {- props.deleteTag(selectedTag.title, selectedTagGroupEntry.uuid);+ setTagGroups(+ deleteTag(+ selectedTag.title,+ selectedTagGroupEntry.uuid,+ tagGroups,+ props.locations+ )+ );}}const {- tagGroups,classes,- allTags,+ // allTags,showNotification,isReadOnly,reduceHeightBy} = props;+ const allTags = getAllTags(tagGroups);return (<divclassName={classes.panel}@@ -356,7 +428,13 @@ function TagLibrary(props: Props) {})}confirmCallback={result => {if (result && selectedTagGroupEntry) {- props.removeTagGroup(selectedTagGroupEntry.uuid);+ setTagGroups(+ removeTagGroup(+ selectedTagGroupEntry.uuid,+ tagGroups,+ props.locations+ )+ );}}}cancelDialogTID="cancelDeleteTagGroupDialog"@@ -367,7 +445,9 @@ function TagLibrary(props: Props) {<CreateTagGroupDialogopen={isCreateTagGroupDialogOpened}onClose={() => setIsCreateTagGroupDialogOpened(false)}- createTagGroup={props.createTagGroup}+ createTagGroup={(entry: TS.TagGroup) =>+ setTagGroups(createTagGroup(entry, tagGroups, props.locations))+ }color={props.tagBackgroundColor}textcolor={props.tagTextColor}/>@@ -376,7 +456,11 @@ function TagLibrary(props: Props) {<CreateTagsDialogopen={isCreateTagDialogOpened}onClose={() => setIsCreateTagDialogOpened(false)}- addTag={props.addTag}+ addTag={(tag: any, parentTagGroupUuid: TS.Uuid) =>+ setTagGroups(+ addTag(tag, parentTagGroupUuid, tagGroups, props.locations)+ )+ }selectedTagGroupEntry={selectedTagGroupEntry}/>)}@@ -384,7 +468,9 @@ function TagLibrary(props: Props) {<EditTagGroupDialogopen={isEditTagGroupDialogOpened}onClose={() => setIsEditTagGroupDialogOpened(false)}- editTagGroup={props.editTagGroup}+ editTagGroup={(entry: TS.TagGroup) =>+ setTagGroups(editTagGroup(entry, tagGroups, props.locations))+ }selectedTagGroupEntry={selectedTagGroupEntry}/>)}@@ -398,9 +484,15 @@ function TagLibrary(props: Props) {showDeleteTagGroupDialog={showDeleteTagGroupDialog}handleCloseTagGroupMenu={() => setTagGroupMenuAnchorEl(null)}showEditTagGroupDialog={showEditTagGroupDialog}- moveTagGroupUp={props.moveTagGroupUp}- moveTagGroupDown={props.moveTagGroupDown}- sortTagGroup={props.sortTagGroup}+ moveTagGroupUp={parentTagGroupUuid =>+ setTagGroups(moveTagGroupUp(parentTagGroupUuid, tagGroups))+ }+ moveTagGroupDown={parentTagGroupUuid =>+ setTagGroups(moveTagGroupDown(parentTagGroupUuid, tagGroups))+ }+ sortTagGroup={parentTagGroupUuid =>+ setTagGroups(sortTagGroup(parentTagGroupUuid, tagGroups))+ }collectTagsFromLocation={props.collectTagsFromLocation}/>)}@@ -409,8 +501,10 @@ function TagLibrary(props: Props) {open={Boolean(tagLibraryMenuAnchorEl)}onClose={() => setTagLibraryMenuAnchorEl(null)}tagGroups={tagGroups}- importTagGroups={props.importTagGroups}- exportTagGroups={props.exportTagGroups}+ importTagGroups={(newGroups, replace) =>+ setTagGroups(importTagGroups(newGroups, tagGroups, replace))+ }+ exportTagGroups={tg => exportTagGroups(tg, props.settingsVersion)}showCreateTagGroupDialog={showCreateTagGroupDialog}showNotification={showNotification}openURLExternally={props.openURLExternally}@@ -433,7 +527,21 @@ function TagLibrary(props: Props) {<EditTagDialogopen={isEditTagDialogOpened}onClose={() => setIsEditTagDialogOpened(false)}- editTag={props.editTag}+ editTag={(+ tag: TS.Tag,+ parentTagGroupUuid: TS.Uuid,+ origTitle: string+ ) =>+ setTagGroups(+ editTag(+ tag,+ parentTagGroupUuid,+ origTitle,+ tagGroups,+ props.locations+ )+ )+ }selectedTagGroupEntry={selectedTagGroupEntry}selectedTag={selectedTag}/>@@ -479,16 +587,18 @@ function TagLibrary(props: Props) {function mapStateToProps(state) {return {- tagGroups: getTagGroups(state),+ // tagGroups: getTagGroups(state),tagBackgroundColor: getTagColor(state),tagTextColor: getTagTextColor(state),selectedEntries: getSelectedEntries(state),- allTags: getAllTags(state),+ // allTags: getAllTags(state),isReadOnly: isReadOnlyMode(state),tagGroupCollapsed: state.settings.tagGroupCollapsed,locations: getLocations(state),saveTagInLocation: state.settings.saveTagInLocation,- language: getCurrentLanguage(state)+ settingsVersion: state.settings.settingsVersion,+ language: getCurrentLanguage(state),+ isTagLibraryChanged: isTagLibraryChanged(state)};}@@ -496,20 +606,20 @@ function mapDispatchToProps(dispatch) {return bindActionCreators({toggleTagGroup: SettingsActions.toggleTagGroup,- removeTagGroup: TagLibraryActions.removeTagGroup,- moveTagGroupUp: TagLibraryActions.moveTagGroupUp,- moveTagGroup: TagLibraryActions.moveTagGroup,- moveTagGroupDown: TagLibraryActions.moveTagGroupDown,- sortTagGroup: TagLibraryActions.sortTagGroup,- importTagGroups: TagLibraryActions.importTagGroups,- exportTagGroups: TagLibraryActions.exportTagGroups,- createTagGroup: TagLibraryActions.createTagGroup,- editTag: TagLibraryActions.editTag,- moveTag: TagLibraryActions.moveTag,- changeTagOrder: TagLibraryActions.changeTagOrder,- editTagGroup: TagLibraryActions.editTagGroup,- deleteTag: TagLibraryActions.deleteTag,- addTag: TagLibraryActions.addTag,+ // removeTagGroup: TagLibraryActions.removeTagGroup,+ // moveTagGroupUp: TagLibraryActions.moveTagGroupUp,+ // moveTagGroup: TagLibraryActions.moveTagGroup,+ // moveTagGroupDown: TagLibraryActions.moveTagGroupDown,+ // sortTagGroup: TagLibraryActions.sortTagGroup,+ // importTagGroups: TagLibraryActions.importTagGroups,+ // exportTagGroups: TagLibraryActions.exportTagGroups,+ // createTagGroup: TagLibraryActions.createTagGroup,+ // editTag: TagLibraryActions.editTag,+ // moveTag: TagLibraryActions.moveTag,+ // changeTagOrder: TagLibraryActions.changeTagOrder,+ // editTagGroup: TagLibraryActions.editTagGroup,+ // deleteTag: TagLibraryActions.deleteTag,+ // addTag: TagLibraryActions.addTag,addTags: TaggingActions.addTags,collectTagsFromLocation: TaggingActions.collectTagsFromLocation,openURLExternally: AppActions.openURLExternally,diff --git a/app/components/TagsPreview.tsx b/app/components/TagsPreview.tsxindex 23bd74862..f5524aefd 100644--- a/app/components/TagsPreview.tsx+++ b/app/components/TagsPreview.tsx@@ -16,27 +16,29 @@**/-import React from 'react';+import React, { useRef } from 'react';import { connect } from 'react-redux';import Tooltip from '-/components/Tooltip';import { TS } from '-/tagspaces.namespace';-import { getAllTags, getTagColors } from '-/reducers/taglibrary';+// import { getAllTags, getTagColors } from '-/reducers/taglibrary';import {getCurrentLanguage,getTagColor,getTagTextColor} from '-/reducers/settings';import i18n from '-/services/i18n';+import { getAllTags, getTagLibrary } from '-/services/taglibrary-utils';interface Props {tags: Array<TS.Tag>;- allTags?: Array<TS.Tag>;+ // allTags?: Array<TS.Tag>;defaultTextColor?: string;defaultBackgroundColor?: string;}function TagsPreview(props: Props) {- const { tags, allTags, defaultBackgroundColor, defaultTextColor } = props;+ const { tags, defaultBackgroundColor, defaultTextColor } = props;+ const allTags = useRef<Array<TS.Tag>>(getAllTags(getTagLibrary()));if (!tags || tags.length < 1) {return <></>;}@@ -45,16 +47,15 @@ function TagsPreview(props: Props) {tagNames = tagNames + tag.title + ' ';});- const tag1Colors = getTagColors(allTags, tags[0].title);- const firstTagColor =- tags[0].color || tag1Colors.color || defaultBackgroundColor;+ // const tag1Colors = getTagColors(allTags.current, tags[0].title);+ const firstTagColor = tags[0].color || defaultBackgroundColor; // || tag1Colors.colorlet secondTagColor = defaultBackgroundColor;let moreThanOne = false;if (tags[1]) {moreThanOne = true;- const tag2Colors = getTagColors(allTags, tags[1].title);+ // const tag2Colors = getTagColors(allTags.current, tags[1].title);if (tags[1].color) {- secondTagColor = tags[1].color || tag2Colors.color;+ secondTagColor = tags[1].color; // || tag2Colors.color;}}return (@@ -71,7 +72,7 @@ function TagsPreview(props: Props) {backgroundColor: firstTagColor,fontSize: 11,lineHeight: '16px',- color: tag1Colors.textcolor || defaultTextColor,+ color: firstTagColor || defaultTextColor, //tag1Colors.textcolor ,textAlign: 'center'}}>@@ -83,7 +84,7 @@ function TagsPreview(props: Props) {function mapStateToProps(state) {return {- allTags: getAllTags(state),+ // allTags: getAllTags(state),defaultBackgroundColor: getTagColor(state),defaultTextColor: getTagTextColor(state),language: getCurrentLanguage(state)diff --git a/app/components/TagsSelect.tsx b/app/components/TagsSelect.tsxindex f1c868c79..6f576b6ce 100644--- a/app/components/TagsSelect.tsx+++ b/app/components/TagsSelect.tsx@@ -21,12 +21,13 @@ import { useSelector } from 'react-redux';import withStyles from '@mui/styles/withStyles';import TextField from '@mui/material/TextField';import Autocomplete from '@mui/material/Autocomplete';-import { getAllTags } from '-/reducers/taglibrary';+// import { getAllTags } from '-/reducers/taglibrary';import { getTagColor, getTagTextColor } from '-/reducers/settings';import EntryTagMenu from '-/components/menus/EntryTagMenu';import { TS } from '-/tagspaces.namespace';import TagContainer from '-/components/TagContainer';import { getUuid } from '-/services/utils-io';+import { getAllTags } from '-/services/taglibrary-utils';const styles: any = (theme: any) => ({root: {@@ -72,8 +73,8 @@ interface Props {tags: TS.Tag[];label?: string;tagSearchType?: string;- defaultBackgroundColor?: string;- defaultTextColor?: string;+ // defaultBackgroundColor?: string;+ // defaultTextColor?: string;handleChange?: (param1: any, param2: any, param3?: any) => void;allTags?: TS.Tag[];tagMode?: 'default' | 'display' | 'remove';@@ -90,8 +91,9 @@ function TagsSelect(props: Props) {);const [selectedTag, setSelectedTag] = useState(undefined);+ const [allTags, setAllTags] = useState(getAllTags());- const allTags = useSelector(getAllTags);+ /*const allTags = useSelector(getAllTags); */const defaultBackgroundColor = useSelector(getTagColor);const defaultTextColor = useSelector(getTagTextColor);const {diff --git a/app/components/dialogs/AddTagToTagGroupDialog.tsx b/app/components/dialogs/AddTagToTagGroupDialog.tsxindex e475a4bc5..9cccba4a4 100644--- a/app/components/dialogs/AddTagToTagGroupDialog.tsx+++ b/app/components/dialogs/AddTagToTagGroupDialog.tsx@@ -30,12 +30,13 @@ import MenuItem from '@mui/material/MenuItem';import IconButton from '@mui/material/IconButton';import CloseIcon from '@mui/icons-material/Close';import { connect } from 'react-redux';-import { getTagGroups } from '-/reducers/taglibrary';+// import { getTagGroups } from '-/reducers/taglibrary';import i18n from '-/services/i18n';import { getTagColor, getTagTextColor } from '-/reducers/settings';import { TS } from '-/tagspaces.namespace';import useTheme from '@mui/styles/useTheme';import useMediaQuery from '@mui/material/useMediaQuery';+import { getTagLibrary } from "-/services/taglibrary-utils";interface Props {open: boolean;@@ -44,7 +45,7 @@ interface Props {selectedTag: TS.Tag;defaultBackgroundColor?: string;defaultTextColor?: string;- tagGroups: Array<TS.TagGroup>;+ // tagGroups: Array<TS.TagGroup>;}function AddTagToTagGroupDialog(props: Props) {@@ -112,7 +113,7 @@ function AddTagToTagGroupDialog(props: Props) {onChange={handleTagGroupChange}input={<Input id="addTagToTagGroupInput" />}>- {props.tagGroups.map(tg => (+ {getTagLibrary().map(tg => (<MenuItem value={tg.uuid}>{tg.title}</MenuItem>))}</Select>@@ -134,7 +135,7 @@ function AddTagToTagGroupDialog(props: Props) {}const mapStateToProps = state => ({- tagGroups: getTagGroups(state),+ // tagGroups: getTagGroups(state),defaultBackgroundColor: getTagColor(state),defaultTextColor: getTagTextColor(state)});diff --git a/app/components/dialogs/ImportExportTagGroupsDialog.tsx b/app/components/dialogs/ImportExportTagGroupsDialog.tsxindex d1b6baaec..0bc117109 100644--- a/app/components/dialogs/ImportExportTagGroupsDialog.tsx+++ b/app/components/dialogs/ImportExportTagGroupsDialog.tsx@@ -53,8 +53,8 @@ interface Props {onClose: () => void;dialogModeImport: boolean;showNotification?: (text: string) => void;- importTagGroups: (taggroup: any) => void;- exportTagGroups: (taggroup: any) => void;+ importTagGroups: (taggroups: Array<TS.TagGroup>) => void;+ exportTagGroups: (taggroups: Array<TS.TagGroup>) => void;}function ImportExportTagGroupsDialog(props: Props) {diff --git a/app/components/menus/TagLibraryMenu.tsx b/app/components/menus/TagLibraryMenu.tsxindex b63e61917..cb3990ecd 100644--- a/app/components/menus/TagLibraryMenu.tsx+++ b/app/components/menus/TagLibraryMenu.tsx@@ -41,7 +41,7 @@ interface Props {open: boolean;onClose: () => void;importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;- exportTagGroups: () => void;+ exportTagGroups: (entries: Array<TS.TagGroup>) => void;showCreateTagGroupDialog: () => void;showNotification: (text: string,diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex 2b1fc4143..924cde06a 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -28,7 +28,7 @@ import {} from '@tagspaces/tagspaces-common/misc';import AppConfig from '-/AppConfig';import { isVisibleOnScreen } from '-/utils/dom';-import { actions as TagLibraryActions } from '-/reducers/taglibrary';+// import { actions as TagLibraryActions } from '-/reducers/taglibrary';import {getSupportedFileTypes,getDesktopMode,@@ -876,7 +876,7 @@ function mapActionCreatorsToProps(dispatch) {toggleDeleteMultipleEntriesDialog:AppActions.toggleDeleteMultipleEntriesDialog,addTags: TaggingActions.addTags,- addTag: TagLibraryActions.addTag+ addTag: AppActions.addTag},dispatch);diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsxindex 16c3ab238..5d25d56f8 100644--- a/app/perspectives/list/components/MainContainer.tsx+++ b/app/perspectives/list/components/MainContainer.tsx@@ -28,7 +28,7 @@ import {} from '@tagspaces/tagspaces-common/misc';import AppConfig from '-/AppConfig';import { isVisibleOnScreen } from '-/utils/dom';-import { actions as TagLibraryActions } from '-/reducers/taglibrary';+// import { actions as TagLibraryActions } from '-/reducers/taglibrary';import {getSupportedFileTypes,getDesktopMode,@@ -876,7 +876,7 @@ function mapActionCreatorsToProps(dispatch) {toggleDeleteMultipleEntriesDialog:AppActions.toggleDeleteMultipleEntriesDialog,addTags: TaggingActions.addTags,- addTag: TagLibraryActions.addTag+ addTag: AppActions.addTag},dispatch);diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex a6a2a6bab..33941faba 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -60,6 +60,7 @@ import {import i18n from '../services/i18n';import { Pro } from '../pro';import { actions as LocationIndexActions } from './location-index';+import { actions as tagLibraryActions } from './taglibrary';import {actions as SettingsActions,getCheckForUpdateOnStartup,@@ -69,6 +70,11 @@ import {import { TS } from '-/tagspaces.namespace';import { PerspectiveIDs } from '-/perspectives';import versionMeta from '-/version.json';+import {+ addTag,+ getTagLibrary,+ setTagLibrary+} from '-/services/taglibrary-utils';import { getProTeaserSlideIndex } from '-/content/ProTeaserSlides';export const types = {@@ -103,6 +109,7 @@ export const types = {SET_IS_META_LOADED: 'APP/SET_IS_META_LOADED',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_FILEDRAGGED: 'APP/SET_FILEDRAGGED',SET_READONLYMODE: 'APP/SET_READONLYMODE',RENAME_FILE: 'APP/RENAME_FILE',@@ -232,6 +239,7 @@ export const initialState = {importKanBanDialogOpened: false,// lastSelectedEntry: null,selectedEntries: [],+ tagLibraryChanged: false,isEntryInFullWidth: false,isGeneratingThumbs: false,locationManagerPanelOpened: showLocations,@@ -377,6 +385,9 @@ export default (state: any = initialState, action: any) => {case types.SET_SELECTED_ENTRIES: {return { ...state, selectedEntries: action.selectedEntries };}+ case types.SET_TAG_LIBRARY_CHANGED: {+ return { ...state, tagLibraryChanged: !state.tagLibraryChanged };+ }case types.SET_CURRENDIRECTORYCOLOR: {if (state.currentDirectoryColor !== action.color) {return { ...state, currentDirectoryColor: action.color };@@ -924,6 +935,16 @@ export const actions = {loggedIn: user => ({ type: types.LOGIN_SUCCESS, user }),initApp: () => (dispatch: (action) => void, getState: () => any) => {disableBackGestureMac();+ // migrate TagLibrary from redux state+ const { taglibrary } = getState();+ if (taglibrary && taglibrary.length > 0) {+ try {+ setTagLibrary(taglibrary);+ dispatch(tagLibraryActions.deleteAll());+ } catch (e) {+ console.error('migrate TagLibrary failed', e);+ }+ }dispatch(SettingsActions.setZoomRestoreApp());dispatch(SettingsActions.upgradeSettings()); // TODO call this only on app version update@@ -1425,6 +1446,17 @@ export const actions = {type: types.SET_SELECTED_ENTRIES,selectedEntries}),+ addTag: (tag: any, parentTagGroupUuid: TS.Uuid) => (+ dispatch: (action) => void,+ getState: () => any+ ) => {+ const { locations } = getState();+ addTag(tag, parentTagGroupUuid, getTagLibrary(), locations);+ dispatch(actions.tagLibraryChanged());+ },+ tagLibraryChanged: () => ({+ type: types.SET_TAG_LIBRARY_CHANGED+ }),deleteDirectory: (directoryPath: string) => (dispatch: (action) => void,getState: () => any@@ -2666,6 +2698,7 @@ export const getLastSelectedEntryPath = (state: any) => {return currentDirectoryPath;};export const getSelectedTag = (state: any) => state.app.tag;+export const isTagLibraryChanged = (state: any) => state.app.tagLibraryChanged;export const getSelectedEntries = (state: any) =>state.app.selectedEntries ? state.app.selectedEntries : [];export const getSelectedEntriesLength = (state: any) =>diff --git a/app/reducers/index.ts b/app/reducers/index.tsindex 2728cc048..7121bad6c 100644--- a/app/reducers/index.ts+++ b/app/reducers/index.ts@@ -28,7 +28,7 @@ import locationIndex from './location-index';import searches from './searches';const externalLocations = window.ExtLocations || false;-const externalTagLibrary = window.ExtTagLibrary || false;+// const externalTagLibrary = window.ExtTagLibrary || false;const externalSearches = window.ExtSearches || false;let locationsInBlackList = false; // electron case@@ -45,7 +45,7 @@ const blacklist = ['app','locationIndex',locationsInBlackList ? 'locations' : '',- externalTagLibrary ? 'taglibrary' : '',+ // externalTagLibrary ? 'taglibrary' : '',externalSearches ? 'searches' : ''];@@ -118,7 +118,7 @@ const rootReducer = persistCombineReducers(rootPersistConfig, {settings,app,locations: externalLocations ? () => externalLocations : locations,- taglibrary: externalTagLibrary ? () => externalTagLibrary : taglibrary,+ taglibrary, // externalTagLibrary ? () => externalTagLibrary : taglibrary,searches: externalSearches ? () => externalSearches : searches,locationIndex});diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.tsindex 601015cb1..faea33d1e 100644--- a/app/reducers/tagging-actions.ts+++ b/app/reducers/tagging-actions.ts@@ -23,7 +23,6 @@ import {actions as AppActions,getLocationPersistTagsInSidecarFile} from './app';-import { actions as TagLibraryActions } from './taglibrary';import {extractFileExtension,extractFileName,@@ -44,6 +43,7 @@ import { Pro } from '../pro';import GlobalSearch from '../services/search-index';import { getPersistTagsInSidecarFile } from './settings';import { TS } from '-/tagspaces.namespace';+import { getTagLibrary, mergeTagGroup } from '-/services/taglibrary-utils';// export const defaultTagLocation = OpenLocationCode.encode(51.48, 0, undefined); // default tag coordinate Greenwich@@ -62,7 +62,7 @@ const actions = {dispatch: (action) => void,getState: () => any): Promise<boolean> => {- const { settings, taglibrary } = getState();+ const { settings } = getState();let defaultTagLocation;if (settings.geoTaggingFormat.toLowerCase() === 'mgrs') {defaultTagLocation = mgrs.forward([0, 51.48]);@@ -130,7 +130,7 @@ const actions = {const uniqueTags = [];processedTags.map(tag => {if (- taglibrary.findIndex(+ getTagLibrary().findIndex(tagGroup =>tagGroup.children.findIndex(obj => obj.title === tag.title) !==-1@@ -156,7 +156,7 @@ const actions = {created_date: new Date().getTime(),modified_date: new Date().getTime()};- dispatch(TagLibraryActions.mergeTagGroup(tagGroup));+ // dispatch(TagLibraryActions.mergeTagGroup(tagGroup));}}return Promise.all(promises).then(() => true);@@ -348,7 +348,7 @@ const actions = {dispatch: (actions: Object) => void,getState: () => any) => {- const { settings, taglibrary } = getState();+ const { settings } = getState();if (newTagTitle === undefined) {// eslint-disable-next-line no-param-reassignnewTagTitle = tag.title;@@ -517,7 +517,7 @@ const actions = {// filter existed in tagLibraryconst uniqueTags = [];if (- taglibrary.findIndex(+ getTagLibrary().findIndex(tagGroup =>tagGroup.children.findIndex(obj => obj.title === newTagTitle) !== -1) === -1 &&@@ -541,7 +541,7 @@ const actions = {created_date: new Date().getTime(),modified_date: new Date().getTime()};- dispatch(TagLibraryActions.mergeTagGroup(tagGroup));+ // dispatch(TagLibraryActions.mergeTagGroup(tagGroup));}}},@@ -783,7 +783,9 @@ const actions = {children: uniqueTags,modified_date: new Date().getTime()};- dispatch(TagLibraryActions.mergeTagGroup(changedTagGroup));+ const { locations } = getState();+ mergeTagGroup(changedTagGroup, getTagLibrary(), locations);+ // dispatch(TagLibraryActions.mergeTagGroup(changedTagGroup));}}};diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.tsindex 469ed9e9e..2de915630 100644--- a/app/reducers/taglibrary.ts+++ b/app/reducers/taglibrary.ts@@ -29,6 +29,7 @@ import { TS } from '-/tagspaces.namespace';import { Pro } from '-/pro';export const types = {+ DELETE_ALL: 'DELETE_ALL',CREATE_TAGGROUP: 'CREATE_TAGGROUP',IMPORT_TAGGROUP: 'IMPORT_TAGGROUP',IMPORT_OLD_TAGGROUP: 'IMPORT_OLD_TAGGROUP',@@ -52,6 +53,9 @@ export const types = {export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {switch (action.type) {+ case types.DELETE_ALL: {+ return [];+ }case types.CREATE_TAGGROUP: {return [...state,@@ -453,6 +457,9 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {};export const actions = {+ deleteAll: () => ({+ type: types.DELETE_ALL+ }),createTagGroup: (entry: TS.TagGroup) => (dispatch: (actions: Object) => void,getState: () => anydiff --git a/app/services/taglibrary-utils.ts b/app/services/taglibrary-utils.tsnew file mode 100644index 000000000..6c003eedf--- /dev/null+++ b/app/services/taglibrary-utils.ts@@ -0,0 +1,578 @@+import { TS } from '-/tagspaces.namespace';+import { Pro } from '-/pro';+import {+ extend,+ formatDateTime4Tag,+ immutablySwapItems,+ prepareTagGroupForExport+} from '@tagspaces/tagspaces-common/misc';+import versionMeta from '-/version.json';+import { getUuid, parseNewTags, saveAsTextFile } from '-/services/utils-io';+import AppConfig from '-/AppConfig';+import defaultTagLibrary from '../reducers/taglibrary-default';++export const tagLibraryKey = 'tsTagLibrary';++export function getTagLibrary(): Array<TS.TagGroup> {+ if (window.ExtTagLibrary) {+ return window.ExtTagLibrary;+ }+ const item = localStorage.getItem(tagLibraryKey);+ if (item) {+ return JSON.parse(item);+ }+ return defaultTagLibrary;+}++export function setTagLibrary(+ tagGroups: Array<TS.TagGroup>+): Array<TS.TagGroup> {+ if (tagGroups && tagGroups.length > 0) {+ localStorage.setItem(tagLibraryKey, JSON.stringify(tagGroups));+ }+ return tagGroups;+}++export function getAllTags(tagGroups?: Array<TS.TagGroup>) {+ if (tagGroups === undefined) {+ tagGroups = getTagLibrary();+ }+ const uniqueTags: TS.Tag[] = [];+ tagGroups.forEach(tagGroup => {+ tagGroup.children.forEach(tag => {+ const found = uniqueTags.find(uTag => uTag.title === tag.title);+ if (!found) {+ uniqueTags.push(tag);+ }+ });+ });+ return uniqueTags.sort((a, b) =>+ a.title > b.title ? 1 : a.title < b.title ? -1 : 0+ );+}++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) {+ const tagLibrary = entry;+ const jsonFormat =+ '{ "appName": "' ++ versionMeta.name ++ '", "appVersion": "' ++ versionMeta.version ++ '", "settingsVersion": ' ++ settingsVersion ++ ', "tagGroups": ';+ const allTagGroups = [];+ tagLibrary.forEach(value => {+ const preparedTagGroup = prepareTagGroupForExport(value);+ if (preparedTagGroup.title && preparedTagGroup.uuid) {+ allTagGroups.push(preparedTagGroup);+ }+ });++ const blob = new Blob(+ [jsonFormat + JSON.stringify(allTagGroups, null, 2) + '}'],+ {+ type: 'application/json'+ }+ );+ const dateTimeTag = formatDateTime4Tag(new Date(), true);+ saveAsTextFile(blob, 'tag-library [tagspaces ' + dateTimeTag + '].json');+ console.log('Tag library exported...');+}++export function createTagGroup(+ entry: TS.TagGroup,+ tagGroups: Array<TS.TagGroup>,+ locations: Array<TS.Location>+): Array<TS.TagGroup> {+ if (Pro && entry.locationId) {+ const location: TS.Location = locations.find(+ l => l.uuid === entry.locationId+ );+ if (location) {+ Pro.MetaOperations.createTagGroup(location.path, entry);+ }+ }+ return setTagLibrary([+ ...tagGroups,+ {+ ...entry,+ created_date: new Date().getTime(),+ modified_date: new Date().getTime()+ }+ ]);+}++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 = {+ ...tagGroup,+ 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>+) {+ if (Pro && entry.locationId) {+ const location: TS.Location = locations.find(+ l => l.uuid === entry.locationId+ );+ if (location) {+ Pro.MetaOperations.editTagGroup(location.path, entry);+ }+ }+ return updateTagGroup(entry, 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 = {+ ...tagGroup,+ 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) {+ 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 = extend({ created_date: new Date() }, entry, {+ modified_date: new Date()+ });+ return setTagLibrary([+ ...tagGroups.slice(0, indexForEditing),+ modifiedEntry,+ ...tagGroups.slice(indexForEditing + 1)+ ]);+ }+ return tagGroups;+}++/* Why this function exist?+export const getTagColors = (allTags: Array<TS.Tag>, tagTitle: string) => {+ const tagColors = {+ textcolor: '',+ color: ''+ };+ allTags.forEach((tag: TS.Tag) => {+ if (tag.title === tagTitle) {+ tagColors.textcolor = tag.textcolor;+ tagColors.color = tag.color;+ }+ });+ return tagColors;+};*/diff --git a/app/tagspaces.namespace.d.ts b/app/tagspaces.namespace.d.tsindex 7cc8eb36e..5c52d184f 100644--- a/app/tagspaces.namespace.d.ts+++ b/app/tagspaces.namespace.d.ts@@ -1,5 +1,3 @@-import { PerspectiveIDs } from '-/perspectives';-/*** TagSpaces - universal file and folder organizer* Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)diff --git a/app/utils/HandleAuth.tsx b/app/utils/HandleAuth.tsxindex 45ac162be..58f7f4852 100644--- a/app/utils/HandleAuth.tsx+++ b/app/utils/HandleAuth.tsx@@ -8,15 +8,16 @@ 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 TagGroupActions } from '-/reducers/taglibrary';import { actions as AppActions } from '-/reducers/app';import { TS } from '-/tagspaces.namespace';+import { importTagGroups } from "-/services/taglibrary-utils";interface Props {loggedIn: (user: CognitoUserInterface) => void;initApp: () => void;addLocations: (locations: Array<TS.Location>, override: boolean) => void;- importTagGroups: (tagGroups: Array<TS.TagGroup>, replace: boolean) => void;+ // importTagGroups: (tagGroups: Array<TS.TagGroup>, replace: boolean) => void;}function HandleAuth(props: Props) {const username = useRef(undefined);@@ -93,7 +94,7 @@ function HandleAuth(props: Props) {});if (data && data.TagGroupsByTenant.items.length > 0) {const tagGroupsByTenant = data.TagGroupsByTenant.items[0];- props.importTagGroups(+ importTagGroups(JSON.parse(tagGroupsByTenant.tagGroups),tagGroupsByTenant.replace);@@ -124,7 +125,7 @@ function mapDispatchToProps(dispatch) {loggedIn: AppActions.loggedIn,initApp: AppActions.initApp,addLocations: LocationActions.addLocations,- importTagGroups: TagGroupActions.importTagGroups+ // importTagGroups: TagGroupActions.importTagGroups},dispatch);