bigbuffet-rw/app/soapbox/reducers/patron.js

24 lines
687 B
JavaScript
Raw Normal View History

2022-01-10 14:01:24 -08:00
import { Map as ImmutableMap, fromJS } from 'immutable';
2020-07-04 19:25:43 -07:00
import {
PATRON_INSTANCE_FETCH_SUCCESS,
PATRON_ACCOUNT_FETCH_SUCCESS,
} from '../actions/patron';
2020-03-31 15:45:12 -07:00
const initialState = ImmutableMap();
2020-07-04 19:25:43 -07:00
const normalizePatronAccount = (state, account) => {
const normalized = fromJS(account).deleteAll(['url']);
return state.setIn(['accounts', account.url], normalized);
};
2020-03-31 15:45:12 -07:00
export default function patron(state = initialState, action) {
switch(action.type) {
2020-07-04 12:14:36 -07:00
case PATRON_INSTANCE_FETCH_SUCCESS:
2020-07-04 19:25:43 -07:00
return state.set('instance', fromJS(action.instance));
case PATRON_ACCOUNT_FETCH_SUCCESS:
return normalizePatronAccount(state, action.account);
2020-03-31 15:45:12 -07:00
default:
return state;
}
2021-08-03 12:22:51 -07:00
}