mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 20:17:25 +08:00
Ádd classnames based on tags
This commit is contained in:
@@ -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 (
|
||||
<div
|
||||
className={cn([commentClass, classNames])}
|
||||
id={`c_${comment.id}`}
|
||||
style={{marginLeft: depth * 30}}
|
||||
className={cn([commentClass, classNamesToAdd])}
|
||||
>
|
||||
<hr aria-hidden={true} />
|
||||
<div
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import styles from './ViewingOptions.css';
|
||||
import cn from 'classnames';
|
||||
import styles from './ViewingOptions.css';
|
||||
import Slot from 'coral-framework/components/Slot';
|
||||
|
||||
export default class ViewingOptions extends React.Component {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import {ADD_CLASSNAME, REMOVE_CLASSNAME} from '../constants/comment';
|
||||
|
||||
const initialState = {
|
||||
classNames: []
|
||||
classNames: [{
|
||||
'wapoOff' : {
|
||||
tags: ['OFF_TOPIC']
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
export default function comment (state = initialState, action) {
|
||||
|
||||
@@ -6,11 +6,14 @@ import {addClassName, removeClassName} from 'coral-embed-stream/src/actions/comm
|
||||
|
||||
class OffTopicFilter extends React.Component {
|
||||
|
||||
className = 'OFF_TOPIC';
|
||||
tag = 'OFF_TOPIC';
|
||||
className = 'wapoOfftopic';
|
||||
|
||||
handleChange = (e) => {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user