bigbuffet-rw/app/soapbox/reducers/dropdown-menu.ts

29 lines
849 B
TypeScript
Raw Normal View History

import { Record as ImmutableRecord } from 'immutable';
import {
DROPDOWN_MENU_OPEN,
DROPDOWN_MENU_CLOSE,
2022-11-16 05:32:32 -08:00
} from '../actions/dropdown-menu';
import type { AnyAction } from 'redux';
2022-11-15 06:10:14 -08:00
import type { DropdownPlacement } from 'soapbox/components/dropdown-menu';
const ReducerRecord = ImmutableRecord({
openId: null as number | null,
placement: null as any as DropdownPlacement,
keyboard: false,
});
type State = ReturnType<typeof ReducerRecord>;
export default function dropdownMenu(state: State = ReducerRecord(), action: AnyAction) {
switch (action.type) {
case DROPDOWN_MENU_OPEN:
return state.merge({ openId: action.id, placement: action.placement, keyboard: action.keyboard });
case DROPDOWN_MENU_CLOSE:
return state.openId === action.id ? state.set('openId', null) : state;
default:
return state;
}
}