TagSpaces is an offline, open source, document manager with tagging support
refactoring tagcontainer as functional component
Ilian Sapundshievbe0fbc4e5163
diff --git a/app/components/TagContainer.js b/app/components/TagContainer.jsindex 8c032adcf..7d73fe4b8 100644--- a/app/components/TagContainer.js+++ b/app/components/TagContainer.js@@ -42,126 +42,125 @@ type Props = {deleteIcon: Object};+const TagContainer = (props: Props) => {+ // shouldComponentUpdate(nextProps) {+ // if (this.props.tag.title !== nextProps.tag.title+ // || typeof this.props.key !== typeof nextProps.key+ // || (this.props.key && nextProps.key && this.props.key !== nextProps.key)+ // || this.props.tag.color !== nextProps.tag.color+ // || this.props.tag.textcolor !== nextProps.tag.textcolor+ // || this.props.allTags.some((currentTag: Tag) => {+ // if (currentTag.title === this.props.tag.title) {+ // return (nextProps.allTags.some((updatedTag: Tag) => {+ // if (updatedTag.title === this.props.tag.title) {+ // return currentTag.color !== updatedTag.color || currentTag.textcolor !== updatedTag.textcolor;+ // }+ // return false;+ // }));+ // }+ // return false;+ // })+ // || (this.props.tagGroup && this.props.tagGroup ? (this.props.tagGroup.uuid !== nextProps.tagGroup.uuid) : false)+ // || this.props.isDragging !== nextProps.isDragging+ // || typeof this.props.entryPath !== typeof nextProps.entryPath+ // || (this.props.entryPath && this.props.entryPath !== nextProps.entryPath)+ // ) {+ // return true;+ // }+ // return false;+ // }-class TagContainer extends React.Component<Props> {- shouldComponentUpdate(nextProps) {- if (this.props.tag.title !== nextProps.tag.title- || typeof this.props.key !== typeof nextProps.key- || (this.props.key && nextProps.key && this.props.key !== nextProps.key)- || this.props.tag.color !== nextProps.tag.color- || this.props.tag.textcolor !== nextProps.tag.textcolor- || this.props.allTags.some((currentTag: Tag) => {- if (currentTag.title === this.props.tag.title) {- return (nextProps.allTags.some((updatedTag: Tag) => {- if (updatedTag.title === this.props.tag.title) {- return currentTag.color !== updatedTag.color || currentTag.textcolor !== updatedTag.textcolor;- }- return false;- }));- }- return false;- })- || (this.props.tagGroup && this.props.tagGroup ? (this.props.tagGroup.uuid !== nextProps.tagGroup.uuid) : false)- || this.props.isDragging !== nextProps.isDragging- || typeof this.props.entryPath !== typeof nextProps.entryPath- || (this.props.entryPath && this.props.entryPath !== nextProps.entryPath)- ) {- return true;- }- return false;- }-- render() {- const {- key,- tag,- deleteIcon,- isDragging,- defaultTextColor,- defaultBackgroundColor,- tagGroup,- entryPath,- allTags- } = this.props;- const { tagMode } = this.props;- let mode = '';+ const {+ key,+ tag,+ deleteIcon,+ isDragging,+ defaultTextColor,+ defaultBackgroundColor,+ tagGroup,+ entryPath,+ allTags,+ handleRemoveTag,+ handleTagMenu,+ tagMode+ } = props;- let textColor = tag.textcolor || defaultTextColor;- let backgroundColor = tag.color || defaultBackgroundColor;+ let mode = '';+ let textColor = tag.textcolor || defaultTextColor;+ let backgroundColor = tag.color || defaultBackgroundColor;- allTags.some((currentTag: Tag) => {- if (currentTag.title === tag.title) {- textColor = currentTag.textcolor;- backgroundColor = currentTag.color;- return true;- }- return false;- });-- if (tagMode === 'remove') {- mode = deleteIcon || (- <RemoveTagIcon- data-tid={'tagRemoveButton_' + tag.title.replace(/ /g, '_')}- style={{- color: tag.textColor- }}- onClick={event => this.props.handleRemoveTag(event, tag)}- />- );- } else if (tagMode === 'display') {- mode = '';- } else {- mode = (- <MoreVertIcon- data-tid={'tagMoreButton_' + tag.title.replace(/ /g, '_')}- style={{- color: tag.textColor- }}- />- );+ allTags.some((currentTag: Tag) => {+ if (currentTag.title === tag.title) {+ textColor = currentTag.textcolor;+ backgroundColor = currentTag.color;+ return true;}+ return false;+ });- return (- <div- role="presentation"- data-tid={'tagContainer_' + tag.title.replace(/ /g, '_')}- key={key || tag.id || uuidv1()}- onClick={event => { if (this.props.handleTagMenu) { this.props.handleTagMenu(event, tag, entryPath || tagGroup); } }}- onContextMenu={event => { if (this.props.handleTagMenu) { this.props.handleTagMenu(event, tag, entryPath || tagGroup); } }}- onDoubleClick={event => { if (this.props.handleTagMenu) { this.props.handleTagMenu(event, tag, entryPath || tagGroup); } }}+ if (tagMode === 'remove') {+ mode = deleteIcon || (+ <RemoveTagIcon+ data-tid={'tagRemoveButton_' + tag.title.replace(/ /g, '_')}style={{- backgroundColor: 'transparent',- marginLeft: 4,- marginTop: 0,- marginBottom: 4,- display: 'inline-block'+ color: tag.textColor}}- >- <Button- size="small"- style={{- opacity: isDragging ? 0.5 : 1,- fontSize: 13,- textTransform: 'none',- color: textColor,- backgroundColor,- minHeight: 25,- margin: 0,- paddingTop: 0,- paddingBottom: 0,- paddingRight: 3,- borderRadius: 5- }}- >- <span>- {tag.title}- </span>- {mode}- </Button>- </div>+ onClick={event => handleRemoveTag(event, tag)}+ />+ );+ } else if (tagMode === 'display') {+ mode = '';+ } else {+ mode = (+ <MoreVertIcon+ data-tid={'tagMoreButton_' + tag.title.replace(/ /g, '_')}+ style={{+ color: tag.textColor+ }}+ />);}-}++ return (+ <div+ role="presentation"+ data-tid={'tagContainer_' + tag.title.replace(/ /g, '_')}+ key={key || tag.id || uuidv1()}+ onClick={event => { if (handleTagMenu) { props.handleTagMenu(event, tag, entryPath || tagGroup); } }}+ onContextMenu={event => { if (handleTagMenu) { props.handleTagMenu(event, tag, entryPath || tagGroup); } }}+ onDoubleClick={event => { if (handleTagMenu) { props.handleTagMenu(event, tag, entryPath || tagGroup); } }}+ style={{+ backgroundColor: 'transparent',+ marginLeft: 4,+ marginTop: 0,+ marginBottom: 4,+ display: 'inline-block'+ }}+ >+ <Button+ size="small"+ style={{+ opacity: isDragging ? 0.5 : 1,+ fontSize: 13,+ textTransform: 'none',+ color: textColor,+ backgroundColor,+ minHeight: 25,+ margin: 0,+ paddingTop: 0,+ paddingBottom: 0,+ paddingRight: 3,+ borderRadius: 5+ }}+ >+ <span>+ {tag.title}+ </span>+ {mode}+ </Button>+ </div>+ );+};function mapStateToProps(state) {return {