From 0ce892fe7a2c47f4b47203d0678bcdf4b0659d50 Mon Sep 17 00:00:00 2001 From: David Jay Date: Thu, 10 Nov 2016 17:04:04 -0500 Subject: [PATCH] Loading settings and modifying commentbox to reflect pre and post-mod behavior. --- .../coral-embed-stream/src/CommentStream.js | 4 ++- .../coral-framework/store/actions/config.js | 34 +++++++++++-------- client/coral-framework/store/actions/items.js | 2 +- client/coral-plugin-author-name/AuthorName.js | 2 +- client/coral-plugin-commentbox/CommentBox.js | 10 ++++-- client/coral-plugin-replies/ReplyBox.js | 7 +--- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index 28b70841f..d6edfddda 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -108,6 +108,7 @@ class CommentStream extends Component { appendItemArray={this.props.appendItemArray} updateItem={this.props.updateItem} id={rootItemId} + premod={this.props.config.moderation} reply={false}/> { @@ -138,6 +139,7 @@ class CommentStream extends Component { updateItem={this.props.updateItem} id={rootItemId} parent_id={commentId} + premod={this.props.config.moderation} showReply={comment.showReply}/> { comment.children && @@ -168,7 +170,7 @@ class CommentStream extends Component { }) } diff --git a/client/coral-framework/store/actions/config.js b/client/coral-framework/store/actions/config.js index 7eb82d428..800017102 100644 --- a/client/coral-framework/store/actions/config.js +++ b/client/coral-framework/store/actions/config.js @@ -14,17 +14,23 @@ export const FETCH_CONFIG_SUCCESS = 'FETCH_CONFIG_SUCCESS'; * Action creators */ -export const fetchConfig = () => async (dispatch) => { - dispatch({type: FETCH_CONFIG_REQUEST}); - - try { - //TODO: Replace with fetching config from backend - // const response = await fetch(`./talk.config.json`) - // const json = await response.json() - dispatch({type: FETCH_CONFIG_SUCCESS, config: fromJS({ - notifLength: 4500 - })}); - } catch (error) { - dispatch({type: FETCH_CONFIG_FAILED}); - } -}; +export function fetchConfig () { + return (dispatch) => { + dispatch({type: FETCH_CONFIG_REQUEST}); + console.log('Fetching settings'); + return fetch('/api/v1/settings') + .then( + response => { + return response.ok ? response.json() + : Promise.reject(`${response.status} ${response.statusText}`); + } + ) + .then((json) => { + console.log(json); + return dispatch({type: FETCH_CONFIG_SUCCESS, config: fromJS(json)}); + }).catch((error) => { + console.log(error); + dispatch({type: FETCH_CONFIG_FAILED, error}); + }); + }; +} diff --git a/client/coral-framework/store/actions/items.js b/client/coral-framework/store/actions/items.js index b690c6f0a..5b44de359 100644 --- a/client/coral-framework/store/actions/items.js +++ b/client/coral-framework/store/actions/items.js @@ -148,7 +148,7 @@ export function getStream (assetId) { export function getItemsArray (ids) { return (dispatch) => { - return fetch(`/v1/item/${ ids}`) + return fetch(`/v1/item/${ids}`) .then( response => { return response.ok ? response.json() diff --git a/client/coral-plugin-author-name/AuthorName.js b/client/coral-plugin-author-name/AuthorName.js index ddfd40ccf..585c1c07d 100644 --- a/client/coral-plugin-author-name/AuthorName.js +++ b/client/coral-plugin-author-name/AuthorName.js @@ -2,7 +2,7 @@ import React from 'react'; const packagename = 'coral-plugin-author-name'; const AuthorName = ({name}) => -
+
{name}
; diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index a4e32d73b..3811e0cd9 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -19,7 +19,7 @@ class CommentBox extends Component { } postComment = () => { - const {postItem, updateItem, id, parent_id, addNotification, appendItemArray} = this.props; + const {postItem, updateItem, id, parent_id, addNotification, appendItemArray, premod} = this.props; let comment = { body: this.state.body, asset_id: id, @@ -38,8 +38,12 @@ class CommentBox extends Component { updateItem(parent_id, 'showReply', false, 'comments'); postItem(comment, 'comments') .then((comment_id) => { - appendItemArray(parent_id || id, related, comment_id, !parent_id, parent_type); - addNotification('success', 'Your comment has been posted.'); + if (premod === 'pre') { + addNotification('success', 'Your comment has been posted and is being reviewed by our moderation team.'); + } else { + appendItemArray(parent_id || id, related, comment_id, !parent_id, parent_type); + addNotification('success', 'Your comment has been posted.'); + } }).catch((err) => console.error(err)); this.setState({body: ''}); } diff --git a/client/coral-plugin-replies/ReplyBox.js b/client/coral-plugin-replies/ReplyBox.js index cd226181b..d9fddf1ad 100644 --- a/client/coral-plugin-replies/ReplyBox.js +++ b/client/coral-plugin-replies/ReplyBox.js @@ -8,12 +8,7 @@ const ReplyBox = (props) =>
{ props.showReply && }