import { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { overrideStylesURL } from '../../../common/api/apiConstants'; import NavLogo from '../../../common/components/nav/NavLogo'; import useFitText from '../../../common/hooks/useFitText'; import { useRuntimeStylesheet } from '../../../common/hooks/useRuntimeStylesheet'; import { formatDisplay } from '../../../common/utils/dateConfig'; import { formatEventList, getEventsWithDelay, trimEventlist, } from '../../../common/utils/eventsManager'; import { formatTime, stringFromMillis } from '../../../common/utils/time'; import './StudioClock.scss'; const formatOptions = { showSeconds: false, format: 'hh:mm', }; export default function StudioClock(props) { const { title, time, backstageEvents, selectedId, nextId, onAir, viewSettings } = props; // deferring rendering seems to affect styling (font and useFitText) useRuntimeStylesheet(viewSettings?.overrideStyles && overrideStylesURL); const { fontSize: titleFontSize, ref: titleRef } = useFitText({ maxFontSize: 500 }); const [schedule, setSchedule] = useState([]); const activeIndicators = [...Array(12).keys()]; const secondsIndicators = [...Array(60).keys()]; const MAX_TITLES = 10; useEffect(() => { document.title = 'ontime - Studio Clock'; }, []); // Prepare event list useEffect(() => { if (backstageEvents == null) return; const delayed = getEventsWithDelay(backstageEvents); const events = delayed.filter((e) => e.type === 'event'); const trimmed = trimEventlist(events, selectedId, MAX_TITLES); const formatted = formatEventList(trimmed, selectedId, nextId, { showEnd: false, }); setSchedule(formatted); }, [backstageEvents, nextId, selectedId] ); const clock = formatTime(time.clock, formatOptions); const [, , secondsNow] = stringFromMillis(time.clock).split(':'); return (
{clock}
{title.titleNext}
{selectedId != null && formatDisplay(time.running)}
{activeIndicators.map((i) => (
))} {secondsIndicators.map((i) => (
))}
ON AIR
    {schedule.map((s) => (
  • {`${s.time} ${s.title}`}
  • ))}
); } StudioClock.propTypes = { title: PropTypes.object, time: PropTypes.object, backstageEvents: PropTypes.array, selectedId: PropTypes.string, nextId: PropTypes.string, onAir: PropTypes.bool, viewSettings: PropTypes.object, };