diff --git a/src/components/intro/intro.jsx b/src/components/intro/intro.jsx index 0dd57a8ca..acc1de4a7 100644 --- a/src/components/intro/intro.jsx +++ b/src/components/intro/intro.jsx @@ -2,7 +2,7 @@ var connect = require('react-redux').connect; var omit = require('lodash.omit'); var React = require('react'); -var actions = require('../../redux/auth.js'); +var sessionActions = require('../../redux/session.js'); var Modal = require('../modal/modal.jsx'); var Registration = require('../registration/registration.jsx'); @@ -48,7 +48,7 @@ var Intro = React.createClass({ this.setState({'registrationOpen': false}); }, completeRegistration: function () { - this.props.dispatch(actions.refreshSession()); + this.props.dispatch(sessionActions.refreshSession()); this.closeRegistration(); }, render: function () { diff --git a/src/components/navigation/www/navigation.jsx b/src/components/navigation/www/navigation.jsx index 25b160a42..ffeaf21d3 100644 --- a/src/components/navigation/www/navigation.jsx +++ b/src/components/navigation/www/navigation.jsx @@ -5,7 +5,7 @@ var ReactIntl = require('react-intl'); var FormattedMessage = ReactIntl.FormattedMessage; var injectIntl = ReactIntl.injectIntl; -var actions = require('../../../redux/auth.js'); +var sessionActions = require('../../../redux/session.js'); var Api = require('../../../mixins/api.jsx'); var Avatar = require('../../avatar/avatar.jsx'); @@ -132,7 +132,7 @@ var Navigation = React.createClass({ this.showCanceledDeletion(); } }.bind(this)); - this.props.dispatch(actions.refreshSession()); + this.props.dispatch(sessionActions.refreshSession()); } } // JS error already logged by api mixin @@ -149,7 +149,7 @@ var Navigation = React.createClass({ }, function (err) { if (err) log.error(err); this.closeLogin(); - this.props.dispatch(actions.refreshSession()); + this.props.dispatch(sessionActions.refreshSession()); }.bind(this)); }, handleAccountNavClick: function (e) { @@ -169,7 +169,7 @@ var Navigation = React.createClass({ this.setState({'registrationOpen': false}); }, completeRegistration: function () { - this.props.dispatch(actions.refreshSession()); + this.props.dispatch(sessionActions.refreshSession()); this.closeRegistration(); }, render: function () { diff --git a/src/lib/render.jsx b/src/lib/render.jsx index 5706f3197..9c7ed465c 100644 --- a/src/lib/render.jsx +++ b/src/lib/render.jsx @@ -6,7 +6,7 @@ var ReactDOM = require('react-dom'); var StoreProvider = require('react-redux').Provider; var IntlProvider = require('./intl.jsx').IntlProvider; -var authActions = require('../redux/auth.js'); +var sessionActions = require('../redux/session.js'); var reducer = require('../redux/reducer.js'); require('../main.scss'); @@ -43,7 +43,7 @@ var render = function (jsx, element) { ); // Get initial session - store.dispatch(authActions.refreshSession()); + store.dispatch(sessionActions.refreshSession()); }; module.exports = render; diff --git a/src/redux/conference-details.js b/src/redux/conference-details.js index dece82fdd..0d46b1282 100644 --- a/src/redux/conference-details.js +++ b/src/redux/conference-details.js @@ -74,6 +74,9 @@ module.exports.getDetails = function (id) { dispatch(module.exports.setDetailsError('Not Found')); } return; + } else { + dispatch(module.exports.setDetailsError('An unexpected error occurred')); + return; } }); }; diff --git a/src/redux/conference-schedule.js b/src/redux/conference-schedule.js index 0877e9a57..c86c86535 100644 --- a/src/redux/conference-schedule.js +++ b/src/redux/conference-schedule.js @@ -2,30 +2,17 @@ var keyMirror = require('keymirror'); var api = require('../mixins/api.jsx').api; var Types = keyMirror({ - SET_DAY: null, SET_SCHEDULE: null, SET_SCHEDULE_FETCHING: null, - SET_DAY_ERROR: null, SET_SCHEDULE_ERROR: null }); -module.exports.dayReducer = function (state, action) { - if (typeof state === 'undefined') { - state = ''; - } - switch (action.type) { - case Types.SET_DAY: - return action.day; - case Types.SET_DAY_ERROR: - return state; - default: - return state; - } -}; - module.exports.scheduleReducer = function (state, action) { if (typeof state === 'undefined') { - state = []; + state = { + chunks: [], + day: '' + }; } switch (action.type) { case Types.SET_SCHEDULE: @@ -39,20 +26,6 @@ module.exports.scheduleReducer = function (state, action) { } }; -module.exports.setDayError = function (error) { - return { - type: Types.SET_DAY_ERROR, - error: error - }; -}; - -module.exports.setDay = function (day) { - return { - type: Types.SET_DAY, - day: day - }; -}; - module.exports.setSchedule = function (schedule) { return { type: Types.SET_SCHEDULE, @@ -93,7 +66,6 @@ module.exports.getDaySchedule = function (day) { uri: '/conference/schedule/' + day }, function (err, body) { if (err) { - dispatch(module.exports.setDayError(err)); dispatch(module.exports.setScheduleError(err)); return; } @@ -150,8 +122,13 @@ module.exports.getDaySchedule = function (day) { items: scheduleByChunk.chunks[scheduleByChunk.info[i].name] }); } - dispatch(module.exports.setDay(day)); - dispatch(module.exports.setSchedule(schedule)); + dispatch(module.exports.setSchedule({ + chunks: schedule, + day: day + })); + return; + } else { + dispatch(module.exports.setScheduleError('An unexpected error occurred')); return; } }); diff --git a/src/redux/reducer.js b/src/redux/reducer.js index 356cb55ac..71bdfc11c 100644 --- a/src/redux/reducer.js +++ b/src/redux/reducer.js @@ -1,15 +1,15 @@ var combineReducers = require('redux').combineReducers; -var authReducers = require('./auth.js'); -var conferenceScheduleReducers = require('./conference-schedule.js'); -var conferenceDetailsReducers = require('./conference-details.js'); +var scheduleReducer = require('./conference-schedule.js').scheduleReducer; +var detailsReducer = require('./conference-details.js').detailsReducer; +var sessionReducer = require('./session.js').sessionReducer; +var tokenReducer = require('./token.js').tokenReducer; var appReducer = combineReducers({ - session: authReducers.sessionReducer, - token: authReducers.tokenReducer, - day: conferenceScheduleReducers.dayReducer, - schedule: conferenceScheduleReducers.scheduleReducer, - details: conferenceDetailsReducers.detailsReducer + session: sessionReducer, + token: tokenReducer, + conferenceSchedule: scheduleReducer, + conferenceDetails: detailsReducer }); module.exports = appReducer; diff --git a/src/redux/session.js b/src/redux/session.js new file mode 100644 index 000000000..9038a1c8c --- /dev/null +++ b/src/redux/session.js @@ -0,0 +1,58 @@ +var keyMirror = require('keymirror'); +var api = require('../mixins/api.jsx').api; + +var Types = keyMirror({ + SET_SESSION: null, + SET_SESSION_ERROR: null +}); + +module.exports.sessionReducer = function (state, action) { + // Reducer for handling changes to session state + if (typeof state === 'undefined') { + state = {}; + } + switch (action.type) { + case Types.SET_SESSION: + return action.session; + case Types.SET_SESSION_ERROR: + // TODO: do something with action.error + return state; + default: + return state; + } +}; + +module.exports.setSessionError = function (error) { + return { + type: Types.SET_SESSION_ERROR, + error: error + }; +}; + +module.exports.setSession = function (session) { + return { + type: Types.SET_SESSION, + session: session + }; +}; + +module.exports.refreshSession = function () { + return function (dispatch) { + api({ + host: '', + uri: '/session/' + }, function (err, body) { + if (err) return dispatch(module.exports.setSessionError(err)); + + if (typeof body !== 'undefined') { + if (body.banned) { + return window.location = body.url; + } else { + dispatch(module.exports.getToken()); + dispatch(module.exports.setSession(body)); + return; + } + } + }); + }; +}; diff --git a/src/redux/auth.js b/src/redux/token.js similarity index 51% rename from src/redux/auth.js rename to src/redux/token.js index aff9ba600..41be10a33 100644 --- a/src/redux/auth.js +++ b/src/redux/token.js @@ -1,31 +1,12 @@ var keyMirror = require('keymirror'); -var api = require('../mixins/api.jsx').api; var jar = require('../lib/jar.js'); var Types = keyMirror({ - SET_SESSION: null, - SET_SESSION_ERROR: null, SET_TOKEN: null, SET_TOKEN_ERROR: null, USE_TOKEN: null }); -module.exports.sessionReducer = function (state, action) { - // Reducer for handling changes to session state - if (typeof state === 'undefined') { - state = {}; - } - switch (action.type) { - case Types.SET_SESSION: - return action.session; - case Types.SET_SESSION_ERROR: - // TODO: do something with action.error - return state; - default: - return state; - } -}; - module.exports.tokenReducer = function (state, action) { // Reducer for updating the api token if (typeof state === 'undefined') { @@ -42,41 +23,6 @@ module.exports.tokenReducer = function (state, action) { } }; -module.exports.setSessionError = function (error) { - return { - type: Types.SET_SESSION_ERROR, - error: error - }; -}; - -module.exports.setSession = function (session) { - return { - type: Types.SET_SESSION, - session: session - }; -}; - -module.exports.refreshSession = function () { - return function (dispatch) { - api({ - host: '', - uri: '/session/' - }, function (err, body) { - if (err) return dispatch(module.exports.setSessionError(err)); - - if (typeof body !== 'undefined') { - if (body.banned) { - return window.location = body.url; - } else { - dispatch(module.exports.getToken()); - dispatch(module.exports.setSession(body)); - return; - } - } - }); - }; -}; - module.exports.getToken = function () { return function (dispatch) { jar.get('scratchsessionsid', function (err, value) { diff --git a/src/views/conference/details/details.jsx b/src/views/conference/details/details.jsx index 769832d93..086f376a1 100644 --- a/src/views/conference/details/details.jsx +++ b/src/views/conference/details/details.jsx @@ -13,7 +13,7 @@ var ConferenceDetails = React.createClass({ type: 'ConferenceDetails', propTypes: { detailsId: React.PropTypes.number, - details: React.PropTypes.object + conferenceDetails: React.PropTypes.object }, componentDidMount: function () { var pathname = window.location.pathname.toLowerCase(); @@ -26,13 +26,13 @@ var ConferenceDetails = React.createClass({ }, render: function () { var backUri = '/conference/schedule'; - if (!this.props.details.error && !this.props.details.fetching) { - backUri = backUri + '#' + this.props.details.Day; + if (!this.props.conferenceDetails.error && !this.props.conferenceDetails.fetching) { + backUri = backUri + '#' + this.props.conferenceDetails.Day; } var classes = classNames({ 'inner': true, 'details': true, - 'fetching': this.props.details.fetching + 'fetching': this.props.conferenceDetails.fetching }); return (