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

26 lines
726 B
JavaScript
Raw Normal View History

import { List as ImmutableList } from 'immutable';
import { MODAL_OPEN, MODAL_CLOSE } from '../actions/modals';
2020-03-27 13:59:38 -07:00
const initialState = ImmutableList();
2020-03-27 13:59:38 -07:00
export default function modal(state = initialState, action) {
switch(action.type) {
case MODAL_OPEN:
return state.push({ modalType: action.modalType, modalProps: action.modalProps });
2020-03-27 13:59:38 -07:00
case MODAL_CLOSE:
if (state.size === 0) {
return state;
}
if (action.modalType === undefined) {
return state.pop();
}
if (state.some(({ modalType }) => action.modalType === modalType)) {
return state.slice(0, state.findLastIndex(({ modalType }) => action.modalType === modalType));
}
return state;
2020-03-27 13:59:38 -07:00
default:
return state;
}
2021-08-03 12:22:51 -07:00
}