import React from 'react'; import {connect} from 'react-redux'; import key from 'keymaster'; import ModerationKeysModal from 'components/ModerationKeysModal'; import CommentList from 'components/CommentList'; import {updateStatus} from 'actions/comments'; import {updateUserStatus} from 'actions/users'; import styles from './ModerationQueue.css'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../../translations.json'; /* * Renders the moderation queue as a tabbed layout with 3 moderation queues * * pending: filtered by status Untouchedand comments that are flagged in the post-moderation setting. * * rejected: filtered by status Rejected * * flagged: with a flagged action on them */ class ModerationQueue extends React.Component { constructor (props) { super(props); this.state = {activeTab: 'pending', singleView: false, modalOpen: false}; } // Fetch comments and bind singleView key before render componentWillMount () { this.props.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH'}); key('s', () => this.setState({singleView: !this.state.singleView})); key('shift+/', () => this.setState({modalOpen: true})); key('esc', () => this.setState({modalOpen: false})); } // Unbind singleView key before unmount componentWillUnmount () { key.unbind('s'); key.unbind('shift+/'); key.unbind('esc'); } // Hack for dynamic mdl tabs componentDidMount () { if (typeof componentHandler !== 'undefined') { // FIXME: fix this hack componentHandler.upgradeAllRegistered(); // eslint-disable-line no-undef } } // Dispatch the appropiate action onAction (status, id) { switch(status){ case 'banned': this.props.dispatch(updateUserStatus(status, id)); break; default: this.props.dispatch(updateStatus(status, id)); } } // Dispatch the update comment status action onCommentAction (status, id) { this.props.dispatch(updateStatus(status, id)); } // Dispatch the update user status action onUserAction (status, id) { this.props.dispatch(updateUserStatus(status, id)); } onTabClick (activeTab) { this.setState({activeTab}); } // Render the tabbed lists moderation queues render () { const {comments} = this.props; const {activeTab, singleView, modalOpen} = this.state; return (
this.onTabClick('pending')} className={`mdl-tabs__tab ${styles.tab}`}>{lang.t('modqueue.pending')} this.onTabClick('rejected')} className={`mdl-tabs__tab ${styles.tab}`}>{lang.t('modqueue.rejected')} this.onTabClick('flagged')} className={`mdl-tabs__tab ${styles.tab}`}>{lang.t('modqueue.flagged')}
!comments.get('byId') .get(id) .get('status')) } comments={comments.get('byId')} onClickAction={(action, id) => this.onAction(action, id)} actions={['reject', 'approve', 'banned']} loading={comments.loading} />
comments .get('byId') .get(id) .get('status') === 'rejected') } comments={comments.get('byId')} onClickAction={(action, id) => this.onCommentAction(action, id)} actions={['approve']} loading={comments.loading} />
{ const data = comments.get('byId').get(id); return !data.get('status') && data.get('flagged') === true; })} comments={comments.get('byId')} onClickAction={(action, id) => this.onCommentAction(action, id)} actions={['reject', 'approve']} loading={comments.loading} />
this.setState({modalOpen: false})} />
); } } export default connect(({comments}) => ({comments}))(ModerationQueue); const lang = new I18n(translations);