refactor: improve fallback timer consistency

This commit is contained in:
Carlos Valente
2024-12-20 13:30:11 +01:00
committed by Carlos Valente
parent 3d37f42fe0
commit 1061ed2a0e
6 changed files with 67 additions and 16 deletions
@@ -16,4 +16,8 @@
&.finished { &.finished {
color: $timer-finished-color; color: $timer-finished-color;
} }
&.muted {
color: $muted-gray;
}
} }
@@ -19,7 +19,7 @@ export default function TimerDisplay(props: TimerDisplayProps) {
const isNegative = (time ?? 0) < 0; const isNegative = (time ?? 0) < 0;
const display = const display =
time == null ? timerPlaceholder : millisToString(time, { fallback: timerPlaceholder }).replace('-', ''); time == null ? timerPlaceholder : millisToString(time, { fallback: timerPlaceholder }).replace('-', '');
const classes = cx([style.timer, isNegative ? style.finished : null]); const classes = cx([style.timer, isNegative ? style.finished : null, time === null && style.muted]);
return <div className={classes}>{display}</div>; return <div className={classes}>{display}</div>;
} }
+51 -10
View File
@@ -4,7 +4,7 @@ import { millisToString } from 'ontime-utils';
import ErrorBoundary from '../../common/components/error-boundary/ErrorBoundary'; import ErrorBoundary from '../../common/components/error-boundary/ErrorBoundary';
import { useIsOnline, useRuntimeOverview, useRuntimePlaybackOverview, useTimer } from '../../common/hooks/useSocket'; import { useIsOnline, useRuntimeOverview, useRuntimePlaybackOverview, useTimer } from '../../common/hooks/useSocket';
import useProjectData from '../../common/hooks-query/useProjectData'; import useProjectData from '../../common/hooks-query/useProjectData';
import { cx, enDash } from '../../common/utils/styleUtils'; import { cx, enDash, timerPlaceholder } from '../../common/utils/styleUtils';
import { TimeColumn, TimeRow } from './composite/TimeLayout'; import { TimeColumn, TimeRow } from './composite/TimeLayout';
import { calculateEndAndDaySpan, formatedTime, getOffsetText } from './overviewUtils'; import { calculateEndAndDaySpan, formatedTime, getOffsetText } from './overviewUtils';
@@ -26,15 +26,37 @@ function _EditorOverview({ children }: PropsWithChildren) {
<OverviewWrapper navElements={children}> <OverviewWrapper navElements={children}>
<TitlesOverview /> <TitlesOverview />
<div> <div>
<TimeRow label='Planned start' value={formatedTime(plannedStart)} className={style.start} /> <TimeRow
<TimeRow label='Actual start' value={formatedTime(actualStart)} className={style.start} /> label='Planned start'
value={formatedTime(plannedStart)}
className={style.start}
muted={plannedStart === null}
/>
<TimeRow
label='Actual start'
value={formatedTime(actualStart)}
className={style.start}
muted={actualStart === null}
/>
</div> </div>
<ProgressOverview /> <ProgressOverview />
<CurrentBlockOverview /> <CurrentBlockOverview />
<RuntimeOverview /> <RuntimeOverview />
<div> <div>
<TimeRow label='Planned end' value={plannedEndText} className={style.end} daySpan={maybePlannedDaySpan} /> <TimeRow
<TimeRow label='Expected end' value={expectedEndText} className={style.end} daySpan={maybeExpectedDaySpan} /> label='Planned end'
value={plannedEndText}
className={style.end}
daySpan={maybePlannedDaySpan}
muted={maybePlannedEnd === null}
/>
<TimeRow
label='Expected end'
value={expectedEndText}
className={style.end}
daySpan={maybeExpectedDaySpan}
muted={maybeExpectedEnd === null}
/>
</div> </div>
</OverviewWrapper> </OverviewWrapper>
); );
@@ -57,8 +79,20 @@ function _CuesheetOverview({ children }: PropsWithChildren) {
<TimerOverview /> <TimerOverview />
<RuntimeOverview /> <RuntimeOverview />
<div> <div>
<TimeRow label='Planned end' value={plannedEndText} className={style.end} daySpan={maybePlannedDaySpan} /> <TimeRow
<TimeRow label='Expected end' value={expectedEndText} className={style.end} daySpan={maybeExpectedDaySpan} /> label='Planned end'
value={plannedEndText}
className={style.end}
daySpan={maybePlannedDaySpan}
muted={maybePlannedEnd === null}
/>
<TimeRow
label='Expected end'
value={expectedEndText}
className={style.end}
daySpan={maybeExpectedDaySpan}
muted={maybeExpectedEnd === null}
/>
</div> </div>
</OverviewWrapper> </OverviewWrapper>
); );
@@ -100,15 +134,22 @@ function CurrentBlockOverview() {
const timeInBlock = formatedTime(currentBlock.startedAt === null ? null : clock - currentBlock.startedAt); const timeInBlock = formatedTime(currentBlock.startedAt === null ? null : clock - currentBlock.startedAt);
return <TimeColumn label='Time in block' value={timeInBlock} className={style.clock} />; return (
<TimeColumn
label='Time in block'
value={timeInBlock}
className={style.clock}
muted={currentBlock.startedAt === null}
/>
);
} }
function TimerOverview() { function TimerOverview() {
const { current } = useTimer(); const { current } = useTimer();
const display = millisToString(current); const display = millisToString(current, { fallback: timerPlaceholder });
return <TimeColumn label='Running timer' value={display} />; return <TimeColumn label='Running timer' value={display} muted={current === null} />;
} }
function ProgressOverview() { function ProgressOverview() {
@@ -44,6 +44,10 @@
content: "*"; content: "*";
vertical-align: super; vertical-align: super;
font-size: 0.75em; font-size: 0.75em;
color: $blue-500; color: $info-blue;
} }
} }
.muted {
color: $muted-gray;
}
@@ -7,20 +7,21 @@ import style from './TimeLayout.module.scss';
interface TimeLayoutProps { interface TimeLayoutProps {
label: string; label: string;
value: string; value: string;
muted?: boolean;
daySpan?: number; daySpan?: number;
className?: string; className?: string;
} }
export function TimeColumn({ label, value, className }: TimeLayoutProps) { export function TimeColumn({ label, value, muted, className }: TimeLayoutProps) {
return ( return (
<div className={style.column}> <div className={style.column}>
<span className={style.label}>{label}</span> <span className={style.label}>{label}</span>
<span className={cx([style.clock, className])}>{value}</span> <span className={cx([style.clock, muted && style.muted, className])}>{value}</span>
</div> </div>
); );
} }
export function TimeRow({ label, value, daySpan, className }: TimeLayoutProps) { export function TimeRow({ label, value, daySpan, muted, className }: TimeLayoutProps) {
return ( return (
<div className={style.row}> <div className={style.row}>
<span className={style.label}>{label}</span> <span className={style.label}>{label}</span>
@@ -29,7 +30,7 @@ export function TimeRow({ label, value, daySpan, className }: TimeLayoutProps) {
<span className={cx([style.clock, style.daySpan, className])}>{value}</span> <span className={cx([style.clock, style.daySpan, className])}>{value}</span>
</Tooltip> </Tooltip>
) : ( ) : (
<span className={cx([style.clock, className])}>{value}</span> <span className={cx([style.clock, muted && style.muted, className])}>{value}</span>
)} )}
</div> </div>
); );
+1
View File
@@ -52,6 +52,7 @@ $main-spacing: 2rem;
$ontime-font-family: "Open Sans", "Segoe UI", sans-serif; $ontime-font-family: "Open Sans", "Segoe UI", sans-serif;
$label-gray: $gray-400; $label-gray: $gray-400;
$secondary-text-gray: $gray-400; $secondary-text-gray: $gray-400;
$muted-gray: $gray-600;
$section-white: $ui-white; $section-white: $ui-white;
$inner-section-text-size: calc(1rem - 2px); $inner-section-text-size: calc(1rem - 2px);
$text-body-size: calc(1rem - 1px); $text-body-size: calc(1rem - 1px);