Skip to content

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

Tag color from the tags in location tag group do not apply (#2323)

Stanimir9f6ff75dae79
diff --git a/src/renderer/components/TagContainer.tsx b/src/renderer/components/TagContainer.tsx
index 7c85f127e..3fa642e5d 100644
--- a/src/renderer/components/TagContainer.tsx
+++ b/src/renderer/components/TagContainer.tsx
@@ -30,6 +30,7 @@ import PlaceIcon from '@mui/icons-material/Place';
import { formatDateTime } from '@tagspaces/tagspaces-common/misc';
import React, { useMemo } from 'react';
import { useSelector } from 'react-redux';
+import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';
interface Props {
tag: TS.Tag;
@@ -68,6 +69,7 @@ function TagContainer(props: Props) {
const { addTags } = useTaggingActionsContext();
const { selectedEntries } = useSelectedEntriesContext();
+ const { tagGroups } = useEditedTagLibraryContext();
const defaultBackgroundColor = useSelector(getTagColor);
const defaultTextColor = useSelector(getTagTextColor);
@@ -86,6 +88,7 @@ function TagContainer(props: Props) {
const tagColors = getTagColors(
title,
+ tagGroups,
tag.textcolor || defaultTextColor,
tag.color || defaultBackgroundColor,
);
diff --git a/src/renderer/components/TagsPreview.tsx b/src/renderer/components/TagsPreview.tsx
index e34bdfa31..1dd291681 100644
--- a/src/renderer/components/TagsPreview.tsx
+++ b/src/renderer/components/TagsPreview.tsx
@@ -23,6 +23,7 @@ import { useSelector } from 'react-redux';
import { getTagColor, getTagTextColor } from '-/reducers/settings';
import { getTagColors } from '-/services/taglibrary-utils';
import { useTranslation } from 'react-i18next';
+import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';
interface Props {
tags: Array<TS.Tag>;
@@ -30,6 +31,7 @@ interface Props {
function TagsPreview(props: Props) {
const { t } = useTranslation();
+ const { tagGroups } = useEditedTagLibraryContext();
const defaultBackgroundColor = useSelector(getTagColor);
const defaultTextColor = useSelector(getTagTextColor);
@@ -51,6 +53,7 @@ function TagsPreview(props: Props) {
} else {
const tagColors = getTagColors(
tags[0].title,
+ tagGroups,
defaultTextColor,
defaultBackgroundColor,
);
@@ -67,6 +70,7 @@ function TagsPreview(props: Props) {
} else {
const tag2Colors = getTagColors(
tags[1].title,
+ tagGroups,
defaultTextColor,
defaultBackgroundColor,
);
diff --git a/src/renderer/hooks/ChatProvider.tsx b/src/renderer/hooks/ChatProvider.tsx
index ca3145dbe..e21de6525 100644
--- a/src/renderer/hooks/ChatProvider.tsx
+++ b/src/renderer/hooks/ChatProvider.tsx
@@ -1350,6 +1350,7 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
title: tagTitle,
...getTagColors(
tagTitle,
+ tagGroups,
defaultTextColor,
defaultBackgroundColor,
),
diff --git a/src/renderer/hooks/SavedSearchesContextProvider.tsx b/src/renderer/hooks/SavedSearchesContextProvider.tsx
index beaf350d9..6ddb6dede 100644
--- a/src/renderer/hooks/SavedSearchesContextProvider.tsx
+++ b/src/renderer/hooks/SavedSearchesContextProvider.tsx
@@ -20,6 +20,7 @@ import {
getTagTextColor,
} from '-/reducers/settings';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
+import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';
type SavedSearchesContextData = {
searches: TS.SearchQuery[];
@@ -50,6 +51,7 @@ export const SavedSearchesContextProvider = ({
}: SavedSearchesContextProviderProps) => {
const searchesKey = 'tsSavedSearches';
const { setSearchQuery } = useDirectoryContentContext();
+ const { tagGroups } = useEditedTagLibraryContext();
const reduxSearches = useSelector(getSearches);
const defaultBackgroundColor = useSelector(getTagColor);
const defaultTextColor = useSelector(getTagTextColor);
@@ -152,6 +154,7 @@ export const SavedSearchesContextProvider = ({
return tags.map((tag) => {
const tagColors = getTagColors(
tag.title,
+ tagGroups,
defaultTextColor,
defaultBackgroundColor,
);
diff --git a/src/renderer/services/taglibrary-utils.ts b/src/renderer/services/taglibrary-utils.ts
index 47621c357..504273fa4 100644
--- a/src/renderer/services/taglibrary-utils.ts
+++ b/src/renderer/services/taglibrary-utils.ts
@@ -6,6 +6,7 @@ import {
import versionMeta from '-/version.json';
import { saveAsTextFile } from '-/services/utils-io';
import defaultTagLibrary from '../reducers/taglibrary-default';
+import TagGroup = TS.TagGroup;
export const tagLibraryKey = 'tsTagLibrary';
@@ -89,10 +90,13 @@ export function exportTagGroups(
*/
export const getTagColors = (
tagTitle: string,
+ tagGroups: TagGroup[],
defaultTextColor: string,
defaultBackgroundColor: string,
) => {
- const tagExist = getAllTags().find((tag: TS.Tag) => tag.title === tagTitle);
+ const tagExist = getAllTags(tagGroups).find(
+ (tag: TS.Tag) => tag.title === tagTitle,
+ );
return tagExist
? {
textcolor: tagExist.textcolor || defaultTextColor,