2020-10-29 23:46:54 +00:00
|
|
|
import {
|
|
|
|
Map as ImmutableMap,
|
|
|
|
List as ImmutableList,
|
|
|
|
fromJS,
|
|
|
|
} from 'immutable'
|
|
|
|
import {
|
|
|
|
LINK_FETCH_REQUEST,
|
|
|
|
LINK_FETCH_SUCCESS,
|
|
|
|
LINK_FETCH_FAIL,
|
2020-10-31 23:10:59 +00:00
|
|
|
IMPORT_LINK_CARDS,
|
2020-10-29 23:46:54 +00:00
|
|
|
} from '../actions/links'
|
|
|
|
|
|
|
|
const initialState = ImmutableMap({
|
|
|
|
isFetched: false,
|
|
|
|
isError: false,
|
|
|
|
isLoading: false,
|
|
|
|
items: ImmutableMap(),
|
|
|
|
})
|
|
|
|
|
|
|
|
export default function links(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case LINK_FETCH_REQUEST:
|
|
|
|
return state.set('isLoading', true)
|
|
|
|
case LINK_FETCH_SUCCESS:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.setIn(['items', `${action.card.id}`], fromJS(action.card))
|
|
|
|
mutable.set('isLoading', false)
|
|
|
|
mutable.set('isFetched', false)
|
|
|
|
mutable.set('isError', false)
|
|
|
|
})
|
2020-10-31 23:10:59 +00:00
|
|
|
case IMPORT_LINK_CARDS:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
action.cards.forEach((card) => mutable.setIn(['items', `${card.id}`], fromJS(card)))
|
|
|
|
mutable.set('isLoading', false)
|
|
|
|
mutable.set('isFetched', false)
|
|
|
|
mutable.set('isError', false)
|
|
|
|
})
|
2020-10-29 23:46:54 +00:00
|
|
|
case LINK_FETCH_FAIL:
|
|
|
|
return state.withMutations((mutable) => {
|
|
|
|
mutable.set('isLoading', false)
|
|
|
|
mutable.set('isFetched', false)
|
|
|
|
mutable.set('isError', true)
|
|
|
|
})
|
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|