From 598fcc4cb0fa7f55185a037e4eff618d8f92c8fb Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 16 Mar 2017 11:07:38 -0600 Subject: [PATCH] Added new pageData action/reducer --- client/coral-admin/src/actions/pageData.js | 7 +++++++ client/coral-admin/src/components/AdminLogin.js | 7 ++++--- .../src/containers/LayoutContainer.js | 15 +++++++++++++-- client/coral-admin/src/reducers/index.js | 4 +++- client/coral-admin/src/reducers/pageData.js | 16 ++++++++++++++++ routes/admin/index.js | 6 +++++- routes/embed/index.js | 6 +++++- views/admin.ejs | 3 +++ views/embed/stream.ejs | 10 +++++++++- webpack.config.js | 3 --- 10 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 client/coral-admin/src/actions/pageData.js create mode 100644 client/coral-admin/src/reducers/pageData.js diff --git a/client/coral-admin/src/actions/pageData.js b/client/coral-admin/src/actions/pageData.js new file mode 100644 index 000000000..beaef6e60 --- /dev/null +++ b/client/coral-admin/src/actions/pageData.js @@ -0,0 +1,7 @@ +export const PAGE_DATA_UPDATED = 'PAGE_DATA_UPDATED'; + +export const fetchPageData = () => dispatch => { + let json = document.getElementById('data'); + let data = JSON.parse(json.textContent); + dispatch({type: PAGE_DATA_UPDATED, data}); +}; diff --git a/client/coral-admin/src/components/AdminLogin.js b/client/coral-admin/src/components/AdminLogin.js index 11e840eb7..e7e41eb48 100644 --- a/client/coral-admin/src/components/AdminLogin.js +++ b/client/coral-admin/src/components/AdminLogin.js @@ -34,7 +34,7 @@ class AdminLogin extends React.Component { } render () { - const {errorMessage, loginMaxExceeded} = this.props; + const {errorMessage, loginMaxExceeded, recaptchaPublic} = this.props; const signInForm = (
{errorMessage && {lang.t(`errors.${errorMessage}`)}} @@ -62,7 +62,7 @@ class AdminLogin extends React.Component { { loginMaxExceeded && ; } if (!isAdmin) { @@ -27,6 +35,7 @@ class LayoutContainer extends Component { handleLogin={this.props.handleLogin} requestPasswordReset={this.props.requestPasswordReset} passwordRequestSuccess={passwordRequestSuccess} + recaptchaPublic={TALK_RECAPTCHA_PUBLIC} errorMessage={loginError} />; } if (isAdmin && loggedIn) { return ; } @@ -35,11 +44,13 @@ class LayoutContainer extends Component { } const mapStateToProps = state => ({ - auth: state.auth.toJS() + auth: state.auth.toJS(), + TALK_RECAPTCHA_PUBLIC: state.pageData.get('data').get('TALK_RECAPTCHA_PUBLIC', null) }); const mapDispatchToProps = dispatch => ({ checkLogin: () => dispatch(checkLogin()), + fetchPageData: () => dispatch(fetchPageData()), handleLogin: (username, password, recaptchaResponse) => dispatch(handleLogin(username, password, recaptchaResponse)), requestPasswordReset: email => dispatch(requestPasswordReset(email)), handleLogout: () => dispatch(logout()) diff --git a/client/coral-admin/src/reducers/index.js b/client/coral-admin/src/reducers/index.js index 837ad507d..33be4f384 100644 --- a/client/coral-admin/src/reducers/index.js +++ b/client/coral-admin/src/reducers/index.js @@ -4,6 +4,7 @@ import settings from './settings'; import community from './community'; import moderation from './moderation'; import install from './install'; +import pageData from './pageData'; export default { auth, @@ -11,5 +12,6 @@ export default { settings, community, moderation, - install + install, + pageData }; diff --git a/client/coral-admin/src/reducers/pageData.js b/client/coral-admin/src/reducers/pageData.js new file mode 100644 index 000000000..322d092bd --- /dev/null +++ b/client/coral-admin/src/reducers/pageData.js @@ -0,0 +1,16 @@ +import {Map} from 'immutable'; + +import * as actions from '../actions/pageData'; + +const initialState = Map({ + data: Map({}) +}); + +export default function pageData (state = initialState, action) { + switch (action.type) { + case actions.PAGE_DATA_UPDATED: + return state.set('data', Map(action.data)); + default: + return state; + } +} diff --git a/routes/admin/index.js b/routes/admin/index.js index cb256327a..d250ea32a 100644 --- a/routes/admin/index.js +++ b/routes/admin/index.js @@ -16,7 +16,11 @@ router.get('/password-reset', (req, res) => { }); router.get('*', (req, res) => { - res.render('admin', {basePath: '/client/coral-admin'}); + const data = { + TALK_RECAPTCHA_PUBLIC: process.env.TALK_RECAPTCHA_PUBLIC + }; + + res.render('admin', {basePath: '/client/coral-admin', data}); }); module.exports = router; diff --git a/routes/embed/index.js b/routes/embed/index.js index ccc872c1f..efa563422 100644 --- a/routes/embed/index.js +++ b/routes/embed/index.js @@ -7,7 +7,11 @@ router.use('/:embed', (req, res, next) => { case 'stream': return SettingsService.retrieve() .then(({customCssUrl}) => { - return res.render('embed/stream', {customCssUrl}); + const data = { + TALK_RECAPTCHA_PUBLIC: process.env.TALK_RECAPTCHA_PUBLIC + }; + + return res.render('embed/stream', {customCssUrl, data}); }); default: diff --git a/views/admin.ejs b/views/admin.ejs index d4d635dcc..36e3d15c8 100644 --- a/views/admin.ejs +++ b/views/admin.ejs @@ -82,6 +82,9 @@ } + <% if (data != null) { %> + + <% } %>
diff --git a/views/embed/stream.ejs b/views/embed/stream.ejs index fe7baf919..4c300f6d6 100644 --- a/views/embed/stream.ejs +++ b/views/embed/stream.ejs @@ -8,9 +8,17 @@ <% if (locals.customCssUrl) { %> <% } %> + <% if (data != null) { %> + + <% } %> +
- + <%# %> + diff --git a/webpack.config.js b/webpack.config.js index e7652a67d..432bb6155 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -118,9 +118,6 @@ module.exports = { 'process.env': { 'VERSION': `"${require('./package.json').version}"` } - }), - new webpack.EnvironmentPlugin({ - TALK_RECAPTCHA_PUBLIC: JSON.stringify(process.env.TALK_RECAPTCHA_PUBLIC) }) ], resolve: {