client/src/reducers/sessionsReducer.js
changeset 124 c77570164050
parent 93 469da13402e2
child 129 d48946d164c6
--- a/client/src/reducers/sessionsReducer.js	Wed Jul 19 17:03:40 2017 +0200
+++ b/client/src/reducers/sessionsReducer.js	Thu Jul 20 11:23:08 2017 +0200
@@ -3,27 +3,35 @@
 import SessionRecord from '../store/sessionRecord';
 
 export const sessions = (state = Immutable.List([]), action) => {
-  let sessionIndex;
 
   switch (action.type) {
-    case types.CREATE_SESSION:
+
+    case types.CREATE_SESSION: {
       return state.push(new SessionRecord(action.session));
-    case types.UPDATE_SESSION:
+    }
+    case types.UPDATE_SESSION: {
       const sessionToUpdate = state.find(session => session === action.session);
-      sessionIndex = state.indexOf(action.session);
+      const sessionIndex = state.indexOf(action.session);
       if (sessionIndex === -1) {
         return state;
       }
-      const updatedSession = sessionToUpdate.merge(action.values);
+      const updatedSession = sessionToUpdate.merge(action.values, {modified: true});
       return state.set(sessionIndex, updatedSession);
-    case types.DELETE_SESSION:
-      sessionIndex = state.indexOf(action.session);
+    }
+    case types.DO_DELETE_SESSION: {
+      return state.filter((note) => action.session.get('_id') !== note.session)
+    }
+    case types.DELETE_SESSION: {
+      const sessionIndex = state.indexOf(action.session);
       if (sessionIndex === -1) {
         return state;
       }
-      return state.delete(sessionIndex);
-    case types.LOAD_SESSIONS:
+      const deletedSession = state.get(sessionIndex);
+      return state.set(sessionIndex, deletedSession.merge({deleted:true, modified:true}));
+    }
+    case types.LOAD_SESSIONS: {
       return action.sessions;
+    }
     default:
       return state;
   }