TagSpaces is an offline, open source, document manager with tagging support
fix: tag and tag preview color handling
Ilian Sapundshievb116a724793a
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsxindex 3bcd034ba..070ce60cb 100644--- a/app/components/EntryContainer.tsx+++ b/app/components/EntryContainer.tsx@@ -67,7 +67,6 @@ import {actions as SettingsActions,isDesktopMode,getKeyBindingObject,- getTagColor,getMapTileServer} from '-/reducers/settings';import TaggingActions from '-/reducers/tagging-actions';@@ -182,7 +181,6 @@ interface Props {currentDirectoryPath: string | null;isDesktopMode: boolean;tileServer: TS.MapTileServer;- defaultTagColor?: string;}const EntryContainer = (props: Props) => {@@ -820,7 +818,7 @@ const EntryContainer = (props: Props) => {</div>);- const { classes, keyBindings, theme, defaultTagColor } = props;+ const { classes, keyBindings, theme } = props;const fileTitle: string = openedFile.path? extractTitle(@@ -928,10 +926,7 @@ const EntryContainer = (props: Props) => {</Box></Button>)}- <TagsPreview- tags={openedFile.tags}- defaultTagColor={defaultTagColor}- />+ <TagsPreview tags={openedFile.tags} /></Box><div className={classes.entryCloseSection}>{editingSupported && openedFile.editMode && (@@ -1165,7 +1160,6 @@ const EntryContainer = (props: Props) => {function mapStateToProps(state) {return {settings: state.settings,- defaultTagColor: getTagColor(state),isReadOnlyMode: isReadOnlyMode(state),keyBindings: getKeyBindingObject(state),isDesktopMode: isDesktopMode(state),diff --git a/app/components/TagContainer.tsx b/app/components/TagContainer.tsxindex aee73b0c9..c4233a073 100644--- a/app/components/TagContainer.tsx+++ b/app/components/TagContainer.tsx@@ -23,7 +23,7 @@ import MoreVertIcon from '@material-ui/icons/MoreVert';import PlaceIcon from '@material-ui/icons/Place';import DateIcon from '@material-ui/icons/DateRange';import RemoveTagIcon from '@material-ui/icons/Close';-import { getAllTags } from '-/reducers/taglibrary';+import { getAllTags, getTagColors } from '-/reducers/taglibrary';import { getTagColor, getTagTextColor } from '-/reducers/settings';import { isGeoTag, formatDateTime } from '-/utils/misc';import { isDateTimeTag, convertToDateTime, convertToDate } from '-/utils/dates';@@ -68,8 +68,6 @@ const TagContainer = (props: Props) => {addTags,tagMode} = props;- let textColor = tag.textcolor || defaultTextColor;- let backgroundColor = tag.color || defaultBackgroundColor;let { title } = tag;// Check if tag is plus code@@ -82,15 +80,10 @@ const TagContainer = (props: Props) => {isTagDate = !isTagGeo && isDateTimeTag(title);}- // TODO move this in reducer- allTags.some((currentTag: TS.Tag) => {- if (currentTag.title === title) {- textColor = currentTag.textcolor;- backgroundColor = currentTag.color;- return true;- }- return false;- });+ const tagColors = getTagColors(allTags, title);+ const textColor = tag.textcolor || tagColors.textcolor || defaultTextColor;+ const backgroundColor =+ tag.color || tagColors.color || defaultBackgroundColor;let tid = 'tagContainer_';if (title && title.length > 0) {diff --git a/app/components/TagsPreview.tsx b/app/components/TagsPreview.tsxindex afe7885fe..6d3553bd6 100644--- a/app/components/TagsPreview.tsx+++ b/app/components/TagsPreview.tsx@@ -17,17 +17,22 @@*/import React from 'react';+import { connect } from 'react-redux';import Tooltip from '@material-ui/core/Tooltip';import { TS } from '-/tagspaces.namespace';+import { getAllTags, getTagColors } from '-/reducers/taglibrary';+import { getTagColor, getTagTextColor } from '-/reducers/settings';import i18n from '-/services/i18n';interface Props {tags: Array<TS.Tag>;- defaultTagColor?: string;+ allTags?: Array<TS.Tag>;+ defaultTextColor?: string;+ defaultBackgroundColor?: string;}const TagsPreview = (props: Props) => {- const { tags, defaultTagColor } = props;+ const { tags, allTags, defaultBackgroundColor, defaultTextColor } = props;if (!tags || tags.length < 1) {return <></>;}@@ -35,13 +40,17 @@ const TagsPreview = (props: Props) => {tags.forEach(tag => {tagNames = tagNames + tag.title + ' ';});- const firstTagColor = tags[0].color || defaultTagColor;- let secondTagColor = defaultTagColor;++ const tag1Colors = getTagColors(allTags, tags[0].title);+ const firstTagColor =+ tags[0].color || tag1Colors.color || defaultBackgroundColor;+ let secondTagColor = defaultBackgroundColor;let moreThanOne = false;if (tags[1]) {moreThanOne = true;+ const tag2Colors = getTagColors(allTags, tags[1].title);if (tags[1].color) {- secondTagColor = tags[1].color;+ secondTagColor = tags[1].color || tag2Colors.color;}}return (@@ -49,7 +58,7 @@ const TagsPreview = (props: Props) => {<spanstyle={{display: 'inline-block',- width: 15,+ width: 18,height: 15,marginLeft: 5,borderRadius: 7,@@ -57,7 +66,8 @@ const TagsPreview = (props: Props) => {boxShadow: moreThanOne ? '4px 0px 0px 0px ' + secondTagColor : 'none',backgroundColor: firstTagColor,fontSize: 11,- color: 'white',+ lineHeight: '16px',+ color: tag1Colors.textcolor || defaultTextColor,textAlign: 'center'}}>@@ -66,4 +76,12 @@ const TagsPreview = (props: Props) => {</Tooltip>);};-export default TagsPreview;++function mapStateToProps(state) {+ return {+ allTags: getAllTags(state),+ defaultBackgroundColor: getTagColor(state),+ defaultTextColor: getTagTextColor(state)+ };+}+export default connect(mapStateToProps)(TagsPreview);diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsxindex 67f744477..d7a96422c 100644--- a/app/perspectives/grid-perspective/components/CellContent.tsx+++ b/app/perspectives/grid-perspective/components/CellContent.tsx@@ -71,7 +71,6 @@ interface Props {handleGridCellClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;editTagForEntry?: (path: string, tag: TS.Tag) => void;reorderTags: boolean;- defaultTagColor?: string;}const CellContent = (props: Props) => {@@ -96,8 +95,7 @@ const CellContent = (props: Props) => {openFsEntry,selectEntry,deselectEntry,- isLast,- defaultTagColor+ isLast} = props;const entryTitle = extractTitle(fsEntry.name,@@ -143,9 +141,7 @@ const CellContent = (props: Props) => {});}tagTitles = tagTitles.substring(0, tagTitles.length - 2);- const tagPlaceholder = (- <TagsPreview tags={entryTags} defaultTagColor={defaultTagColor} />- );+ const tagPlaceholder = <TagsPreview tags={entryTags} />;function renderGridCell() {return (@@ -460,7 +456,6 @@ const CellContent = (props: Props) => {function mapStateToProps(state) {return {- defaultTagColor: getTagColor(state),reorderTags: state.settings.reorderTags};}