# HG changeset patch # User ymh # Date 1500542588 -7200 # Node ID c775701640504d7ec95eb0e62588356c5519894d # Parent 6542f93cdc0d0a0992c0af1765ced499be943599 implement soft delete and indicator that session and notes have been modiied diff -r 6542f93cdc0d -r c77570164050 client/src/actions/sessionsActions.js --- a/client/src/actions/sessionsActions.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/actions/sessionsActions.js Thu Jul 20 11:23:08 2017 +0200 @@ -9,6 +9,8 @@ date: now(), title: '', description: '', + deleted: false, + modified: true }; return { diff -r 6542f93cdc0d -r c77570164050 client/src/components/NotesList.js --- a/client/src/components/NotesList.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/components/NotesList.js Thu Jul 20 11:23:08 2017 +0200 @@ -88,7 +88,10 @@ }; function mapStateToProps(state, props) { - return props; + return { + ...props, + notes : props.notes.filter(note => !note.deleted) + }; } function mapDispatchToProps(dispatch) { diff -r 6542f93cdc0d -r c77570164050 client/src/components/SessionList.js --- a/client/src/components/SessionList.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/components/SessionList.js Thu Jul 20 11:23:08 2017 +0200 @@ -55,10 +55,8 @@ {this.props.sessions.map((session) => - this.props.history.push('/sessions/' + session.get('_id'))}> - {session.title || 'No title'} {session.get('_id')} {moment(session.get('date')).format('DD/MM/YYYY')} + + this.props.history.push('/sessions/' + session.get('_id'))}>{session.title || 'No title'} {session.get('_id')} {moment(session.get('date')).format('DD/MM/YYYY')} delete @@ -87,7 +85,7 @@ function mapStateToProps(state, props) { return { - sessions: state['sessions'] + sessions: state['sessions'].filter(session => !session.deleted) }; } diff -r 6542f93cdc0d -r c77570164050 client/src/components/SessionSummary.js --- a/client/src/components/SessionSummary.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/components/SessionSummary.js Thu Jul 20 11:23:08 2017 +0200 @@ -23,7 +23,10 @@ } function mapStateToProps(state, props) { - return props; + return { + ...props, + notes : props.notes.filter(note => !note.deleted) + }; } export default connect(mapStateToProps)(SessionSummary); diff -r 6542f93cdc0d -r c77570164050 client/src/constants/actionTypes.js --- a/client/src/constants/actionTypes.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/constants/actionTypes.js Thu Jul 20 11:23:08 2017 +0200 @@ -2,11 +2,13 @@ export const ADD_NOTE = 'ADD_NOTE'; export const DELETE_NOTE = 'DELETE_NOTE'; +export const DO_DELETE_NOTE = 'DO_DELETE_NOTE'; export const UPDATE_NOTE = 'UPDATE_NOTE'; export const CREATE_SESSION = 'CREATE_SESSION'; export const UPDATE_SESSION = 'UPDATE_SESSION'; export const DELETE_SESSION = 'DELETE_SESSION'; +export const DO_DELETE_SESSION = 'DO_DELETE_SESSION'; export const LOAD_SESSIONS = 'LOAD_SESSIONS'; export const AUTH_LOGIN_SUBMIT = 'AUTH_LOGIN_SUBMIT'; diff -r 6542f93cdc0d -r c77570164050 client/src/reducers/notesReducer.js --- a/client/src/reducers/notesReducer.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/reducers/notesReducer.js Thu Jul 20 11:23:08 2017 +0200 @@ -12,21 +12,34 @@ export default (state = Immutable.List([]), action) => { switch (action.type) { - case types.ADD_NOTE: + case types.ADD_NOTE: { return state.push(new NoteRecord(action.note)); - case types.DELETE_NOTE: + } + case types.DELETE_NOTE: { + const noteIndex = findNoteIndex(state, action.note.get('_id')); + const note = findNote(state, action.note.get('_id')); + return state.set(noteIndex, note.merge({deleted:true, modified:true})); + } + case types.DO_DELETE_NOTE: { const noteIndex = state.findIndex((note) => note.get('_id') === action.note.get('_id')); return state.delete(noteIndex); - case types.UPDATE_NOTE: + } + case types.UPDATE_NOTE: { const index = findNoteIndex(state, action.note.get('_id')); const note = findNote(state, action.note.get('_id')); - let newNote = note; - Object.entries(action.data).forEach(([key, value]) => { - newNote = note.set(key, value) - }); + let newNote = note.merge(action.data, {modified:true}); return state.set(index, newNote); - case types.DELETE_SESSION: - return state.filter((note) => action.session.get('_id') !== note.session) + } + case types.DELETE_SESSION: { + const sessionId = action.session.get('_id'); + return state.map((note) => { + if(sessionId === note.session) { + return note.merge({deleted:true, modified:true}); + } else { + return note; + } + }) + } default: return state; } diff -r 6542f93cdc0d -r c77570164050 client/src/reducers/sessionsReducer.js --- 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; } diff -r 6542f93cdc0d -r c77570164050 client/src/store/noteRecord.js --- a/client/src/store/noteRecord.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/store/noteRecord.js Thu Jul 20 11:23:08 2017 +0200 @@ -13,5 +13,7 @@ categories: [], - marginComment: '' + marginComment: '', + deleted: false, + modified: true }, 'Note'); diff -r 6542f93cdc0d -r c77570164050 client/src/store/sessionRecord.js --- a/client/src/store/sessionRecord.js Wed Jul 19 17:03:40 2017 +0200 +++ b/client/src/store/sessionRecord.js Thu Jul 20 11:23:08 2017 +0200 @@ -8,6 +8,9 @@ date: '', - group: null + group: null, + + deleted: false, + modified: true }, 'Session');