import { memo, useCallback, useEffect, useState } from 'react'; import { Tooltip } from '@chakra-ui/react'; import { BiArrowToBottom } from '@react-icons/all-files/bi/BiArrowToBottom'; import { IoArrowDown } from '@react-icons/all-files/io5/IoArrowDown'; import { IoArrowUp } from '@react-icons/all-files/io5/IoArrowUp'; import { IoOptions } from '@react-icons/all-files/io5/IoOptions'; import { IoPeople } from '@react-icons/all-files/io5/IoPeople'; import { IoPlay } from '@react-icons/all-files/io5/IoPlay'; import { IoPlayForward } from '@react-icons/all-files/io5/IoPlayForward'; import { IoPlaySkipForward } from '@react-icons/all-files/io5/IoPlaySkipForward'; import { IoStop } from '@react-icons/all-files/io5/IoStop'; import { IoTime } from '@react-icons/all-files/io5/IoTime'; import { EndAction, Playback, TimerType } from 'ontime-types'; import { millisToString } from 'ontime-utils'; import TooltipActionBtn from '../../../common/components/buttons/TooltipActionBtn'; import { useAppMode } from '../../../common/stores/appModeStore'; import { millisToDelayString } from '../../../common/utils/dateConfig'; import { tooltipDelayMid } from '../../../ontimeConfig'; import EditableBlockTitle from '../common/EditableBlockTitle'; import { EventItemActions } from '../RundownEntry'; import BlockActionMenu from './composite/BlockActionMenu'; import EventBlockPlayback from './composite/EventBlockPlayback'; import EventBlockProgressBar from './composite/EventBlockProgressBar'; import EventBlockTimers from './composite/EventBlockTimers'; import style from './EventBlock.module.scss'; const blockBtnStyle = { size: 'sm', }; const tooltipProps = { openDelay: tooltipDelayMid, }; interface EventBlockInnerProps { isOpen: boolean; timeStart: number; timeEnd: number; duration: number; eventId: string; isPublic: boolean; endAction: EndAction; timerType: TimerType; title: string; note: string; delay: number; previousEnd: number; next: boolean; skip: boolean; selected: boolean; playback?: Playback; isRolling: boolean; actionHandler: (action: EventItemActions, payload?: any) => void; disableEdit: boolean; isFirstEvent: boolean; } const EventBlockInner = (props: EventBlockInnerProps) => { const { isOpen, timeStart, timeEnd, duration, eventId, isPublic = true, endAction, timerType, title, note, delay, previousEnd, next, skip = false, selected, playback, isRolling, actionHandler, disableEdit, isFirstEvent, } = props; const [renderInner, setRenderInner] = useState(false); const setEditId = useAppMode((state) => state.setEditId); useEffect(() => { setRenderInner(true); }, []); const toggleOpenEvent = useCallback(() => { if (isOpen) { setEditId(null); } else { setEditId(eventId); } }, [eventId, isOpen, setEditId]); const eventIsPlaying = playback === Playback.Play; const eventIsPaused = playback === Playback.Pause; const playBtnStyles = { _hover: {} }; if (!skip && eventIsPlaying) { playBtnStyles._hover = { bg: '#c05621' }; // $ontime-paused } else if (!skip && !eventIsPlaying) { playBtnStyles._hover = {}; } const delayedStart = Math.max(0, timeStart + delay); const newTime = millisToString(delayedStart); const delayTime = delay !== 0 ? millisToDelayString(delay) : null; const overlap = previousEnd - timeStart; const overlapTime = !isFirstEvent ? overlap > 0 ? `Overlapping ${millisToDelayString(overlap)}` : overlap < 0 ? `Spacing ${millisToDelayString(overlap)}` : null : null; return !renderInner ? null : ( <> {next ? ( UP NEXT ) : ( {delayTime}
New Time: {newTime} ) } >
0 ? style.overlap : overlap < 0 && overlapTime !== null ? style.spacing : '' }`} />
timeEnd ? style.nextDay : ''}`} /> )}
{note}
{selected && }
} clickHandler={toggleOpenEvent} tooltip='Event options' aria-label='Event options' tabIndex={-1} backgroundColor={isOpen ? '#2B5ABC' : undefined} color={isOpen ? 'white' : '#f6f6f6'} isDisabled={disableEdit} />
); }; export default memo(EventBlockInner); function EndActionIcon(props: { action: EndAction; className: string }) { const { action, className } = props; if (action === EndAction.LoadNext) { return ; } if (action === EndAction.PlayNext) { return ; } if (action === EndAction.Stop) { return ; } return ; } function TimerIcon(props: { type: TimerType; className: string }) { const { type, className } = props; if (type === TimerType.CountUp) { return ; } if (type === TimerType.Clock) { return ; } if (type === TimerType.TimeToEnd) { return ; } return ; }