From 8c215e08612dbe6ce870434620ff1c5fb14f312c Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Tue, 8 Nov 2016 17:15:57 -0500 Subject: [PATCH 1/9] api-adapt(coral-admin): Get flagging mod queue working with the backend --- client/coral-admin/src/reducers/comments.js | 2 +- client/coral-admin/src/services/talk-adapter.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/reducers/comments.js b/client/coral-admin/src/reducers/comments.js index 4fd14673a..e75079ce4 100644 --- a/client/coral-admin/src/reducers/comments.js +++ b/client/coral-admin/src/reducers/comments.js @@ -39,7 +39,7 @@ const updateStatus = (state, action) => { // Flag a comment const flag = (state, action) => { const byId = state.get('byId') - const data = byId.get(action.id).get('data').set('flagged', true) + const data = byId.get(action.id).set('flagged', true) const comment = byId.get(action.id).set('data', data) return state.set('byId', byId.set(action.id, comment)) } diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js index 2336e0cfd..0772bb24a 100644 --- a/client/coral-admin/src/services/talk-adapter.js +++ b/client/coral-admin/src/services/talk-adapter.js @@ -29,8 +29,12 @@ export default store => next => action => { // Get comments to fill each of the three lists on the mod queue const fetchModerationQueueComments = store => -fetch(`/api/v1/queue`) -.then(res => res.json()) +Promise.all([fetch(`/api/v1/comments/status/pending`), fetch(`/api/v1/comments/status/rejected`), fetch(`/api/v1/comments/action/flag`)]) +.then(res => Promise.all(res.map(r => r.json()))) +.then(res => { + res[2] = res[2].map(comment => { comment.flagged = true; return comment; }) + return res.reduce((prev, curr) => prev.concat(curr), []) +}) .then(res => store.dispatch({ type: 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS', comments: res })) .catch(error => store.dispatch({ type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error })) From 2823232c12528f51ef299381d6c8e9b1b9aadbc7 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 15:25:48 -0700 Subject: [PATCH 2/9] add actions and reducers for settings --- .eslintrc.json | 4 ++ client/coral-admin/package.json | 3 +- client/coral-admin/src/actions/settings.js | 67 +++++++++++++++++++ .../coral-admin/src/containers/Configure.css | 1 + .../coral-admin/src/containers/Configure.js | 32 ++++++++- .../src/containers/ModerationQueue.js | 3 - client/coral-admin/src/reducers/index.js | 2 + client/coral-admin/src/reducers/settings.js | 42 ++++++++++++ 8 files changed, 147 insertions(+), 7 deletions(-) create mode 100644 client/coral-admin/src/actions/settings.js create mode 100644 client/coral-admin/src/reducers/settings.js diff --git a/.eslintrc.json b/.eslintrc.json index 5df3444a6..d15dc3367 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,8 @@ { + "globals": { + "fetch": true, + "Headers": true + }, "env": { "es6": true, "node": true diff --git a/client/coral-admin/package.json b/client/coral-admin/package.json index 048359526..dcd26d06a 100644 --- a/client/coral-admin/package.json +++ b/client/coral-admin/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "build": "./node_modules/.bin/webpack --config webpack.config.js", - "start": "./node_modules/.bin/webpack-dev-server --config webpack.config.dev.js --inline --hot --content-base public --port 3142" + "start": "./node_modules/.bin/webpack-dev-server --config webpack.config.dev.js --inline --hot --content-base public --port 3142", + "dev": "./node_modules/.bin/webpack -w" }, "keywords": [], "author": "", diff --git a/client/coral-admin/src/actions/settings.js b/client/coral-admin/src/actions/settings.js new file mode 100644 index 000000000..73e7d9510 --- /dev/null +++ b/client/coral-admin/src/actions/settings.js @@ -0,0 +1,67 @@ +export const SETTINGS_LOADING = 'SETTINGS_LOADING' +export const SETTINGS_RECEIVED = 'SETTINGS_RECEIVED' +export const SETTINGS_FETCH_ERROR = 'SETTINGS_FETCH_ERROR' + +export const SETTINGS_UPDATED = 'SETTINGS_UPDATED' + +export const SAVE_SETTINGS_LOADING = 'SAVE_SETTINGS_LOADING' +export const SAVE_SETTINGS_SUCCESS = 'SAVE_SETTINGS_SUCCESS' +export const SAVE_SETTINGS_FAILED = 'SAVE_SETTINGS_FAILED' + +const base = '/api/v1' + +const getInit = (method, body) => { + const headers = new Headers({ + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }) + + const init = {method, headers} + if (method.toLowerCase() !== 'get') { + init.body = JSON.stringify(body) + } + + return init +} + +const handleResp = res => { + if (res.status === 401) { + throw new Error('Not Authorized to make this request') + } else if (res.status > 399) { + throw new Error('Error! Status ' + res.status) + } else if (res.status === 204) { + return res.text() + } else { + return res.json() + } +} + +export const fetchSettings = () => dispatch => { + dispatch({type: SETTINGS_LOADING}) + fetch(`${base}/settings`, getInit('GET')) + .then(handleResp) + .then(settings => { + dispatch({type: SETTINGS_RECEIVED, settings}) + }) + .catch(error => { + dispatch({type: SETTINGS_FETCH_ERROR, error}) + }) +} + +export const updateSettings = settings => { + console.log('updated settings', settings) + return {type: SETTINGS_UPDATED, settings} +} + +export const saveSettingsToServer = (dispatch, getState) => { + const settings = getState().settings.settings + dispatch({type: SAVE_SETTINGS_LOADING}) + fetch(`${base}/settings`, getInit('PUT', settings)) + .then(handleResp) + .then(() => { + dispatch({type: SAVE_SETTINGS_SUCCESS, settings}) + }) + .catch(error => { + dispatch({type: SAVE_SETTINGS_FAILED, error}) + }) +} diff --git a/client/coral-admin/src/containers/Configure.css b/client/coral-admin/src/containers/Configure.css index 2c65fd5bc..b5ec3735b 100644 --- a/client/coral-admin/src/containers/Configure.css +++ b/client/coral-admin/src/containers/Configure.css @@ -20,6 +20,7 @@ border-radius: 4px; height: 90px; margin-bottom: 10px; + cursor: pointer; } .configSettingEmbed { diff --git a/client/coral-admin/src/containers/Configure.js b/client/coral-admin/src/containers/Configure.js index 4a36e56e7..70c357cc5 100644 --- a/client/coral-admin/src/containers/Configure.js +++ b/client/coral-admin/src/containers/Configure.js @@ -1,5 +1,6 @@ import React from 'react' import {connect} from 'react-redux' +import {fetchSettings, updateSettings, saveSettingsToServer} from '../actions/settings' import { List, ListItem, @@ -17,12 +18,31 @@ class Configure extends React.Component { constructor (props) { super(props) this.state = {activeSection: 'comments'} + this.updateModeration = this.updateModeration.bind(this) + this.saveSettings = this.saveSettings.bind(this) + } + + componentWillMount () { + this.props.dispatch(fetchSettings()) + } + + updateModeration () { + const moderation = this.props.settings.moderation === 'pre' ? 'post' : 'pre' + this.props.dispatch(updateSettings({moderation})) + } + + saveSettings () { + this.props.dispatch(saveSettingsToServer()) } getCommentSettings () { return - + + + Enable pre-moderation @@ -75,7 +95,7 @@ class Configure extends React.Component { icon='code'>Embed Comment Stream - @@ -93,4 +113,10 @@ class Configure extends React.Component { } } -export default connect(x => x)(Configure) +const mapStateToProps = state => { + return { + settings: state.settings.toJS() + } +} + +export default connect(mapStateToProps)(Configure) diff --git a/client/coral-admin/src/containers/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue.js index 061786543..3f13b8bf4 100644 --- a/client/coral-admin/src/containers/ModerationQueue.js +++ b/client/coral-admin/src/containers/ModerationQueue.js @@ -20,8 +20,6 @@ class ModerationQueue extends React.Component { constructor (props) { super(props) - console.log('ModerationQueue', props) - this.state = { activeTab: 'pending', singleView: false, modalOpen: false } } @@ -60,7 +58,6 @@ class ModerationQueue extends React.Component { render () { const { comments } = this.props const { activeTab, singleView, modalOpen } = this.state - console.log('moderation queue', styles) return ( diff --git a/client/coral-admin/src/reducers/index.js b/client/coral-admin/src/reducers/index.js index 5c99e3bb2..0c95fb566 100644 --- a/client/coral-admin/src/reducers/index.js +++ b/client/coral-admin/src/reducers/index.js @@ -1,8 +1,10 @@ import { combineReducers } from 'redux' import comments from 'reducers/comments' +import settings from 'reducers/settings' // Combine all reducers into a main one export default combineReducers({ + settings, comments }) diff --git a/client/coral-admin/src/reducers/settings.js b/client/coral-admin/src/reducers/settings.js new file mode 100644 index 000000000..9d877a36d --- /dev/null +++ b/client/coral-admin/src/reducers/settings.js @@ -0,0 +1,42 @@ +import { Map } from 'immutable' +import * as types from '../actions/settings' + +const initialState = Map({ + settings: Map(), + saveSettingsError: null, + fetchSettingsError: null, + fetchingSettings: false +}) + +// Handle the comment actions +export default (state = initialState, action) => { + switch (action.type) { + case types.SETTINGS_LOADING: return state.set('fetchingSettings', true).set('fetchSettingsError', null) + case types.SETTINGS_RECEIVED: return receivedSettings(state, action) + case types.SETTINGS_FETCH_ERROR: return settingsFetchFailed(state, action) + case types.SETTINGS_UPDAETD: return state.get('settings').merge(action.settings) + case types.SAVE_SETTINGS_LOADING: return state.set('fetchingSettings', true).set('saveSettingsError', null) + case types.SAVE_SETTINGS_SUCCESS: return saveComplete(state, action) + case types.SAVE_SETTINGS_FAILED: return settingsSaveFailed(state, action) + default: return state + } +} + +const receivedSettings = (state, action) => { + state.set('fetchingSettings', false).set('fetchSettingsError', null) + return state.get('settings').merge(action.settings) +} + +const saveComplete = (state, action) => { + state.set('fetchingSettings', false).set('saveSettingsError', null) + console.log('saveComplete', action.settings) + return state.get('settings').merge(action.settings) +} + +const settingsFetchFailed = (state, action) => { + return state.set('fetchingSettings', false).set('fetchSettingsError', action.error) +} + +const settingsSaveFailed = (state, action) => { + return state.set('fetchingSettings', false).set('fetchSettingsError', action.error) +} From ff52714f272aa69f0c090e9c0630d36de37ca528 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 16:16:27 -0700 Subject: [PATCH 3/9] update state correctly. save to server correctly --- client/coral-admin/src/actions/settings.js | 5 ++--- client/coral-admin/src/containers/Configure.js | 6 +----- client/coral-admin/src/reducers/settings.js | 17 +++++++++-------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/client/coral-admin/src/actions/settings.js b/client/coral-admin/src/actions/settings.js index 73e7d9510..488764c17 100644 --- a/client/coral-admin/src/actions/settings.js +++ b/client/coral-admin/src/actions/settings.js @@ -49,12 +49,11 @@ export const fetchSettings = () => dispatch => { } export const updateSettings = settings => { - console.log('updated settings', settings) return {type: SETTINGS_UPDATED, settings} } -export const saveSettingsToServer = (dispatch, getState) => { - const settings = getState().settings.settings +export const saveSettingsToServer = () => (dispatch, getState) => { + const settings = getState().settings.toJS().settings dispatch({type: SAVE_SETTINGS_LOADING}) fetch(`${base}/settings`, getInit('PUT', settings)) .then(handleResp) diff --git a/client/coral-admin/src/containers/Configure.js b/client/coral-admin/src/containers/Configure.js index 70c357cc5..12a47613c 100644 --- a/client/coral-admin/src/containers/Configure.js +++ b/client/coral-admin/src/containers/Configure.js @@ -113,10 +113,6 @@ class Configure extends React.Component { } } -const mapStateToProps = state => { - return { - settings: state.settings.toJS() - } -} +const mapStateToProps = state => state.settings.toJS() export default connect(mapStateToProps)(Configure) diff --git a/client/coral-admin/src/reducers/settings.js b/client/coral-admin/src/reducers/settings.js index 9d877a36d..60dcd05af 100644 --- a/client/coral-admin/src/reducers/settings.js +++ b/client/coral-admin/src/reducers/settings.js @@ -12,9 +12,9 @@ const initialState = Map({ export default (state = initialState, action) => { switch (action.type) { case types.SETTINGS_LOADING: return state.set('fetchingSettings', true).set('fetchSettingsError', null) - case types.SETTINGS_RECEIVED: return receivedSettings(state, action) + case types.SETTINGS_RECEIVED: return updateSettings(state, action) case types.SETTINGS_FETCH_ERROR: return settingsFetchFailed(state, action) - case types.SETTINGS_UPDAETD: return state.get('settings').merge(action.settings) + case types.SETTINGS_UPDATED: return updateSettings(state, action) case types.SAVE_SETTINGS_LOADING: return state.set('fetchingSettings', true).set('saveSettingsError', null) case types.SAVE_SETTINGS_SUCCESS: return saveComplete(state, action) case types.SAVE_SETTINGS_FAILED: return settingsSaveFailed(state, action) @@ -22,15 +22,16 @@ export default (state = initialState, action) => { } } -const receivedSettings = (state, action) => { - state.set('fetchingSettings', false).set('fetchSettingsError', null) - return state.get('settings').merge(action.settings) +const updateSettings = (state, action) => { + const s = state.set('fetchingSettings', false).set('fetchSettingsError', null) + const settings = s.get('settings').merge(action.settings) + return s.set('settings', settings) } const saveComplete = (state, action) => { - state.set('fetchingSettings', false).set('saveSettingsError', null) - console.log('saveComplete', action.settings) - return state.get('settings').merge(action.settings) + const s = state.set('fetchingSettings', false).set('saveSettingsError', null) + const settings = s.get('settings').merge(action.settings) + return s.set('settings', settings) } const settingsFetchFailed = (state, action) => { From c6188913d884fc70dee60f815e2f675a4bb14be2 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 16:19:40 -0700 Subject: [PATCH 4/9] display a simple error text --- client/coral-admin/src/containers/Configure.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/containers/Configure.js b/client/coral-admin/src/containers/Configure.js index 12a47613c..364703934 100644 --- a/client/coral-admin/src/containers/Configure.js +++ b/client/coral-admin/src/containers/Configure.js @@ -75,10 +75,12 @@ class Configure extends React.Component { } render () { - const pageTitle = this.state.activeSection === 'comments' + let pageTitle = this.state.activeSection === 'comments' ? 'Comment Settings' : 'Embed Comment Stream' + if (this.props.fetchingSettings) pageTitle += ' - Loading...' + return (
@@ -101,6 +103,8 @@ class Configure extends React.Component {

{pageTitle}

+ { this.props.saveFetchingError } + { this.props.fetchSettingsError } { this.state.activeSection === 'comments' ? this.getCommentSettings() From f708271d0003dd9de5df2295f70adbd3e3a42a03 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 9 Nov 2016 09:03:25 -0700 Subject: [PATCH 5/9] Added missing babel plugin --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 979475b5b..5be396a32 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,10 @@ "babel-core": "^6.18.2", "babel-loader": "^6.2.7", "babel-plugin-transform-async-to-generator": "^6.16.0", + "babel-plugin-transform-class-properties": "^6.18.0", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-object-assign": "^6.8.0", + "babel-plugin-transform-object-rest-spread": "^6.16.0", "babel-plugin-transform-react-jsx": "^6.8.0", "babel-polyfill": "^6.16.0", "babel-preset-es2015": "^6.18.0", From d7ea18cba9b874b1f6bf893aa75bf8813a787e3f Mon Sep 17 00:00:00 2001 From: gaba Date: Wed, 9 Nov 2016 13:52:47 -0800 Subject: [PATCH 6/9] Fix linting problems. Remove comment of code. Add package. --- client/coral-admin/src/actions/settings.js | 2 +- package.json | 1 + tests/models/comment.js | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/actions/settings.js b/client/coral-admin/src/actions/settings.js index e4df4adfe..f71730663 100644 --- a/client/coral-admin/src/actions/settings.js +++ b/client/coral-admin/src/actions/settings.js @@ -28,7 +28,7 @@ const handleResp = res => { if (res.status === 401) { throw new Error('Not Authorized to make this request'); } else if (res.status > 399) { - throw new Error('Error! Status ' + res.status); + throw new Error('Error! Status ', res.status); } else if (res.status === 204) { return res.text(); } else { diff --git a/package.json b/package.json index a3656ddba..7b6b66fe5 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "body-parser": "^1.15.2", "debug": "^2.2.0", "ejs": "^2.5.2", + "eslint-config-postcss": "^2.0.2", "express": "^4.14.0", "mongoose": "^4.6.5", "morgan": "^1.7.0", diff --git a/tests/models/comment.js b/tests/models/comment.js index b3f0c0f30..4ebcbbc64 100644 --- a/tests/models/comment.js +++ b/tests/models/comment.js @@ -44,6 +44,4 @@ describe('Comment: models', () => { }); }); }); - - // }); }); From decb6747fd5634f43d4eda6448ccaf91fef61f24 Mon Sep 17 00:00:00 2001 From: David Erwin Date: Wed, 9 Nov 2016 17:12:52 -0500 Subject: [PATCH 7/9] Comment out inactive Settings options --- client/coral-admin/src/containers/Configure.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/containers/Configure.js b/client/coral-admin/src/containers/Configure.js index 9f0b32dcf..0d4cf58d6 100644 --- a/client/coral-admin/src/containers/Configure.js +++ b/client/coral-admin/src/containers/Configure.js @@ -7,7 +7,7 @@ import { ListItem, ListItemContent, ListItemAction, - Textfield, + //Textfield, Checkbox, Button, Icon @@ -50,6 +50,7 @@ class Configure extends React.Component { Enable pre-moderation + {/* Include Comment Stream Description for Readers @@ -62,6 +63,7 @@ class Configure extends React.Component { error='Input is not a number!' label='Maximum Characters' /> + */} ; } From 39654f34f23f9715858d59f40c010fb9b5fdb83d Mon Sep 17 00:00:00 2001 From: David Erwin Date: Wed, 9 Nov 2016 17:15:39 -0500 Subject: [PATCH 8/9] Updating eslint as per @wyattjoh's request --- .eslintrc.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ac9157879..98585fbc2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,8 @@ { - "globals": { - "fetch": true, - "Headers": true - }, "env": { "es6": true, - "node": true + "node": true, + "browser": true }, "extends": "eslint:recommended", "rules": { From f6473972d849d6316f4759fbb5780c791fac86a9 Mon Sep 17 00:00:00 2001 From: David Erwin Date: Wed, 9 Nov 2016 17:19:44 -0500 Subject: [PATCH 9/9] Remove browser: true in favor of client's eslint file --- .eslintrc.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 98585fbc2..23bdea410 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,8 +1,7 @@ { "env": { "es6": true, - "node": true, - "browser": true + "node": true }, "extends": "eslint:recommended", "rules": {