refactor: cleanup store (#727)

* refactor: isolate clock

* refactor: isolate private

* refactor: remove duplicate

* chore: rename loaded > runtime

* fix: handle no events loaded
This commit is contained in:
Carlos Valente
2024-01-24 00:20:10 +01:00
committed by GitHub
parent 0cd2ca4191
commit b4ad533e6a
31 changed files with 411 additions and 384 deletions
@@ -30,8 +30,8 @@ interface OperatorEventProps {
// extract this to contain re-renders
function RollingTime() {
const timer = useTimer();
return <RunningTime value={timer.current} />;
const { current } = useTimer();
return <RunningTime value={current} />;
}
function OperatorEvent(props: OperatorEventProps) {
@@ -1,7 +1,7 @@
import { ViewSettings } from 'ontime-types';
import MultiPartProgressBar from '../../../common/components/multi-part-progress-bar/MultiPartProgressBar';
import { useTimer } from '../../../common/hooks/useSocket';
import { useProgressData } from '../../../common/hooks/useSocket';
import styles from './StatusBar.module.scss';
@@ -11,18 +11,17 @@ interface StatusBarProgressProps {
export default function StatusBarProgress(props: StatusBarProgressProps) {
const { viewSettings } = props;
const timer = useTimer();
const totalTime = (timer.duration ?? 0) + (timer.addedTime ?? 0);
const { addedTime, current, duration, timeWarning, timeDanger } = useProgressData();
const totalTime = (duration ?? 0) + (addedTime ?? 0);
return (
<MultiPartProgressBar
now={timer.current}
now={current}
complete={totalTime}
normalColor={viewSettings.normalColor}
warning={timer?.timeWarning}
warning={timeWarning}
warningColor={viewSettings.warningColor}
danger={timer?.timeDanger}
danger={timeDanger}
dangerColor={viewSettings.dangerColor}
className={styles.progressOverride}
/>
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { MaybeNumber, Playback } from 'ontime-types';
import PlaybackIcon from '../../../common/components/playback-icon/PlaybackIcon';
import { useTimer } from '../../../common/hooks/useSocket';
import { useClock, useTimer } from '../../../common/hooks/useSocket';
import { cx } from '../../../common/utils/styleUtils';
import ClockTime from '../../viewers/common/clock-time/ClockTime';
import RunningTime from '../../viewers/common/running-time/RunningTime';
@@ -23,6 +23,7 @@ export default function StatusBarTimers(props: StatusBarTimersProps) {
const { projectTitle, playback, selectedEventId, firstStart, firstId, lastEnd, lastId } = props;
const timer = useTimer();
const { clock } = useClock();
const getTimeStart = (): MaybeNumber => {
if (firstStart === undefined) {
@@ -61,7 +62,7 @@ export default function StatusBarTimers(props: StatusBarTimersProps) {
{PlaybackIconComponent}
<div className={styles.timeNow}>
<span className={styles.label}>Time now</span>
<ClockTime className={styles.timer} value={timer.clock} />
<ClockTime className={styles.timer} value={clock} />
</div>
<div className={styles.elapsedTime}>
<span className={styles.label}>Elapsed time</span>