bigbuffet-rw/app/soapbox/reducers/dropdown_menu.ts
marcin mikołajczak 41a2b1f08f Reducers: TypeScript, fixes
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2022-06-05 20:21:25 +02:00

28 lines
849 B
TypeScript

import { Record as ImmutableRecord } from 'immutable';
import {
DROPDOWN_MENU_OPEN,
DROPDOWN_MENU_CLOSE,
} from '../actions/dropdown_menu';
import type { AnyAction } from 'redux';
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;
}
}