Skip to content

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

fix: issue with duplicated tags

Stanimird68486bdf634
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index 9df2deac9..18fc445eb 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -383,7 +383,7 @@ const EntryContainer = (props: Props) => {
props.updateOpenedFile(openedFile.path, {
...openedFile,
editMode: false,
- shouldReload: true
+ shouldReload: !openedFile.shouldReload
});
}
}
diff --git a/app/components/FileView.tsx b/app/components/FileView.tsx
index a7d209d86..6959a685a 100644
--- a/app/components/FileView.tsx
+++ b/app/components/FileView.tsx
@@ -133,6 +133,7 @@ const FileView = (props: Props) => {
const areEqual = (prevProp, nextProp) =>
nextProp.openedFile.path === prevProp.openedFile.path &&
nextProp.openedFile.editMode === prevProp.openedFile.editMode &&
+ nextProp.openedFile.shouldReload === prevProp.openedFile.shouldReload &&
nextProp.isFullscreen === prevProp.isFullscreen;
/* ((nextProp.openedFile.editMode === undefined &&
prevProp.openedFile.editMode === true) ||
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 456b16549..910ac04ec 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -1772,26 +1772,10 @@ export const actions = {
entry
}),
/**
- * @deprecated use updateCurrentDirEntry instead
* @param path
- * @param entryMeta
+ * @param tags
+ * @param updateIndex
*/
- /* reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => (
- dispatch: (actions: Object) => void
- ) => {
- dispatch(actions.reflectUpdateSidecarMetaInt(path, entryMeta));
- dispatch(LocationIndexActions.reflectUpdateSidecarMeta(path, entryMeta));
- }, */
- /**
- * @deprecated use updateCurrentDirEntry instead
- * @param path
- * @param entryMeta
- */
- /* reflectUpdateSidecarMetaInt: (path: string, entryMeta: Object) => ({
- type: types.REFLECT_UPDATE_SIDECARMETA,
- path,
- entryMeta
- }), */
reflectUpdateSidecarTags: (
path: string,
tags: Array<TS.Tag>,
@@ -1801,7 +1785,11 @@ export const actions = {
/**
* if its have openedFiles updateCurrentDirEntry is called from FolderContainer (useEffect -> ... if (openedFile.changed)
*/
- if (openedFiles.length === 0 || selectedEntries.length > 1) {
+ if (
+ openedFiles.length === 0 ||
+ !openedFiles.some(obj => obj.path === path) ||
+ selectedEntries.length > 1
+ ) {
dispatch(actions.updateCurrentDirEntry(path, { tags }));
}
if (updateIndex) {
diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.ts
index 25178c334..fa2367667 100644
--- a/app/reducers/tagging-actions.ts
+++ b/app/reducers/tagging-actions.ts
@@ -402,42 +402,48 @@ const actions = {
} else if (tag.type === 'sidecar') {
loadMetaDataPromise(path)
.then(fsEntryMeta => {
- let addMode = true;
let tagFoundPosition = -1;
- fsEntryMeta.tags.map((sidecarTag, index) => {
+ let newTagsArray = fsEntryMeta.tags.map((sidecarTag, index) => {
if (sidecarTag.title === tag.title) {
- // eslint-disable-next-line no-param-reassign
- sidecarTag.title = newTagTitle;
- addMode = false;
tagFoundPosition = index;
+ return {
+ ...sidecarTag,
+ title: newTagTitle
+ };
}
- return true;
+ return sidecarTag;
});
if (tag.position !== undefined && tagFoundPosition > -1) {
- // move tag
- const element = fsEntryMeta.tags[tagFoundPosition];
- fsEntryMeta.tags.splice(tagFoundPosition, 1);
- fsEntryMeta.tags.splice(tag.position, 0, element);
+ // move tag (reorder)
+ const element = newTagsArray[tagFoundPosition];
+ newTagsArray.splice(tagFoundPosition, 1);
+ newTagsArray.splice(tag.position, 0, element);
}
- if (addMode) {
- // eslint-disable-next-line no-param-reassign
- tag.title = newTagTitle;
- fsEntryMeta.tags.push(tag);
+ if (tagFoundPosition === -1) {
+ // Add mode
+ newTagsArray.push({ ...tag, title: newTagTitle });
}
- const updatedFsEntryMeta = {
+ // clear duplicates
+ newTagsArray = newTagsArray.filter(
+ (item, pos, array) =>
+ array.findIndex(el => el.title === item.title) === pos
+ );
+ saveMetaDataPromise(path, {
...fsEntryMeta,
- tags: [...fsEntryMeta.tags]
- };
- saveMetaDataPromise(path, updatedFsEntryMeta)
+ tags: newTagsArray
+ })
.then(() => {
- dispatch(
- AppActions.updateOpenedFile(path, {
- tags: fsEntryMeta.tags
- })
- );
+ const { openedFiles } = getState().app;
+ if (openedFiles.find(obj => obj.path === path)) {
+ dispatch(
+ AppActions.updateOpenedFile(path, {
+ tags: newTagsArray
+ })
+ );
+ }
// TODO rethink this updateCurrentDirEntry and not need for KanBan
dispatch(
- AppActions.reflectUpdateSidecarTags(path, fsEntryMeta.tags)
+ AppActions.reflectUpdateSidecarTags(path, newTagsArray, true)
);
return true;
})
@@ -464,11 +470,14 @@ const actions = {
const fsEntryMeta = { tags: [tag] };
saveMetaDataPromise(path, fsEntryMeta)
.then(() => {
- dispatch(
- AppActions.updateOpenedFile(path, {
- tags: fsEntryMeta.tags
- })
- );
+ const { openedFiles } = getState().app;
+ if (openedFiles.find(obj => obj.path === path)) {
+ dispatch(
+ AppActions.updateOpenedFile(path, {
+ tags: fsEntryMeta.tags
+ })
+ );
+ }
// TODO rethink this updateCurrentDirEntry and not need for KanBan
dispatch(
AppActions.reflectUpdateSidecarTags(path, fsEntryMeta.tags)
@@ -644,7 +653,10 @@ const actions = {
.then(() => {
// TODO rethink this updateCurrentDirEntry and not need for KanBan
dispatch(AppActions.reflectUpdateSidecarTags(path, []));
- dispatch(AppActions.updateOpenedFile(path, { tags: [] }));
+ const { openedFiles } = getState().app;
+ if (openedFiles.find(obj => obj.path === path)) {
+ dispatch(AppActions.updateOpenedFile(path, { tags: [] }));
+ }
removeAllTagsFromFilename();
return true;
})