diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-07 22:15:17 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:58 +0200 |
| commit | 1b5d2658f9ec06308b2a5ed062f6f5b4798ed733 (patch) | |
| tree | 84d35684a50f897fc4c5f460bed595adf22c9e66 /src/reducers/simulation-list.js | |
| parent | 8218c3d3c21bfa7c4f3ee4872722b9b1261576fb (diff) | |
Reorganize actions and state tree
Diffstat (limited to 'src/reducers/simulation-list.js')
| -rw-r--r-- | src/reducers/simulation-list.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/reducers/simulation-list.js b/src/reducers/simulation-list.js new file mode 100644 index 00000000..86386093 --- /dev/null +++ b/src/reducers/simulation-list.js @@ -0,0 +1,37 @@ +import {combineReducers} from "redux"; +import { + ADD_SIMULATION_SUCCEEDED, + DELETE_SIMULATION_SUCCEEDED, + SET_AUTH_VISIBILITY_FILTER +} from "../actions/simulations"; +import {FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED} from "../actions/users"; + +export function authorizationsOfCurrentUser(state = [], action) { + switch (action.type) { + case FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED: + return action.authorizationsOfCurrentUser; + case ADD_SIMULATION_SUCCEEDED: + return [ + ...state, + action.authorization + ]; + case DELETE_SIMULATION_SUCCEEDED: + return state.filter(authorization => authorization[1] !== action.id); + default: + return state; + } +} + +export function authVisibilityFilter(state = "SHOW_ALL", action) { + switch (action.type) { + case SET_AUTH_VISIBILITY_FILTER: + return action.filter; + default: + return state; + } +} + +export const simulationList = combineReducers({ + authorizationsOfCurrentUser, + authVisibilityFilter, +}); |
