2018-01-30 11:53:12 -05:00
|
|
|
|
const redux = require('redux');
|
|
|
|
|
const thunk = require('redux-thunk').default;
|
2016-05-16 12:36:28 -04:00
|
|
|
|
// JSX syntax transforms to React.createElement
|
2018-01-30 11:53:12 -05:00
|
|
|
|
const React = require('react'); // eslint-disable-line
|
|
|
|
|
const ReactDOM = require('react-dom');
|
|
|
|
|
const StoreProvider = require('react-redux').Provider;
|
2015-12-16 12:00:42 -05:00
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
|
const IntlProvider = require('./intl.jsx').IntlProvider;
|
|
|
|
|
const permissionsActions = require('../redux/permissions.js');
|
|
|
|
|
const sessionActions = require('../redux/session.js');
|
|
|
|
|
const reducer = require('../redux/reducer.js');
|
2015-10-15 23:11:09 -04:00
|
|
|
|
|
2016-01-14 14:20:21 -05:00
|
|
|
|
require('../main.scss');
|
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
|
/**
|
|
|
|
|
* Function to render views into a full page
|
2018-05-24 16:23:07 -04:00
|
|
|
|
* @param {object} jsx jsx component of the view
|
|
|
|
|
* @param {object} element html element to render to on the template
|
|
|
|
|
* @param {array} reducers list of view-specific reducers
|
|
|
|
|
* @param {object} initialState optional initialState for store
|
|
|
|
|
* @param {bool} enhancer whether or not to apply redux-throttle middleware
|
2018-01-30 11:53:12 -05:00
|
|
|
|
*/
|
2018-05-24 16:23:07 -04:00
|
|
|
|
const render = (jsx, element, reducers, initialState, enhancer) => {
|
2015-10-15 23:11:09 -04:00
|
|
|
|
// Get locale and messages from global namespace (see "init.js")
|
2018-01-30 11:53:12 -05:00
|
|
|
|
let locale = window._locale || 'en';
|
|
|
|
|
let messages = {};
|
2016-05-12 17:57:48 -04:00
|
|
|
|
if (typeof window._messages !== 'undefined') {
|
|
|
|
|
if (typeof window._messages[locale] === 'undefined') {
|
|
|
|
|
// Fall back on the split
|
|
|
|
|
locale = locale.split('-')[0];
|
|
|
|
|
}
|
|
|
|
|
if (typeof window._messages[locale] === 'undefined') {
|
|
|
|
|
// Language appears to not be supported – fall back to 'en'
|
|
|
|
|
locale = 'en';
|
|
|
|
|
}
|
|
|
|
|
messages = window._messages[locale];
|
2016-01-06 14:09:32 -05:00
|
|
|
|
}
|
2015-10-15 23:11:09 -04:00
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
|
const allReducers = reducer(reducers);
|
2018-08-27 17:11:05 -04:00
|
|
|
|
|
2018-05-24 16:23:07 -04:00
|
|
|
|
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || redux.compose;
|
|
|
|
|
const enhancers = enhancer ?
|
|
|
|
|
composeEnhancers(
|
|
|
|
|
redux.applyMiddleware(thunk),
|
|
|
|
|
enhancer
|
|
|
|
|
) :
|
|
|
|
|
composeEnhancers(
|
|
|
|
|
redux.applyMiddleware(thunk)
|
|
|
|
|
);
|
2018-01-30 11:53:12 -05:00
|
|
|
|
const store = redux.createStore(
|
2017-08-31 17:05:22 -04:00
|
|
|
|
allReducers,
|
2018-05-24 16:23:07 -04:00
|
|
|
|
initialState || {},
|
|
|
|
|
enhancers
|
2017-08-31 17:05:22 -04:00
|
|
|
|
);
|
|
|
|
|
|
2016-01-14 08:16:02 -05:00
|
|
|
|
// Render view component
|
2016-03-18 10:54:26 -04:00
|
|
|
|
ReactDOM.render(
|
2016-03-18 11:51:22 -04:00
|
|
|
|
<StoreProvider store={store}>
|
2018-01-30 11:53:12 -05:00
|
|
|
|
<IntlProvider
|
|
|
|
|
locale={locale}
|
|
|
|
|
messages={messages}
|
|
|
|
|
>
|
2016-03-18 11:51:22 -04:00
|
|
|
|
{jsx}
|
|
|
|
|
</IntlProvider>
|
|
|
|
|
</StoreProvider>,
|
2015-10-15 23:11:09 -04:00
|
|
|
|
element
|
|
|
|
|
);
|
|
|
|
|
|
2016-06-28 14:25:11 -04:00
|
|
|
|
// Get initial session & permissions
|
|
|
|
|
store.dispatch(permissionsActions.getPermissions());
|
2016-05-19 16:55:25 -04:00
|
|
|
|
store.dispatch(sessionActions.refreshSession());
|
2015-10-15 23:11:09 -04:00
|
|
|
|
};
|
2015-10-16 15:10:17 -04:00
|
|
|
|
|
|
|
|
|
module.exports = render;
|