From b2f1707f1732d92c08c03efb3efe39fb6b8b67a5 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 17 May 2017 11:19:06 -0300 Subject: [PATCH] Fully working offtopic --- client/coral-embed-stream/src/graphql/index.js | 10 +++++++++- client/coral-framework/graphql/mutations.js | 1 - client/coral-plugin-commentbox/actions.js | 4 ++++ client/coral-plugin-commentbox/constants.js | 1 + client/coral-plugin-commentbox/reducer.js | 4 +++- .../client/components/OffTopicCheckbox.js | 14 ++++++++++++-- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/client/coral-embed-stream/src/graphql/index.js b/client/coral-embed-stream/src/graphql/index.js index d43bfd3d5..77041f554 100644 --- a/client/coral-embed-stream/src/graphql/index.js +++ b/client/coral-embed-stream/src/graphql/index.js @@ -170,7 +170,15 @@ const extension = { parent_id, asset_id, action_summaries: [], - tags, + tags: tags.map(tag => ({ + tag: { + name: tag, + created_at: new Date().toISOString(), + }, + assigned_by: { + id: auth.toJS().user.id, + }, + })), status: null, id: 'pending' } diff --git a/client/coral-framework/graphql/mutations.js b/client/coral-framework/graphql/mutations.js index 66e68be97..1d5318853 100644 --- a/client/coral-framework/graphql/mutations.js +++ b/client/coral-framework/graphql/mutations.js @@ -168,4 +168,3 @@ export const withStopIgnoringUser = withMutation( }); }}), }); - diff --git a/client/coral-plugin-commentbox/actions.js b/client/coral-plugin-commentbox/actions.js index 46bcf4b1b..879824d68 100644 --- a/client/coral-plugin-commentbox/actions.js +++ b/client/coral-plugin-commentbox/actions.js @@ -7,3 +7,7 @@ export const removeTag = idx => ({ type: 'REMOVE_TAG', idx }); + +export const clearTags = () => ({ + type: 'CLEAR_TAGS', +}); diff --git a/client/coral-plugin-commentbox/constants.js b/client/coral-plugin-commentbox/constants.js index b1290f02e..4a80bfe4f 100644 --- a/client/coral-plugin-commentbox/constants.js +++ b/client/coral-plugin-commentbox/constants.js @@ -1,2 +1,3 @@ export const ADD_TAG = 'ADD_TAG'; export const REMOVE_TAG = 'REMOVE_TAG'; +export const CLEAR_TAGS = 'CLEAR_TAGS'; diff --git a/client/coral-plugin-commentbox/reducer.js b/client/coral-plugin-commentbox/reducer.js index d9065fe87..e84f35e93 100644 --- a/client/coral-plugin-commentbox/reducer.js +++ b/client/coral-plugin-commentbox/reducer.js @@ -1,4 +1,4 @@ -import {ADD_TAG, REMOVE_TAG} from './constants'; +import {ADD_TAG, REMOVE_TAG, CLEAR_TAGS} from './constants'; const initialState = { tags: [] @@ -19,6 +19,8 @@ export default function commentBox (state = initialState, action) { ...state.tags.slice(action.idx + 1) ] }; + case CLEAR_TAGS : + return initialState; default : return state; } diff --git a/plugins/coral-plugin-offtopic/client/components/OffTopicCheckbox.js b/plugins/coral-plugin-offtopic/client/components/OffTopicCheckbox.js index 4e7ef7adf..329a16dca 100644 --- a/plugins/coral-plugin-offtopic/client/components/OffTopicCheckbox.js +++ b/plugins/coral-plugin-offtopic/client/components/OffTopicCheckbox.js @@ -1,13 +1,23 @@ import React from 'react'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import {addTag, removeTag} from 'coral-plugin-commentbox/actions'; +import {addTag, removeTag, clearTags} from 'coral-plugin-commentbox/actions'; import styles from './styles.css'; class OffTopicCheckbox extends React.Component { label = 'OFF_TOPIC'; + componentDidMount() { + this.clearTagsHook = this.props.registerHook('postSubmit', (data) => { + this.props.clearTags(); + }); + } + + componentWillUnmount() { + this.props.unregisterHook(this.clearTagsHook); + } + handleChange = (e) => { if (e.target.checked) { this.props.addTag(this.label) @@ -33,6 +43,6 @@ class OffTopicCheckbox extends React.Component { const mapStateToProps = ({commentBox}) => ({commentBox}); const mapDispatchToProps = dispatch => - bindActionCreators({addTag, removeTag}, dispatch); + bindActionCreators({addTag, removeTag, clearTags}, dispatch); export default connect(mapStateToProps, mapDispatchToProps)(OffTopicCheckbox);