Skip to content

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

TSN656 - Add input fields for entering lat and long directly in the g… (#1427)

Stanimirfc3d87fd8d1f
diff --git a/app/components/dialogs/EditEntryTagDialog.tsx b/app/components/dialogs/EditEntryTagDialog.tsx
index 9dacb2770..481ef66ff 100644
--- a/app/components/dialogs/EditEntryTagDialog.tsx
+++ b/app/components/dialogs/EditEntryTagDialog.tsx
@@ -60,8 +60,8 @@ const GeoTagEditor = Pro && Pro.UI ? Pro.UI.GeoTagEditor : React.Fragment;
const DateTagEditor = Pro && Pro.UI ? Pro.UI.DateTagEditor : React.Fragment;
const EditEntryTagDialog = (props: Props) => {
- const [disableConfirmButton, setDisableConfirmButton] = useState(true);
- const [errorTag, setErrorTag] = useState(false);
+ const [showAdvancedMode, setShowAdvancedMode] = useState<boolean>(false);
+ const [errorTag, setErrorTag] = useState<boolean>(false);
const [title, setTitle] = useState(
props.selectedTag && props.selectedTag.title
);
@@ -93,18 +93,15 @@ const EditEntryTagDialog = (props: Props) => {
const tagCheck = RegExp(/^[^#/\\ [\]]{1,}$/);
if (title && tagCheck.test(title)) {
setErrorTag(false);
- setDisableConfirmButton(false);
} else {
setErrorTag(true);
- setDisableConfirmButton(true);
}
}
function onConfirm() {
- if (!disableConfirmButton) {
+ if (!errorTag) {
props.editTagForEntry(props.currentEntryPath, props.selectedTag, title);
setErrorTag(false);
- setDisableConfirmButton(true);
props.onClose();
}
}
@@ -143,10 +140,10 @@ const EditEntryTagDialog = (props: Props) => {
</FormControl>
{showGeoEditor && (
<GeoTagEditor
- key={title}
geoTag={title}
onChange={setTitle}
zoom={title === defaultTagLocation ? 2 : undefined}
+ showAdvancedMode={showAdvancedMode}
/>
)}
{isShowDatePeriodEditor && (
@@ -161,22 +158,36 @@ const EditEntryTagDialog = (props: Props) => {
function renderActions() {
return (
- <DialogActions>
- <Button
- data-tid="closeEditTagEntryDialog"
- onClick={props.onClose}
- color="primary"
- >
- {i18n.t('core:cancel')}
- </Button>
- <Button
- disabled={disableConfirmButton}
- onClick={onConfirm}
- data-tid="confirmEditTagEntryDialog"
- color="primary"
- >
- {i18n.t('core:ok')}
- </Button>
+ <DialogActions style={{ justifyContent: 'space-between' }}>
+ {GeoTagEditor && isPlusCode(title) ? (
+ <Button
+ data-tid="switchAdvancedModeTID"
+ onClick={() => setShowAdvancedMode(!showAdvancedMode)}
+ >
+ {showAdvancedMode
+ ? i18n.t('core:switchSimpleMode')
+ : i18n.t('core:switchAdvancedMode')}
+ </Button>
+ ) : (
+ <div />
+ )}
+ <div>
+ <Button
+ data-tid="closeEditTagEntryDialog"
+ onClick={props.onClose}
+ color="primary"
+ >
+ {i18n.t('core:cancel')}
+ </Button>
+ <Button
+ disabled={errorTag}
+ onClick={onConfirm}
+ data-tid="confirmEditTagEntryDialog"
+ color="primary"
+ >
+ {i18n.t('core:ok')}
+ </Button>
+ </div>
</DialogActions>
);
}
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index dd7819249..ded7d6bb7 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -554,5 +554,7 @@
"duplicateTitle": "Search name already exist!",
"savedSearchesTitle": "Saved Searches",
"exportCsv": "Export current files and folders as CSV file",
+ "lat": "Latitude",
+ "lng": "Longitude",
"-": "-"
}
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index f41684bf5..b021c5472 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -519,6 +519,12 @@ export default (state: any = initialState, action: any) => {
return state;
}
case types.REFLECT_RENAME_ENTRY: {
+ const extractedTags = extractTagsAsObjects(
+ action.newPath,
+ AppConfig.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
+
return {
...state,
currentDirectoryEntries: state.currentDirectoryEntries.map(entry => {
@@ -536,11 +542,7 @@ export default (state: any = initialState, action: any) => {
),
tags: [
...entry.tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
- ...extractTagsAsObjects(
- action.newPath,
- AppConfig.tagDelimiter,
- PlatformIO.getDirSeparator()
- )
+ ...extractedTags
]
};
}),
@@ -550,7 +552,11 @@ export default (state: any = initialState, action: any) => {
}
return {
...entry,
- path: action.newPath // TODO handle change extension case
+ path: action.newPath, // TODO handle change extension case
+ tags: [
+ ...entry.tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
+ ...extractedTags
+ ]
// shouldReload: true
};
})
diff --git a/app/utils/paths.ts b/app/utils/paths.ts
index 46235a3c5..0c2a7038f 100644
--- a/app/utils/paths.ts
+++ b/app/utils/paths.ts
@@ -348,22 +348,21 @@ export function extractTagsAsObjects(
dirSeparator: string // = AppConfig.dirSeparator
): Array<TS.Tag> {
const tagsInFileName = extractTags(filePath, tagDelimiter, dirSeparator);
- const tagArray = [];
- tagsInFileName.map(tag => {
- tagArray.push({
- title: '' + tag,
- type: 'plain'
- });
- return true;
- });
- return tagArray;
+ return tagsAsObjects(tagsInFileName);
+}
+
+export function tagsAsObjects(tags: Array<string>): Array<TS.Tag> {
+ return tags.map(tag => ({
+ title: '' + tag,
+ type: 'plain'
+ }));
}
export function extractTags(
filePath: string,
tagDelimiter: string = AppConfig.tagDelimiter,
dirSeparator: string // = AppConfig.dirSeparator
-) {
+): Array<string> {
// console.log('Extracting tags from: ' + filePath);
const fileName = extractFileName(filePath, dirSeparator);
// WithoutExt
diff --git a/package.json b/package.json
index 8455aa628..0a9763b18 100644
--- a/package.json
+++ b/package.json
@@ -254,6 +254,7 @@
"chokidar": "^3.5.1",
"classnames": "^2.2.6",
"clone": "^2.1.2",
+ "coordinate-parser": "^1.0.7",
"core-js": "2",
"crypto-js": "^4.0.0",
"csv-stringify": "^5.6.2",
diff --git a/yarn.lock b/yarn.lock
index ab48931d3..9e629342d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6651,6 +6651,11 @@ cookie@^0.4.0:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1"
integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==
+coordinate-parser@^1.0.7:
+ version "1.0.7"
+ resolved "https://registry.yarnpkg.com/coordinate-parser/-/coordinate-parser-1.0.7.tgz#9350485f03146af0f377dd51a0907a0ac684363e"
+ integrity sha512-pkcjigkAEjU5JsTYnuXLkRgR6T5fF/7GXR4p9vWJesy8fKwsheN8zC5d3sSvdMmWihHB4u48xWZ5mUCcgBIEpw==
+
copy-concurrently@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/copy-concurrently/-/copy-concurrently-1.0.5.tgz#92297398cae34937fcafd6ec8139c18051f0b5e0"