import { memo, useCallback, useRef } from 'react'; import { IoAdd } from 'react-icons/io5'; import { Button } from '@chakra-ui/react'; import { SupportedEvent } from 'ontime-types'; import { useEventAction } from '../../../common/hooks/useEventAction'; import { useEmitLog } from '../../../common/stores/logger'; import style from './QuickAddBlock.module.scss'; interface QuickAddBlockProps { previousEventId?: string; } export default memo(QuickAddBlock); function QuickAddBlock(props: QuickAddBlockProps) { const { previousEventId } = props; const { addEvent } = useEventAction(); const { emitError } = useEmitLog(); const doLinkPrevious = useRef(null); const doPublic = useRef(null); const handleCreateEvent = useCallback( (eventType: SupportedEvent) => { switch (eventType) { case 'event': { const defaultPublic = doPublic?.current?.checked; const linkPrevious = doLinkPrevious?.current?.checked; const newEvent = { type: SupportedEvent.Event }; const options = { after: previousEventId, defaultPublic, lastEventId: previousEventId, linkPrevious, }; addEvent(newEvent, options); break; } case 'delay': { const options = { lastEventId: previousEventId, after: previousEventId, }; addEvent({ type: SupportedEvent.Delay }, options); break; } case 'block': { const options = { lastEventId: previousEventId, after: previousEventId, }; addEvent({ type: SupportedEvent.Block }, options); break; } default: { emitError(`Cannot create unknown event type: ${eventType}`); break; } } }, [previousEventId, addEvent, emitError], ); return (
); }