From 9364272ffc7b63e6e8641e4a03f2f2f2a0f73eee Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 6 Jun 2017 11:53:19 -0300 Subject: [PATCH] =?UTF-8?q?=C3=81dd=20classnames=20based=20on=20tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Comment.js | 33 ++++++++++++++++++- .../src/components/ViewingOptions.js | 2 +- .../src/reducers/comment.js | 6 +++- .../client/components/OffTopicFilter.js | 7 ++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/client/coral-embed-stream/src/components/Comment.js b/client/coral-embed-stream/src/components/Comment.js index 3b8b8b08d..1364e7748 100644 --- a/client/coral-embed-stream/src/components/Comment.js +++ b/client/coral-embed-stream/src/components/Comment.js @@ -27,6 +27,7 @@ import {getEditableUntilDate} from './util'; import styles from './Comment.css'; const isStaff = (tags) => !tags.every((t) => t.name !== 'STAFF'); +const hasTag = (tags, lookupTag) => !!tags.filter((tag) => tag.name === lookupTag).length; // hold actions links (e.g. Reply) along the comment footer const ActionButton = ({children}) => { @@ -226,11 +227,41 @@ class Comment extends React.Component { () => 'Failed to remove best comment tag' ); + /** + * classNamesToAdd + * adds classNames based on condition + * classnames is an array of objects with key as classnames and value as conditions + * i.e: + * { + * 'myClassName': { tags: ['STAFF']} + * } + * + * This will add myClassName to comments tagged with STAFF TAG. + * **/ + + const classNamesToAdd = classNames.reduce((acc, className) => { + let res = []; + + // Adding classNames based on tags + Object.keys(className).map(cn => { + const condition = className[cn]; + condition.tags.forEach(tag => { + if (hasTag(comment.tags, tag)) { + res = [...res, cn]; + } + }); + }); + + // TODO: Compare rest of the comment obj to the condition if needed + + return [...acc, ...res]; + }, []); + return (

{ if (e.target.checked) { - this.props.addClassName(this.className); + this.props.addClassName({ + [this.className] : {tags: [this.tag]} + }); } else { const idx = this.props.comment.classNames.indexOf(this.className); this.props.removeClassName(idx);