mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 06:29:07 +00:00
refactor: allow reset selection by refreshing
This commit is contained in:
committed by
Carlos Valente
parent
73e23ee323
commit
2877475a35
@@ -7,6 +7,7 @@ import {
|
|||||||
Runtime,
|
Runtime,
|
||||||
Settings,
|
Settings,
|
||||||
SupportedEvent,
|
SupportedEvent,
|
||||||
|
TimerPhase,
|
||||||
ViewSettings,
|
ViewSettings,
|
||||||
} from 'ontime-types';
|
} from 'ontime-types';
|
||||||
|
|
||||||
@@ -43,14 +44,12 @@ export default function Countdown(props: CountdownProps) {
|
|||||||
const { getLocalizedString } = useTranslation();
|
const { getLocalizedString } = useTranslation();
|
||||||
|
|
||||||
const [follow, setFollow] = useState<OntimeEvent | null>(null);
|
const [follow, setFollow] = useState<OntimeEvent | null>(null);
|
||||||
const [runningTimer, setRunningTimer] = useState(0);
|
|
||||||
const [runningMessage, setRunningMessage] = useState<TimerMessage>(TimerMessage.unhandled);
|
|
||||||
const [delay, setDelay] = useState(0);
|
const [delay, setDelay] = useState(0);
|
||||||
|
|
||||||
useWindowTitle('Countdown');
|
useWindowTitle('Countdown');
|
||||||
|
|
||||||
// eg. http://localhost:4001/countdown?eventId=ei0us
|
// eg. http://localhost:4001/countdown?eventId=ei0us
|
||||||
// Check for user options
|
// update data to the event we are following
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!backstageEvents) {
|
if (!backstageEvents) {
|
||||||
return;
|
return;
|
||||||
@@ -59,6 +58,12 @@ export default function Countdown(props: CountdownProps) {
|
|||||||
const eventId = searchParams.get('eventid');
|
const eventId = searchParams.get('eventid');
|
||||||
const eventIndex = searchParams.get('event');
|
const eventIndex = searchParams.get('event');
|
||||||
|
|
||||||
|
// if there is no event selected, we reset the data
|
||||||
|
if (!eventId && !eventIndex) {
|
||||||
|
setFollow(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let followThis: OntimeEvent | null = null;
|
let followThis: OntimeEvent | null = null;
|
||||||
const events: OntimeEvent[] = [...backstageEvents].filter((event) => event.type === SupportedEvent.Event);
|
const events: OntimeEvent[] = [...backstageEvents].filter((event) => event.type === SupportedEvent.Event);
|
||||||
|
|
||||||
@@ -75,23 +80,15 @@ export default function Countdown(props: CountdownProps) {
|
|||||||
}
|
}
|
||||||
}, [backstageEvents, searchParams]);
|
}, [backstageEvents, searchParams]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!follow) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { message, timer } = fetchTimerData(time, follow, selectedId, runtime.offset);
|
|
||||||
setRunningMessage(message);
|
|
||||||
setRunningTimer(timer);
|
|
||||||
}, [follow, selectedId, time, runtime.offset]);
|
|
||||||
|
|
||||||
// defer rendering until we load stylesheets
|
// defer rendering until we load stylesheets
|
||||||
if (!shouldRender) {
|
if (!shouldRender) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { message: runningMessage, timer: runningTimer } = fetchTimerData(time, follow, selectedId, runtime.offset);
|
||||||
|
|
||||||
const standby = time.playback !== Playback.Play && time.playback !== Playback.Roll && selectedId === follow?.id;
|
const standby = time.playback !== Playback.Play && time.playback !== Playback.Roll && selectedId === follow?.id;
|
||||||
const finished = time.playback === Playback.Play && (time.current ?? 0) < 0 && time.startedAt;
|
const finished = time.phase === TimerPhase.Overtime;
|
||||||
const isRunningFinished = finished && runningMessage === TimerMessage.running;
|
const isRunningFinished = finished && runningMessage === TimerMessage.running;
|
||||||
const delayedTimerStyles = delay > 0 ? 'aux-timers__value--delayed' : '';
|
const delayedTimerStyles = delay > 0 ? 'aux-timers__value--delayed' : '';
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,14 @@ export const sanitiseTitle = (title: string | null) => (title ? title : '{no tit
|
|||||||
*/
|
*/
|
||||||
export const fetchTimerData = (
|
export const fetchTimerData = (
|
||||||
time: ViewExtendedTimer,
|
time: ViewExtendedTimer,
|
||||||
follow: OntimeEvent,
|
follow: OntimeEvent | null,
|
||||||
selectedId: string | null,
|
selectedId: string | null,
|
||||||
offset: number,
|
offset: number,
|
||||||
): { message: TimerMessage; timer: number } => {
|
): { message: TimerMessage; timer: number } => {
|
||||||
|
if (follow === null) {
|
||||||
|
return { message: TimerMessage.unhandled, timer: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedId === follow.id) {
|
if (selectedId === follow.id) {
|
||||||
// if it is selected, it may not be running
|
// if it is selected, it may not be running
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user