client/src/reducers/sessionsReducer.js
author ymh <ymh.work@gmail.com>
Mon, 19 Jun 2017 21:37:33 +0200
changeset 58 f16a080e0bc4
parent 29 4cfeabef7d5e
child 59 1eb52770eefa
permissions -rw-r--r--
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint

import Immutable from 'immutable';
import * as types from '../constants/actionTypes';

// export const currentSession = (state = null, action) => {
//   switch (action.type) {
//     case types.CREATE_SESSION:
//       return action.session;
//     default:
//       return state;
//   }
// };

export const sessions = (state = Immutable.List([]), action) => {
  switch (action.type) {
    case types.CREATE_SESSION:
      return state.push(action.session);
    case types.UPDATE_SESSION:
      const sessionToUpdate = state.find(session => session === action.session);
      const sessionIndex = state.indexOf(action.session);
      if (sessionIndex === -1) {
        return state;
      }
      const updatedSession = Object.assign({}, sessionToUpdate, action.values);
      return state.set(sessionIndex, updatedSession);
    case types.LOAD_SESSIONS:
      return action.sessions;
    default:
      return state;
  }
};