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

44 lines
947 B
JavaScript
Raw Normal View History

2021-03-15 15:29:48 -07:00
import {
Map as ImmutableMap,
OrderedSet as ImmutableOrderedSet,
fromJS,
} from 'immutable';
2022-01-10 14:01:24 -08:00
import { ADMIN_LOG_FETCH_SUCCESS } from 'soapbox/actions/admin';
2021-03-15 15:29:48 -07:00
const initialState = ImmutableMap({
items: ImmutableMap(),
index: ImmutableOrderedSet(),
total: 0,
});
const parseItems = items => {
const ids = [];
const map = {};
2021-03-15 15:29:48 -07:00
items.forEach(item => {
ids.push(item.id);
map[item.id] = item;
});
return { ids: ids, map: map };
};
const importItems = (state, items, total) => {
const { ids, map } = parseItems(items);
return state.withMutations(state => {
state.update('index', v => v.union(ids));
state.update('items', v => v.merge(fromJS(map)));
state.set('total', total);
});
};
export default function admin_log(state = initialState, action) {
switch(action.type) {
case ADMIN_LOG_FETCH_SUCCESS:
return importItems(state, action.items, action.total);
default:
return state;
}
2021-08-03 12:22:51 -07:00
}