import { useCallback, useEffect, useState } from 'react'; import { isOntimeEvent, OntimeEvent } from 'ontime-types'; import CopyTag from '../../common/components/copy-tag/CopyTag'; import { useEventAction } from '../../common/hooks/useEventAction'; import useRundown from '../../common/hooks-query/useRundown'; import { useAppMode } from '../../common/stores/appModeStore'; import EventEditorDataLeft from './composite/EventEditorDataLeft'; import EventEditorDataRight from './composite/EventEditorDataRight'; import EventEditorTimes from './composite/EventEditorTimes'; import style from './EventEditor.module.scss'; export type EventEditorSubmitActions = keyof OntimeEvent; export type EditorUpdateFields = 'cue' | 'title' | 'presenter' | 'subtitle' | 'note' | 'colour'; export default function EventEditor() { const openId = useAppMode((state) => state.editId); const { data } = useRundown(); const { updateEvent } = useEventAction(); const [event, setEvent] = useState(null); useEffect(() => { if (!data || !openId) { setEvent(null); return; } const event = data.find((event) => event.id === openId); if (event && isOntimeEvent(event)) { setEvent(event); } }, [data, openId]); const handleSubmit = useCallback( (field: EditorUpdateFields, value: string) => { updateEvent({ id: event?.id, [field]: value }); }, [event?.id, updateEvent], ); if (!event) { return Loading...; } return (
{event.id} {`/ontime/gotoid/${event.id}`} {`/ontime/gotocue/${event.cue}`}
); }