client/src/reducers/sessionsReducer.js
changeset 93 469da13402e2
parent 62 b2514a9bcd49
child 124 c77570164050
--- a/client/src/reducers/sessionsReducer.js	Mon Jun 26 16:50:16 2017 +0200
+++ b/client/src/reducers/sessionsReducer.js	Mon Jun 26 17:40:28 2017 +0200
@@ -2,27 +2,26 @@
 import * as types from '../constants/actionTypes';
 import SessionRecord from '../store/sessionRecord';
 
-// 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) => {
+  let sessionIndex;
 
-export const sessions = (state = Immutable.List([]), action) => {
   switch (action.type) {
     case types.CREATE_SESSION:
       return state.push(new SessionRecord(action.session));
     case types.UPDATE_SESSION:
       const sessionToUpdate = state.find(session => session === action.session);
-      const sessionIndex = state.indexOf(action.session);
+      sessionIndex = state.indexOf(action.session);
       if (sessionIndex === -1) {
         return state;
       }
       const updatedSession = sessionToUpdate.merge(action.values);
       return state.set(sessionIndex, updatedSession);
+    case types.DELETE_SESSION:
+      sessionIndex = state.indexOf(action.session);
+      if (sessionIndex === -1) {
+        return state;
+      }
+      return state.delete(sessionIndex);
     case types.LOAD_SESSIONS:
       return action.sessions;
     default: