mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 12:23:51 +00:00
110d3fb7a3
* lint: cleanup unused * refactor: rename component to avoid conflict * style: gap in element row * refactor: rename playstate -> playback * refactor: cleanup usages of timer and prepare integration manager * style: re-arrange button order * refactor: improve event loading * feat(timer-service): hot reload * fix: issue with duration input * chore: cleanup debug * refactor: resolve poll from runtime store * refactor: cleanup merge * refactor: small improvements in timer hot-reload
35 lines
1014 B
TypeScript
35 lines
1014 B
TypeScript
import { useTimer } from '../../../../common/hooks/useSocket';
|
|
import { Playback } from '../../../../common/models/OntimeTypes';
|
|
import { clamp } from '../../../../common/utils/math';
|
|
|
|
import style from './EventBlockProgressBar.module.scss';
|
|
|
|
interface EventBlockProgressBarProps {
|
|
playback?: Playback;
|
|
}
|
|
|
|
export default function EventBlockProgressBar(props: EventBlockProgressBarProps) {
|
|
const { playback } = props;
|
|
const { data: timer } = useTimer();
|
|
const now = Math.floor(Math.max((timer?.current ?? 1) / 1000, 0));
|
|
const complete = (timer?.duration ?? 1) / 1000;
|
|
const elapsed = clamp(100 - (now * 100) / complete, 0, 100);
|
|
const progress = `${elapsed}%`;
|
|
|
|
if (timer?.current != null && timer?.current < 0) {
|
|
return (
|
|
<div
|
|
className={`${style.progressBar} ${style.overtime}`}
|
|
style={{ width: '100%' }}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={`${style.progressBar} ${playback ? style[playback] : ''}`}
|
|
style={{ width: progress }}
|
|
/>
|
|
);
|
|
}
|