TagSpaces is an offline, open source, document manager with tagging support
Fix colors of filename based tags (#1859)
Stanimirf87e82d82203
diff --git a/app/components/TagContainer.tsx b/app/components/TagContainer.tsxindex 9227f4f8d..9b1c5aa70 100644--- a/app/components/TagContainer.tsx+++ b/app/components/TagContainer.tsx@@ -29,7 +29,7 @@ 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';+import { getTagColors } from '-/services/taglibrary-utils';interface Props {tag: TS.Tag;@@ -87,9 +87,20 @@ function TagContainer(props: Props) {isTagDate = !isTagGeo && isDateTimeTag(title);}- // const tagColors = getTagColors(getAllTags(), title);- const textColor = tag.textcolor || defaultTextColor; // || tagColors.textcolor- const backgroundColor = tag.color || defaultBackgroundColor; // || tagColors.color+ let textColor: string;+ let backgroundColor: string;+ if (tag.color && tag.textcolor) {+ textColor = tag.textcolor;+ backgroundColor = tag.color;+ } else {+ const tagColors = getTagColors(+ title,+ defaultTextColor,+ defaultBackgroundColor+ );+ textColor = tagColors.textcolor;+ backgroundColor = tagColors.color;+ }let tid = 'tagContainer_';if (title && title.length > 0) {@@ -266,7 +277,6 @@ function TagContainer(props: Props) {function mapStateToProps(state) {return {- // allTags: getAllTags(state),defaultBackgroundColor: getTagColor(state),defaultTextColor: getTagTextColor(state)// selectedEntries: getSelectedEntries(state)diff --git a/app/components/TagsPreview.tsx b/app/components/TagsPreview.tsxindex be8979ca5..eb8d55084 100644--- a/app/components/TagsPreview.tsx+++ b/app/components/TagsPreview.tsx@@ -20,14 +20,18 @@ 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 {getCurrentLanguage,getTagColor,getTagTextColor} from '-/reducers/settings';import i18n from '-/services/i18n';-import { getAllTags, getTagLibrary } from '-/services/taglibrary-utils';+import {+ getAllTags,+ getTagColors,+ getTagLibrary+} from '-/services/taglibrary-utils';interface Props {tags: Array<TS.Tag>;@@ -47,16 +51,34 @@ function TagsPreview(props: Props) {tagNames = tagNames + tag.title + ' ';});- // const tag1Colors = getTagColors(allTags.current, tags[0].title);- const firstTagColor = tags[0].color || defaultBackgroundColor;- const firstTagTextColor = tags[0].textcolor || defaultTextColor;+ let firstTagColor: string;+ let firstTagTextColor: string;+ if (tags[0].color && tags[0].textcolor) {+ firstTagColor = tags[0].textcolor;+ firstTagTextColor = tags[0].color;+ } else {+ const tagColors = getTagColors(+ tags[0].title,+ defaultTextColor,+ defaultBackgroundColor+ );+ firstTagColor = tagColors.textcolor;+ firstTagTextColor = tagColors.color;+ }+let secondTagColor = defaultBackgroundColor;let moreThanOne = false;if (tags[1]) {moreThanOne = true;- // const tag2Colors = getTagColors(allTags.current, tags[1].title);if (tags[1].color) {- secondTagColor = tags[1].color; // || tag2Colors.color;+ secondTagColor = tags[1].color;+ } else {+ const tag2Colors = getTagColors(+ tags[1].title,+ defaultTextColor,+ defaultBackgroundColor+ );+ secondTagColor = tag2Colors.color;}}return (diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.tsindex 928857270..4101cdf3f 100644--- a/app/reducers/taglibrary.ts+++ b/app/reducers/taglibrary.ts@@ -788,17 +788,3 @@ export const getAllTags = (state: any) => {a.title > b.title ? 1 : a.title < b.title ? -1 : 0);};--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/services/taglibrary-utils.ts b/app/services/taglibrary-utils.tsindex 80c342bf4..8f4c2f2d5 100644--- a/app/services/taglibrary-utils.ts+++ b/app/services/taglibrary-utils.ts@@ -569,17 +569,23 @@ function updateTagGroup(return tagGroups;}-/* Why this function exist?-export const getTagColors = (allTags: Array<TS.Tag>, tagTitle: string) => {+/**+ * get tagColor used to show color of the filename tags+ */+export const getTagColors = (+ tagTitle: string,+ defaultTextColor: string,+ defaultBackgroundColor: string+) => {const tagColors = {- textcolor: '',- color: ''+ textcolor: defaultTextColor,+ color: defaultBackgroundColor};- allTags.forEach((tag: TS.Tag) => {+ getAllTags().forEach((tag: TS.Tag) => {if (tag.title === tagTitle) {tagColors.textcolor = tag.textcolor;tagColors.color = tag.color;}});return tagColors;-};*/+};