refactor: show delayed times

This commit is contained in:
Carlos Valente
2024-12-22 19:57:43 +01:00
committed by Carlos Valente
parent bdd2a62cee
commit 7f39d035fd
6 changed files with 37 additions and 35 deletions
@@ -9,32 +9,23 @@ import style from './DelayIndicator.module.scss';
interface DelayIndicatorProps { interface DelayIndicatorProps {
delayValue?: number; delayValue?: number;
tooltipPrefix?: string;
} }
export default function DelayIndicator(props: DelayIndicatorProps) { export default function DelayIndicator(props: DelayIndicatorProps) {
const { delayValue } = props; const { delayValue, tooltipPrefix } = props;
if (typeof delayValue === 'number') { if (typeof delayValue !== 'number' || delayValue === 0) {
if (delayValue < 0) { return null;
return (
<Tooltip openDelay={tooltipDelayFast} label={millisToDelayString(delayValue)}>
<span className={style.delaySymbol}>
<IoChevronDown />
</span>
</Tooltip>
);
}
if (delayValue > 0) {
return (
<Tooltip openDelay={tooltipDelayFast} label={millisToDelayString(delayValue)}>
<span className={style.delaySymbol}>
<IoChevronUp />
</span>
</Tooltip>
);
}
} }
return null; const delayString = tooltipPrefix
? `${tooltipPrefix} ${millisToDelayString(delayValue)}`
: millisToDelayString(delayValue);
return (
<Tooltip openDelay={tooltipDelayFast} label={delayString}>
<span className={style.delaySymbol}>{delayValue < 0 ? <IoChevronDown /> : <IoChevronUp />}</span>
</Tooltip>
);
} }
@@ -8,8 +8,13 @@
align-items: center; align-items: center;
gap: 0.25rem; gap: 0.25rem;
&.delayed {
color: $ontime-delay-text;
}
&.muted { &.muted {
color: $muted-gray; // we use opacity instead of colour to handle delayed values
opacity: 0.4;
} }
&:hover { &:hover {
@@ -7,12 +7,13 @@ import style from './TextLikeInput.module.scss';
export default memo(TextLikeInput); export default memo(TextLikeInput);
interface TextLikeInputProps extends HTMLAttributes<HTMLSpanElement> { interface TextLikeInputProps extends HTMLAttributes<HTMLSpanElement> {
delayed?: boolean;
muted?: boolean; muted?: boolean;
} }
function TextLikeInput(props: PropsWithChildren<TextLikeInputProps>) { function TextLikeInput(props: PropsWithChildren<TextLikeInputProps>) {
const { muted, children, className, ...elementProps } = props; const { delayed, muted, children, className, ...elementProps } = props;
const classes = cx([style.textInput, muted && style.muted, className]); const classes = cx([style.textInput, delayed && style.delayed, muted && style.muted, className]);
return ( return (
<div className={classes} {...elementProps} tabIndex={0}> <div className={classes} {...elementProps} tabIndex={0}>
{children} {children}
@@ -7,13 +7,14 @@ import TextLikeInput from './TextLikeInput';
interface TimeInputDurationProps { interface TimeInputDurationProps {
initialValue: number; initialValue: number;
lockedValue: boolean; lockedValue: boolean;
delayed?: boolean;
onSubmit: (value: string) => void; onSubmit: (value: string) => void;
} }
export default memo(TimeInputDuration); export default memo(TimeInputDuration);
function TimeInputDuration(props: PropsWithChildren<TimeInputDurationProps>) { function TimeInputDuration(props: PropsWithChildren<TimeInputDurationProps>) {
const { initialValue, lockedValue, onSubmit, children } = props; const { initialValue, lockedValue, delayed, onSubmit, children } = props;
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
const [value, setValue] = useState(initialValue); const [value, setValue] = useState(initialValue);
@@ -81,7 +82,7 @@ function TimeInputDuration(props: PropsWithChildren<TimeInputDurationProps>) {
handleCancelUpdate={handleFakeBlur} handleCancelUpdate={handleFakeBlur}
/> />
) : ( ) : (
<TextLikeInput onClick={handleFakeFocus} onFocus={handleFakeFocus} muted={!lockedValue}> <TextLikeInput onClick={handleFakeFocus} onFocus={handleFakeFocus} muted={!lockedValue} delayed={delayed}>
{children} {children}
</TextLikeInput> </TextLikeInput>
); );
@@ -24,15 +24,16 @@ function MakeStart({ getValue, row, table }: CellContext<OntimeRundownEntry, unk
const isStartLocked = (row.original as OntimeEvent).linkStart === null; const isStartLocked = (row.original as OntimeEvent).linkStart === null;
const delayValue = (row.original as OntimeEvent)?.delay ?? 0; const delayValue = (row.original as OntimeEvent)?.delay ?? 0;
let formattedTime = millisToString(startTime); const displayTime = showDelayedTimes ? startTime + delayValue : startTime;
let formattedTime = millisToString(displayTime);
if (hideTableSeconds) { if (hideTableSeconds) {
formattedTime = removeSeconds(formattedTime); formattedTime = removeSeconds(formattedTime);
} }
return ( return (
<TimeInput initialValue={startTime} onSubmit={update} lockedValue={isStartLocked}> <TimeInput initialValue={startTime} onSubmit={update} lockedValue={isStartLocked} delayed={delayValue !== 0}>
{formattedTime} {formattedTime}
{delayValue !== 0 && showDelayedTimes && <DelayIndicator delayValue={delayValue} />} <DelayIndicator delayValue={delayValue} tooltipPrefix={millisToString(startTime)} />
</TimeInput> </TimeInput>
); );
} }
@@ -43,21 +44,24 @@ function MakeEnd({ getValue, row, table }: CellContext<OntimeRundownEntry, unkno
} }
const { handleUpdateTimer } = table.options.meta; const { handleUpdateTimer } = table.options.meta;
const { hideTableSeconds } = table.options.meta.options; const { showDelayedTimes, hideTableSeconds } = table.options.meta.options;
const update = (newValue: string) => handleUpdateTimer(row.original.id, 'timeEnd', newValue); const update = (newValue: string) => handleUpdateTimer(row.original.id, 'timeEnd', newValue);
const endTime = getValue() as number; const endTime = getValue() as number;
const isEndLocked = (row.original as OntimeEvent).timeStrategy === TimeStrategy.LockEnd; const isEndLocked = (row.original as OntimeEvent).timeStrategy === TimeStrategy.LockEnd;
const delayValue = (row.original as OntimeEvent)?.delay ?? 0;
let formattedTime = millisToString(endTime); const displayTime = showDelayedTimes ? endTime + delayValue : endTime;
let formattedTime = millisToString(displayTime);
if (hideTableSeconds) { if (hideTableSeconds) {
formattedTime = removeSeconds(formattedTime); formattedTime = removeSeconds(formattedTime);
} }
return ( return (
<TimeInput initialValue={endTime} onSubmit={update} lockedValue={isEndLocked}> <TimeInput initialValue={endTime} onSubmit={update} lockedValue={isEndLocked} delayed={delayValue !== 0}>
{formattedTime} {formattedTime}
<DelayIndicator delayValue={delayValue} tooltipPrefix={millisToString(endTime)} />
</TimeInput> </TimeInput>
); );
} }