client/src/reducers/notesReducer.js
changeset 80 b3a02ea6d097
parent 79 772b73e31069
child 96 b58463d7dc8e
--- a/client/src/reducers/notesReducer.js	Fri Jun 23 10:16:49 2017 +0200
+++ b/client/src/reducers/notesReducer.js	Fri Jun 23 11:16:34 2017 +0200
@@ -2,6 +2,14 @@
 import * as types from '../constants/actionTypes';
 import NoteRecord from '../store/noteRecord';
 
+const findNoteIndex = (notes, id) => {
+  return notes.findIndex((note) => note.get('_id') === id);
+}
+
+const findNote = (notes, id) => {
+  return notes.get(findNoteIndex(notes, id));
+}
+
 export default (state = Immutable.List([]), action) => {
   switch (action.type) {
     case types.ADD_NOTE:
@@ -9,6 +17,15 @@
     case types.DELETE_NOTE:
       const noteIndex = state.findIndex((note) => note.get('_id') === action.note.get('_id'));
       return state.delete(noteIndex);
+    case types.UPDATE_NOTE:
+      const index = findNoteIndex(state, action.note.get('_id'));
+      const note = findNote(state, action.note.get('_id'));
+      const newNote = note
+        .set('plain', action.data.plain)
+        .set('raw', action.data.raw)
+        .set('html', action.data.html)
+        .set('categories', action.data.categories);
+      return state.set(index, newNote);
     default:
       return state;
   }