1 import Immutable from 'immutable'; |
1 import Immutable from 'immutable'; |
2 import * as types from '../constants/actionTypes'; |
2 import * as types from '../constants/actionTypes'; |
3 import SessionRecord from '../store/sessionRecord'; |
3 import SessionRecord from '../store/sessionRecord'; |
4 |
4 |
5 // export const currentSession = (state = null, action) => { |
5 export const sessions = (state = Immutable.List([]), action) => { |
6 // switch (action.type) { |
6 let sessionIndex; |
7 // case types.CREATE_SESSION: |
|
8 // return action.session; |
|
9 // default: |
|
10 // return state; |
|
11 // } |
|
12 // }; |
|
13 |
7 |
14 export const sessions = (state = Immutable.List([]), action) => { |
|
15 switch (action.type) { |
8 switch (action.type) { |
16 case types.CREATE_SESSION: |
9 case types.CREATE_SESSION: |
17 return state.push(new SessionRecord(action.session)); |
10 return state.push(new SessionRecord(action.session)); |
18 case types.UPDATE_SESSION: |
11 case types.UPDATE_SESSION: |
19 const sessionToUpdate = state.find(session => session === action.session); |
12 const sessionToUpdate = state.find(session => session === action.session); |
20 const sessionIndex = state.indexOf(action.session); |
13 sessionIndex = state.indexOf(action.session); |
21 if (sessionIndex === -1) { |
14 if (sessionIndex === -1) { |
22 return state; |
15 return state; |
23 } |
16 } |
24 const updatedSession = sessionToUpdate.merge(action.values); |
17 const updatedSession = sessionToUpdate.merge(action.values); |
25 return state.set(sessionIndex, updatedSession); |
18 return state.set(sessionIndex, updatedSession); |
|
19 case types.DELETE_SESSION: |
|
20 sessionIndex = state.indexOf(action.session); |
|
21 if (sessionIndex === -1) { |
|
22 return state; |
|
23 } |
|
24 return state.delete(sessionIndex); |
26 case types.LOAD_SESSIONS: |
25 case types.LOAD_SESSIONS: |
27 return action.sessions; |
26 return action.sessions; |
28 default: |
27 default: |
29 return state; |
28 return state; |
30 } |
29 } |