import { DropdownAction } from '../actions' import { OPEN_DROPDOWN, CLOSE_DROPDOWN, TOGGLE_DROPDOWN, } from '../constants' export interface DropdownState { [key: string]: boolean } export const initiaDropdownState: DropdownState = { // it's not neccessary to pre initialize dropdowns // you can just start using them with a unique key // or for the sake of safety you could reserve a key here jobsSearchTypeDropdown: false, } export const dropdownReducer = (state = initiaDropdownState, action: DropdownAction): DropdownState => { switch (action.type) { case OPEN_DROPDOWN: { return { ...state, [action.key]: true } } case CLOSE_DROPDOWN: { return { ...state, [action.key]: false } } case TOGGLE_DROPDOWN: { return { ...state, [action.key]: !state[action.key] } } default: { return state } } }