gab-social/app/javascript/gabsocial/reducers/status_revisions.js

32 lines
884 B
JavaScript
Raw Normal View History

2020-03-27 22:57:03 +00:00
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
import {
STATUS_REVISIONS_LOAD,
STATUS_REVISIONS_LOAD_SUCCESS,
STATUS_REVISIONS_LOAD_FAIL
} from '../actions/status_revisions'
const initialState = ImmutableMap({
loading: false,
error: null,
revisions: ImmutableList(),
})
export default function statusRevisions(state = initialState, action) {
switch (action.type) {
case STATUS_REVISIONS_LOAD:
return initialState
case STATUS_REVISIONS_LOAD_SUCCESS:
return state.withMutations(mutable => {
mutable.set('loading', false)
mutable.set('revisions', fromJS(action.revisions).reverse())
})
case STATUS_REVISIONS_LOAD_FAIL:
return state.withMutations(mutable => {
mutable.set('loading', false)
mutable.set('error', action.error)
})
default:
return state
}
}