# HG changeset patch # User Alexandre Segura # Date 1498491628 -7200 # Node ID 469da13402e25cb8e0ed0d5f259853e609e086e4 # Parent 5a73b44925f2d9c3630244b13092972e835c032e Allow to delete session. diff -r 5a73b44925f2 -r 469da13402e2 client/src/actions/sessionsActions.js --- a/client/src/actions/sessionsActions.js Mon Jun 26 16:50:16 2017 +0200 +++ b/client/src/actions/sessionsActions.js Mon Jun 26 17:40:28 2017 +0200 @@ -47,6 +47,23 @@ }; } +export const deleteSession = (session) => { + return { + type: types.DELETE_SESSION, + session: session, + meta: { + offline: { + effect: { + url: `/api/notes/sessions/${session.get('_id')}/`, + method: 'DELETE', + }, + commit: { type: types.NOOP }, + rollback: { type: types.NOOP } + } + } + }; +} + export const loadSessions = () => { return { type: types.LOAD_SESSIONS diff -r 5a73b44925f2 -r 469da13402e2 client/src/components/SessionList.js --- a/client/src/components/SessionList.js Mon Jun 26 16:50:16 2017 +0200 +++ b/client/src/components/SessionList.js Mon Jun 26 17:40:28 2017 +0200 @@ -16,6 +16,13 @@ this.props.history.push('/sessions/' + sessionId); } + onClickDelete(session, e) { + e.preventDefault(); + e.stopPropagation(); + + this.props.sessionsActions.deleteSession(session); + } + render() { return (
@@ -29,6 +36,9 @@ key={session.get('_id')} onClick={() => this.props.history.push('/sessions/' + session.get('_id'))}> {session.title || 'No title'} {session.get('_id')} {moment(session.get('date')).format('DD/MM/YYYY')} + + delete + )} @@ -43,8 +53,6 @@ function mapStateToProps(state, props) { return { - // currentSession: state.get('currentSession'), - // sessions: state.get('sessions') sessions: state['sessions'] }; } diff -r 5a73b44925f2 -r 469da13402e2 client/src/constants/actionTypes.js --- a/client/src/constants/actionTypes.js Mon Jun 26 16:50:16 2017 +0200 +++ b/client/src/constants/actionTypes.js Mon Jun 26 17:40:28 2017 +0200 @@ -6,6 +6,7 @@ export const CREATE_SESSION = 'CREATE_SESSION'; export const UPDATE_SESSION = 'UPDATE_SESSION'; +export const DELETE_SESSION = 'DELETE_SESSION'; export const LOAD_SESSIONS = 'LOAD_SESSIONS'; export const AUTH_LOGIN_SUBMIT = 'AUTH_LOGIN_SUBMIT'; diff -r 5a73b44925f2 -r 469da13402e2 client/src/reducers/sessionsReducer.js --- 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: