import { memo, useCallback, useContext } from 'react'; import { Button, HStack, Menu, MenuButton, MenuDivider, MenuItem, MenuList, Switch } from '@chakra-ui/react'; import { FiMinusCircle } from '@react-icons/all-files/fi/FiMinusCircle'; import { FiTrash2 } from '@react-icons/all-files/fi/FiTrash2'; import { IoAdd } from '@react-icons/all-files/io5/IoAdd'; import { IoTimerOutline } from '@react-icons/all-files/io5/IoTimerOutline'; import { CursorContext } from '../../common/context/CursorContext'; import { useEventAction } from '../../common/hooks/useEventAction'; import { SupportedEvent } from '../../common/models/EventTypes'; import style from './RundownMenu.module.scss'; const RundownMenu = () => { const { isCursorLocked, toggleCursorLocked } = useContext(CursorContext); const { addEvent, deleteAllEvents } = useEventAction(); // TODO: re-write this with stable functions type ActionTypes = SupportedEvent | 'delete-all'; const eventAction = useCallback( (action: ActionTypes) => { switch (action) { case SupportedEvent.Event: addEvent({ type: action }); break; case SupportedEvent.Delay: addEvent({ type: action }); break; case SupportedEvent.Block: addEvent({ type: action }); break; case 'delete-all': deleteAllEvents(); break; } }, [addEvent, deleteAllEvents], ); return ( } size='sm' variant='ontime-subtle' > Event... } onClick={() => eventAction(SupportedEvent.Event)}> Add event at start } onClick={() => eventAction(SupportedEvent.Delay)}> Add delay at start } onClick={() => eventAction(SupportedEvent.Block)}> Add block at start } onClick={() => eventAction('delete-all')} color='#D20300'> Delete all events ); }; export default memo(RundownMenu);