summaryrefslogtreecommitdiff
path: root/frontend/src/reducers/project-list.js
blob: 1f1aa8d05d28ca37ddc30d1fa6ba49b6b61ea5b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { combineReducers } from 'redux'
import { ADD_PROJECT_SUCCEEDED, DELETE_PROJECT_SUCCEEDED, SET_AUTH_VISIBILITY_FILTER } from '../actions/projects'
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_PROJECT_SUCCEEDED:
            return [...state, action.authorization]
        case DELETE_PROJECT_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 projectList = combineReducers({
    authorizationsOfCurrentUser,
    authVisibilityFilter,
})