Added LinkTimeline and PreviewCard fetching by id

• Added:
- LinkTimeline and PreviewCard fetching by id
This commit is contained in:
mgabdev
2020-10-29 18:46:54 -05:00
parent f7dc62460c
commit f129d9c49b
15 changed files with 325 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
import {
Map as ImmutableMap,
List as ImmutableList,
fromJS,
} from 'immutable'
import {
LINK_FETCH_REQUEST,
LINK_FETCH_SUCCESS,
LINK_FETCH_FAIL,
} 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)
})
case LINK_FETCH_FAIL:
return state.withMutations((mutable) => {
mutable.set('isLoading', false)
mutable.set('isFetched', false)
mutable.set('isError', true)
})
default:
return state
}
}