From 9fb8e01cd2d55c47237ba0c54c3a8ebeea85ca88 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 18 Dec 2017 13:34:48 -0300 Subject: [PATCH] working, still wip --- plugin-api/beta/client/hocs/withTags.js | 7 ++++--- .../talk-plugin-featured-comments/client/actions.js | 6 ++++-- .../client/components/FeaturedDialog.js | 5 ++--- .../client/components/ModTag.js | 7 ++++--- .../client/containers/FeaturedDialog.js | 4 +++- plugins/talk-plugin-featured-comments/client/index.js | 6 ++++-- .../talk-plugin-featured-comments/client/reducer.js | 10 ++++++++++ 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/plugin-api/beta/client/hocs/withTags.js b/plugin-api/beta/client/hocs/withTags.js index 66fd7ad2e..14ae4fcf4 100644 --- a/plugin-api/beta/client/hocs/withTags.js +++ b/plugin-api/beta/client/hocs/withTags.js @@ -87,7 +87,7 @@ export default (tag, options = {}) => hoistStatics((WrappedComponent) => { } render() { - const {root, asset, comment, user, config} = this.props; + const {root, asset, comment, user, config, ...rest} = this.props; const alreadyTagged = isTagged(comment.tags, TAG); @@ -100,6 +100,7 @@ export default (tag, options = {}) => hoistStatics((WrappedComponent) => { postTag={this.postTag} deleteTag={this.deleteTag} config={config} + {...rest} />; } } @@ -134,9 +135,9 @@ export default (tag, options = {}) => hoistStatics((WrappedComponent) => { ${fragments.comment ? fragments.comment : ''} ` }), - connect(mapStateToProps, mapDispatchToProps), withAddTag, - withRemoveTag + withRemoveTag, + connect(mapStateToProps, mapDispatchToProps), ); WithTags.displayName = `WithTags(${getDisplayName(WrappedComponent)})`; diff --git a/plugins/talk-plugin-featured-comments/client/actions.js b/plugins/talk-plugin-featured-comments/client/actions.js index c5c81baa8..d212ae736 100644 --- a/plugins/talk-plugin-featured-comments/client/actions.js +++ b/plugins/talk-plugin-featured-comments/client/actions.js @@ -1,7 +1,9 @@ import {OPEN_FEATURED_DIALOG, CLOSE_FEATURED_DIALOG} from './constants'; -export const openFeaturedDialog = () => ({ - type: OPEN_FEATURED_DIALOG +export const openFeaturedDialog = (comment, asset) => ({ + type: OPEN_FEATURED_DIALOG, + comment, + asset, }); export const closeFeaturedDialog = () => ({ diff --git a/plugins/talk-plugin-featured-comments/client/components/FeaturedDialog.js b/plugins/talk-plugin-featured-comments/client/components/FeaturedDialog.js index cad872e12..4975f8e59 100644 --- a/plugins/talk-plugin-featured-comments/client/components/FeaturedDialog.js +++ b/plugins/talk-plugin-featured-comments/client/components/FeaturedDialog.js @@ -9,7 +9,7 @@ import Button from 'coral-ui/components/Button'; const FeaturedDialog = ({showFeaturedDialog, closeFeaturedDialog, postTag}) => ( × @@ -41,8 +41,7 @@ const FeaturedDialog = ({showFeaturedDialog, closeFeaturedDialog, postTag}) => ( ); FeaturedDialog.propTypes = { - showFeaturedDialog: PropTypes.bool, - postTag: PropTypes.func.isRequired, + showFeaturedDialog: PropTypes.bool.isRequired, closeFeaturedDialog: PropTypes.func.isRequired, }; diff --git a/plugins/talk-plugin-featured-comments/client/components/ModTag.js b/plugins/talk-plugin-featured-comments/client/components/ModTag.js index c66b688ab..c3cced4f2 100644 --- a/plugins/talk-plugin-featured-comments/client/components/ModTag.js +++ b/plugins/talk-plugin-featured-comments/client/components/ModTag.js @@ -4,7 +4,6 @@ import cn from 'classnames'; import styles from './ModTag.css'; import {t} from 'plugin-api/beta/client/services'; import {Icon} from 'plugin-api/beta/client/components/ui'; -import {getErrorMessages} from 'plugin-api/beta/client/utils'; export default class ModTag extends React.Component { constructor() { @@ -31,7 +30,7 @@ export default class ModTag extends React.Component { } render() { - const {alreadyTagged, deleteTag} = this.props; + const {alreadyTagged, deleteTag, comment, asset} = this.props; return alreadyTagged ? ( ) : ( + onClick={() => this.props.openFeaturedDialog(comment, asset)} > {alreadyTagged ? t('talk-plugin-featured-comments.featured') : t('talk-plugin-featured-comments.feature')} @@ -56,4 +55,6 @@ ModTag.propTypes = { deleteTag: PropTypes.func, notify: PropTypes.func, openFeaturedDialog: PropTypes.func, + comment: PropTypes.object, + asset: PropTypes.object, }; diff --git a/plugins/talk-plugin-featured-comments/client/containers/FeaturedDialog.js b/plugins/talk-plugin-featured-comments/client/containers/FeaturedDialog.js index 66e9a6a30..0440e9d08 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/FeaturedDialog.js +++ b/plugins/talk-plugin-featured-comments/client/containers/FeaturedDialog.js @@ -6,6 +6,8 @@ import {closeFeaturedDialog} from '../actions'; const mapStateToProps = ({talkPluginFeaturedComments: state}) => ({ showFeaturedDialog: state.showFeaturedDialog, + comment: state.comment, + asset: state.asset, }); const mapDispatchToProps = (dispatch) => @@ -14,8 +16,8 @@ const mapDispatchToProps = (dispatch) => }, dispatch); const enhance = compose( - withTags('featured'), connect(mapStateToProps, mapDispatchToProps), + withTags('featured'), ); export default enhance(FeaturedDialog); diff --git a/plugins/talk-plugin-featured-comments/client/index.js b/plugins/talk-plugin-featured-comments/client/index.js index 21d61d21a..304bff647 100644 --- a/plugins/talk-plugin-featured-comments/client/index.js +++ b/plugins/talk-plugin-featured-comments/client/index.js @@ -6,20 +6,22 @@ import update from 'immutability-helper'; import ModTag from './containers/ModTag'; import ModActionButton from './containers/ModActionButton'; import ModSubscription from './containers/ModSubscription'; -import FeaturedConfirmation from './containers/FeaturedConfirmation'; +import FeaturedDialog from './containers/FeaturedDialog'; import {gql} from 'react-apollo'; +import reducer from './reducer'; import {findCommentInEmbedQuery} from 'coral-embed-stream/src/graphql/utils'; import {prependNewNodes} from 'plugin-api/beta/client/utils'; export default { translations, + reducer, slots: { streamTabsPrepend: [Tab], streamTabPanes: [TabPane], commentInfoBar: [Tag], moderationActions: [ModActionButton], - adminModeration: [ModSubscription, FeaturedConfirmation], + adminModeration: [ModSubscription, FeaturedDialog], adminCommentInfoBar: [ModTag], }, mutations: { diff --git a/plugins/talk-plugin-featured-comments/client/reducer.js b/plugins/talk-plugin-featured-comments/client/reducer.js index 3840155b3..eb6d302ff 100644 --- a/plugins/talk-plugin-featured-comments/client/reducer.js +++ b/plugins/talk-plugin-featured-comments/client/reducer.js @@ -2,6 +2,13 @@ import {OPEN_FEATURED_DIALOG, CLOSE_FEATURED_DIALOG} from './constants'; const initialState = { showFeaturedDialog: false, + comment: { + id: null, + tags: [] + }, + asset: { + id: null, + }, }; export default function reducer(state = initialState, action) { @@ -9,11 +16,14 @@ export default function reducer(state = initialState, action) { case OPEN_FEATURED_DIALOG: return { ...state, + comment: action.comment, + asset: action.asset, showFeaturedDialog: true, }; case CLOSE_FEATURED_DIALOG: return { ...state, + featuredCommentId: null, showFeaturedDialog: false, }; default :