client/src/components/Session.js
changeset 29 4cfeabef7d5e
parent 12 48ddaa42b810
child 30 4d93f4ed95bc
--- a/client/src/components/Session.js	Mon Jun 12 18:09:13 2017 +0200
+++ b/client/src/components/Session.js	Mon Jun 12 18:12:38 2017 +0200
@@ -21,6 +21,10 @@
     });
   }
 
+  componentDidMount = () => {
+    this.props.notesActions.loadNotesBySession({ _id: this.props.match.params.id });
+  }
+
   render() {
     return (
       <div>
@@ -34,7 +38,7 @@
                     <ControlLabel>Title</ControlLabel>
                     <FormControl
                       type="text"
-                      defaultValue={this.props.currentSession.title}
+                      defaultValue={this.props.currentSession ? this.props.currentSession.title : ''}
                       placeholder="Enter a title for this session"
                       inputRef={ref => { this.title = ref; }}
                     />
@@ -43,7 +47,7 @@
                     <ControlLabel>Description</ControlLabel>
                     <FormControl
                       componentClass="textarea"
-                      defaultValue={this.props.currentSession.description}
+                      defaultValue={this.props.currentSession ? this.props.currentSession.description : ''}
                       placeholder="Enter a description for this session"
                       inputRef={ref => { this.description = ref; }}
                     />
@@ -70,14 +74,12 @@
 
   const sessions = state.get('sessions');
   const notes = state.get('notes');
-
-  const currentSession = sessions.find(session => session.id === sessionId);
-  const notesBySession = notes.filter(note => note.session === sessionId);
+  const currentSession = sessions.find(session => session._id === sessionId);
 
   return {
     currentSession: currentSession,
     sessions: sessions,
-    notes: notesBySession
+    notes: notes
   };
 }