import QRCode from 'react-qr-code'; import { useViewportSize } from '@mantine/hooks'; import { CustomFields, OntimeEvent, ProjectData, Settings } from 'ontime-types'; import Empty from '../../common/components/state/Empty'; import TitleCard from '../../common/components/title-card/TitleCard'; import ViewLogo from '../../common/components/view-logo/ViewLogo'; import ViewParamsEditor from '../../common/components/view-params-editor/ViewParamsEditor'; import { useWindowTitle } from '../../common/hooks/useWindowTitle'; import { ViewExtendedTimer } from '../../common/models/TimeManager.type'; import { cx } from '../../common/utils/styleUtils'; import { formatTime, getDefaultFormat } from '../../common/utils/time'; import SuperscriptTime from '../../features/viewers/common/superscript-time/SuperscriptTime'; import { useTranslation } from '../../translation/TranslationProvider'; import { getIsPendingStart } from '../backstage/backstage.utils'; import ScheduleExport from '../common/schedule/ScheduleExport'; import { getPublicOptions, usePublicOptions } from './public.options'; import { getCardData, getFirstStartTime } from './public.utils'; import './Public.scss'; interface BackstageProps { customFields: CustomFields; events: OntimeEvent[]; general: ProjectData; isMirrored: boolean; publicEventNow: OntimeEvent | null; publicEventNext: OntimeEvent | null; time: ViewExtendedTimer; publicSelectedId: string | null; settings: Settings | undefined; } export default function Public(props: BackstageProps) { const { customFields, events, general, isMirrored, publicEventNow, publicEventNext, time, publicSelectedId, settings, } = props; const { getLocalizedString } = useTranslation(); const { secondarySource } = usePublicOptions(); const { height: screenHeight } = useViewportSize(); useWindowTitle('Public Schedule'); // gather card data const hasEvents = events.length > 0; const { showNow, nowMain, nowSecondary, showNext, nextMain, nextSecondary } = getCardData( publicEventNow, publicEventNext, 'title', secondarySource, time.playback, ); // gather timer data const clock = formatTime(time.clock); const isPendingStart = getIsPendingStart(time.playback, time.phase); const scheduledStart = (() => { if (showNow) return undefined; if (!hasEvents) return undefined; return getFirstStartTime(events[0]); })(); // gather presentation styles const qrSize = Math.max(window.innerWidth / 15, 72); const showSchedule = hasEvents && screenHeight > 700; // in vertical screens we may not have space const showPending = scheduledStart !== undefined; // gather option data const defaultFormat = getDefaultFormat(settings?.timeFormat); const publicOptions = getPublicOptions(defaultFormat, customFields); return (