TagSpaces is an offline, open source, document manager with tagging support
geo tags are always sidecar (#2054)
Stanimira71bc17f6f2b
diff --git a/src/renderer/components/dialogs/EditEntryTagDialog.tsx b/src/renderer/components/dialogs/EditEntryTagDialog.tsxindex 477113d3b..8beb62f30 100644--- a/src/renderer/components/dialogs/EditEntryTagDialog.tsx+++ b/src/renderer/components/dialogs/EditEntryTagDialog.tsx@@ -23,9 +23,6 @@ import React, {ChangeEvent,useRef,} from 'react';-import { styled } from '@mui/material/styles';-import { connect } from 'react-redux';-import { bindActionCreators } from 'redux';import Button from '@mui/material/Button';import TextField from '@mui/material/TextField';import DialogActions from '@mui/material/DialogActions';@@ -41,19 +38,16 @@ import { getSelectedTag } from '-/reducers/app';import { isDateTimeTag } from '-/utils/dates';import { TS } from '-/tagspaces.namespace';import useValidation from '-/utils/useValidation';-import { getMapTileServer } from '-/reducers/settings';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import { useTheme } from '@mui/material/styles';import useMediaQuery from '@mui/material/useMediaQuery';import { useTranslation } from 'react-i18next';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';+import { useSelector } from 'react-redux';interface Props {open: boolean;onClose: () => void;- selectedTag: TS.Tag;- tileServer: TS.MapTileServer;- geoTaggingFormat: string;}const GeoTagEditor = Pro && Pro.UI ? Pro.UI.GeoTagEditor : React.Fragment;@@ -62,11 +56,11 @@ const DateTagEditor = Pro && Pro.UI ? Pro.UI.DateTagEditor : React.Fragment;function EditEntryTagDialog(props: Props) {const { t } = useTranslation();- const { editTagForEntry } = useTaggingActionsContext();+ const { addTagsToEntry, editTagForEntry } = useTaggingActionsContext();+ const selectedTag: TS.Tag = useSelector(getSelectedTag);const [showAdvancedMode, setShowAdvancedMode] = useState<boolean>(false);- const [title, setTitle] = useState(- props.selectedTag && props.selectedTag.title,- );+ const [title, setTitle] = useState(selectedTag && selectedTag.title);+const titleRef = useRef<HTMLInputElement>(null);const isShowDatePeriodEditor = useMemo(() => {let showDatePeriodEditor = false;@@ -111,12 +105,12 @@ function EditEntryTagDialog(props: Props) {function onConfirm() {if (handleValidation() && !haveError()) {- /* if (props.selectedEntries.length > 0) {- props.selectedEntries.forEach(entry =>- props.editTagForEntry(entry.path, props.selectedTag, title)- );- } else { */- editTagForEntry(props.selectedTag.path, props.selectedTag, title);+ const isNew = selectedTag.functionality === 'geoTagging'; //path.includes(props.selectedTag.title);+ if (isNew) {+ addTagsToEntry(selectedTag.path, [{ ...selectedTag, title }]);+ } else {+ editTagForEntry(selectedTag.path, selectedTag, title);+ }props.onClose();}}@@ -172,15 +166,13 @@ function EditEntryTagDialog(props: Props) {onChange={setTitle}// zoom={title === defaultTagLocation ? 2 : undefined} TODO defaultTagLocation can be in MGRS formatshowAdvancedMode={showAdvancedMode}- geoTaggingFormat={props.geoTaggingFormat}haveError={haveError}setError={setError}- tileServer={props.tileServer}/>)}{editDisabled && isShowDatePeriodEditor && (<DateTagEditor- datePeriodTag={props.selectedTag && props.selectedTag.title}+ datePeriodTag={selectedTag && selectedTag.title}onChange={setTitle}/>)}@@ -254,17 +246,4 @@ function EditEntryTagDialog(props: Props) {);}-function mapStateToProps(state) {- return {- selectedTag: getSelectedTag(state),- tileServer: getMapTileServer(state),- geoTaggingFormat: state.settings.geoTaggingFormat,- };-}--const areEqual = (prevProp, nextProp) =>- JSON.stringify(nextProp.selectedTag) === JSON.stringify(prevProp.selectedTag);--export default connect(mapStateToProps)(- React.memo(EditEntryTagDialog, areEqual),-);+export default EditEntryTagDialog;diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsxindex a6f7781f3..8197fb913 100644--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx@@ -66,7 +66,11 @@ type extractOptions = {type TaggingActionsContextData = {extractContent: (options?: extractOptions) => Promise<boolean>;addTags: (paths: Array<string>, tags: Array<TS.Tag>) => Promise<boolean>;- addTagsToEntry: (path: string, tags: Array<TS.Tag>) => Promise<string>;+ addTagsToEntry: (+ path: string,+ tags: Array<TS.Tag>,+ reflect?: boolean,+ ) => Promise<string>;editTagForEntry: (path: string, tag: TS.Tag, newTagTitle?: string) => void;removeTags: (paths: Array<string>, tags?: Array<TS.Tag>) => Promise<boolean>;removeTagsFromEntry: (path: string, tags?: Array<TS.Tag>) => Promise<string>;@@ -131,6 +135,37 @@ export const TaggingActionsContextProvider = ({});}+ function addTagsToFilePath(path: string, tags: string[]) {+ if (tags && tags.length > 0) {+ const extractedTags: string[] = extractTags(+ path,+ tagDelimiter,+ PlatformIO.getDirSeparator(),+ );+ const uniqueTags = tags.filter(+ (tag) => !extractedTags.some((tagName) => tagName === tag),+ );+ const fileName = extractFileName(path, PlatformIO.getDirSeparator());+ const containingDirectoryPath = extractContainingDirectoryPath(+ path,+ PlatformIO.getDirSeparator(),+ );++ return (+ (containingDirectoryPath+ ? containingDirectoryPath + PlatformIO.getDirSeparator()+ : '') ++ generateFileName(+ fileName,+ [...extractedTags, ...uniqueTags],+ tagDelimiter,+ prefixTagContainer,+ )+ );+ }+ return path;+ }+function addTags(paths: Array<string>,tags: Array<TS.Tag>,@@ -145,7 +180,7 @@ export const TaggingActionsContextProvider = ({const processedTags = [];tags.map((pTag) => {const tag = { ...pTag };- tag.type = 'sidecar';+ tag.type = persistTagsInSidecarFile ? 'sidecar' : 'plain';if (tag.id) {delete tag.id;}@@ -157,7 +192,6 @@ export const TaggingActionsContextProvider = ({if (tag.functionality === 'geoTagging') {if (Pro) {tag.path = paths[0]; // todo rethink and remove this!- // delete tag.functionality;tag.title = defaultTagLocation;dispatch(AppActions.toggleEditTagDialog(tag));} else {@@ -368,7 +402,7 @@ export const TaggingActionsContextProvider = ({fsEntryMeta.tags,);if (uniqueTags.length > 0) {- const fileName = extractFileName(path, PlatformIO.getDirSeparator());+ /*const fileName = extractFileName(path, PlatformIO.getDirSeparator());const containingDirectoryPath = extractContainingDirectoryPath(path,PlatformIO.getDirSeparator(),@@ -386,14 +420,24 @@ export const TaggingActionsContextProvider = ({extractedTags,tagDelimiter,prefixTagContainer,- );- return renameFile(path, newFilePath).then(() => {- return newFilePath;- });+ );*/+ const newFilePath = addTagsToFilePath(+ path,+ uniqueTags.map((tag) => tag.title),+ );+ if (path !== newFilePath) {+ return renameFile(path, newFilePath).then(() => {+ return newFilePath;+ });+ }}} else {// Handling tags in filename by no sidecar- const fileName = extractFileName(path, PlatformIO.getDirSeparator());+ const newFilePath = addTagsToFilePath(+ path,+ tags.map((tag) => tag.title),+ );+ /*const fileName = extractFileName(path, PlatformIO.getDirSeparator());const containingDirectoryPath = extractContainingDirectoryPath(path,PlatformIO.getDirSeparator(),@@ -419,7 +463,7 @@ export const TaggingActionsContextProvider = ({extractedTags,tagDelimiter,prefixTagContainer,- );+ );*/if (path !== newFilePath) {return renameFile(path, newFilePath).then(() => {return newFilePath;@@ -432,7 +476,7 @@ export const TaggingActionsContextProvider = ({newTagsArray: Array<TS.Tag>,fileTagsArray: string[],sideCarTagsArray: Array<TS.Tag>,- ) {+ ): TS.Tag[] {const newTags = [];for (let i = 0; i < newTagsArray.length; i += 1) {// check if tag is already in the fileTagsArray