chuckya/app/javascript/flavours/glitch/reducers/domain_lists.js
Renaud Chaput 7fe5623a27 [Glitch] Use Immutable Record for accounts in Redux state
Port 3bf2a7296e to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2023-12-20 19:49:44 +01:00

26 lines
888 B
JavaScript

import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
import {
DOMAIN_BLOCKS_FETCH_SUCCESS,
DOMAIN_BLOCKS_EXPAND_SUCCESS,
unblockDomainSuccess
} from '../actions/domain_blocks';
const initialState = ImmutableMap({
blocks: ImmutableMap({
items: ImmutableOrderedSet(),
}),
});
export default function domainLists(state = initialState, action) {
switch(action.type) {
case DOMAIN_BLOCKS_FETCH_SUCCESS:
return state.setIn(['blocks', 'items'], ImmutableOrderedSet(action.domains)).setIn(['blocks', 'next'], action.next);
case DOMAIN_BLOCKS_EXPAND_SUCCESS:
return state.updateIn(['blocks', 'items'], set => set.union(action.domains)).setIn(['blocks', 'next'], action.next);
case unblockDomainSuccess.type:
return state.updateIn(['blocks', 'items'], set => set.delete(action.payload.domain));
default:
return state;
}
}