mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 02:13:48 +00:00
feat: editor layout
This commit is contained in:
committed by
Carlos Valente
parent
967e92e2c8
commit
da02ecd113
@@ -41,5 +41,4 @@
|
||||
|
||||
padding-inline: 0.5em;
|
||||
outline: none;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useMemo } from 'react';
|
||||
import { IoPause, IoPlay, IoPlaySkipBack, IoPlaySkipForward, IoReload, IoStop } from 'react-icons/io5';
|
||||
import { Playback, TimerPhase } from 'ontime-types';
|
||||
import { validatePlayback } from 'ontime-utils';
|
||||
|
||||
import { setPlayback } from '../../../../common/hooks/useSocket';
|
||||
import { getPlaybackControlState } from '../playbackControl.utils';
|
||||
import TapButton from '../tap-button/TapButton';
|
||||
|
||||
import style from './PlaybackButtons.module.scss';
|
||||
@@ -15,44 +14,32 @@ interface PlaybackButtonsProps {
|
||||
timerPhase: TimerPhase;
|
||||
}
|
||||
|
||||
export default function PlaybackButtons(props: PlaybackButtonsProps) {
|
||||
const { playback, numEvents, selectedEventIndex, timerPhase } = props;
|
||||
|
||||
const isRolling = playback === Playback.Roll;
|
||||
const isPlaying = playback === Playback.Play;
|
||||
const isPaused = playback === Playback.Pause;
|
||||
const isArmed = playback === Playback.Armed;
|
||||
|
||||
const isFirst = selectedEventIndex === 0;
|
||||
const isLast = selectedEventIndex === numEvents - 1;
|
||||
const noEvents = numEvents === 0;
|
||||
|
||||
const disableGo = isRolling || noEvents;
|
||||
const disableNext = isRolling || noEvents || isLast;
|
||||
const disablePrev = isRolling || noEvents || isFirst;
|
||||
|
||||
const playbackCan = validatePlayback(playback, timerPhase);
|
||||
const disableStart = !playbackCan.start;
|
||||
const disablePause = !playbackCan.pause;
|
||||
const disableRoll = !playbackCan.roll || noEvents;
|
||||
const disableStop = !playbackCan.stop;
|
||||
const disableReload = !playbackCan.reload;
|
||||
|
||||
const [goModeAction, goModeText] = useMemo(() => {
|
||||
if (isArmed) {
|
||||
return [setPlayback.start, 'Start'];
|
||||
} else if (isLast) {
|
||||
return [setPlayback.stop, 'Finish'];
|
||||
} else if (selectedEventIndex === null) {
|
||||
return [setPlayback.startNext, 'Start'];
|
||||
}
|
||||
return [setPlayback.startNext, 'Next'];
|
||||
}, [isArmed, isLast, selectedEventIndex]);
|
||||
export default function PlaybackButtons({ playback, numEvents, selectedEventIndex, timerPhase }: PlaybackButtonsProps) {
|
||||
const {
|
||||
isPlaying,
|
||||
isPaused,
|
||||
isRolling,
|
||||
disableGo,
|
||||
disableNext,
|
||||
disablePrev,
|
||||
disableStart,
|
||||
disablePause,
|
||||
disableRoll,
|
||||
disableStop,
|
||||
disableReload,
|
||||
goAction,
|
||||
goLabel,
|
||||
} = getPlaybackControlState({
|
||||
playback,
|
||||
numEvents,
|
||||
selectedEventIndex,
|
||||
timerPhase,
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={style.buttonContainer}>
|
||||
<TapButton disabled={disableGo} onClick={goModeAction} aspect='fill' className={style.go}>
|
||||
{goModeText}
|
||||
<TapButton disabled={disableGo} onClick={goAction} aspect='fill' className={style.go}>
|
||||
{goLabel}
|
||||
</TapButton>
|
||||
<div className={style.playbackContainer}>
|
||||
<TapButton onClick={setPlayback.start} disabled={disableStart} theme={Playback.Play} active={isPlaying}>
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
gap: $element-inner-spacing;
|
||||
}
|
||||
|
||||
.timerDisplay {
|
||||
grid-area: timer;
|
||||
max-width: 18.75rem;
|
||||
min-width: 5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
// ---------> INDICATORS
|
||||
|
||||
.indicators {
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function PlaybackTimer({ children }: PropsWithChildren) {
|
||||
<div className={style.indicatorNegative} data-active={isOvertime} />
|
||||
<Tooltip text={addedTimeLabel} render={<div />} className={style.indicatorDelay} data-active={hasAddedTime} />
|
||||
</div>
|
||||
<TimerDisplay time={isWaiting ? timer.secondaryTimer : timer.current} />
|
||||
<TimerDisplay time={isWaiting ? timer.secondaryTimer : timer.current} phase={timer.phase} />
|
||||
<div className={style.status}>
|
||||
{isWaiting ? (
|
||||
<span className={style.rolltag}>Roll: Countdown to start</span>
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { Playback, TimerPhase } from 'ontime-types';
|
||||
import { validatePlayback } from 'ontime-utils';
|
||||
|
||||
import { setPlayback } from '../../../common/hooks/useSocket';
|
||||
|
||||
export interface PlaybackControlInput {
|
||||
playback: Playback;
|
||||
numEvents: number;
|
||||
selectedEventIndex: number | null;
|
||||
timerPhase: TimerPhase;
|
||||
}
|
||||
|
||||
export interface PlaybackControlState {
|
||||
// Playback states
|
||||
isPlaying: boolean;
|
||||
isPaused: boolean;
|
||||
isRolling: boolean;
|
||||
isArmed: boolean;
|
||||
isStopped: boolean;
|
||||
|
||||
// Position states
|
||||
isFirst: boolean;
|
||||
isLast: boolean;
|
||||
noEvents: boolean;
|
||||
|
||||
// Disable flags
|
||||
disableGo: boolean;
|
||||
disableNext: boolean;
|
||||
disablePrev: boolean;
|
||||
disableStart: boolean;
|
||||
disablePause: boolean;
|
||||
disableRoll: boolean;
|
||||
disableStop: boolean;
|
||||
disableReload: boolean;
|
||||
disableAddTime: boolean;
|
||||
|
||||
// Go button configuration
|
||||
goAction: () => void;
|
||||
goLabel: 'Start' | 'Next' | 'Finish';
|
||||
}
|
||||
|
||||
/**
|
||||
* Centralized playback control state calculator.
|
||||
* Consolidates all playback logic, disable states, and derived values in one place.
|
||||
*/
|
||||
export function getPlaybackControlState({
|
||||
playback,
|
||||
numEvents,
|
||||
selectedEventIndex,
|
||||
timerPhase,
|
||||
}: PlaybackControlInput): PlaybackControlState {
|
||||
const isFirst = selectedEventIndex === 0;
|
||||
const isLast = selectedEventIndex === numEvents - 1;
|
||||
const noEvents = numEvents === 0;
|
||||
const isRolling = playback === Playback.Roll;
|
||||
|
||||
const playbackCan = validatePlayback(playback, timerPhase);
|
||||
const { action: goAction, label: goLabel } = getGoAction(playback, selectedEventIndex, isLast);
|
||||
|
||||
return {
|
||||
isPlaying: playback === Playback.Play,
|
||||
isPaused: playback === Playback.Pause,
|
||||
isRolling,
|
||||
isArmed: playback === Playback.Armed,
|
||||
isStopped: playback === Playback.Stop,
|
||||
isFirst,
|
||||
isLast,
|
||||
noEvents,
|
||||
disableGo: isRolling || noEvents,
|
||||
disableNext: isRolling || noEvents || isLast,
|
||||
disablePrev: isRolling || noEvents || isFirst,
|
||||
disableStart: !playbackCan.start,
|
||||
disablePause: !playbackCan.pause,
|
||||
disableRoll: !playbackCan.roll || noEvents,
|
||||
disableStop: !playbackCan.stop,
|
||||
disableReload: !playbackCan.reload,
|
||||
disableAddTime: playback !== Playback.Play && playback !== Playback.Pause,
|
||||
goAction,
|
||||
goLabel,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the action and label for the "Go" button based on playback state.
|
||||
*/
|
||||
function getGoAction(
|
||||
playback: Playback,
|
||||
selectedEventIndex: number | null,
|
||||
isLast: boolean,
|
||||
): { action: () => void; label: 'Start' | 'Next' | 'Finish' } {
|
||||
if (playback === Playback.Armed) return { action: setPlayback.start, label: 'Start' };
|
||||
if (isLast) return { action: setPlayback.stop, label: 'Finish' };
|
||||
if (selectedEventIndex === null) return { action: setPlayback.startNext, label: 'Start' };
|
||||
return { action: setPlayback.startNext, label: 'Next' };
|
||||
}
|
||||
@@ -1,23 +1,34 @@
|
||||
@use '@/theme/viewerDefs' as *;
|
||||
|
||||
.timer {
|
||||
grid-area: timer;
|
||||
white-space: nowrap;
|
||||
max-width: 18.75rem;
|
||||
min-width: 5em;
|
||||
|
||||
color: $timer-color;
|
||||
line-height: 0.9em;
|
||||
text-align: center;
|
||||
line-height: 0.9;
|
||||
letter-spacing: 0.1em;
|
||||
font-weight: 600;
|
||||
font-size: 3.5rem;
|
||||
|
||||
&.finished {
|
||||
color: $timer-finished-color;
|
||||
|
||||
&[data-phase='default'] {
|
||||
color: $timer-color;
|
||||
}
|
||||
|
||||
&.muted {
|
||||
&[data-phase='warning'] {
|
||||
color: $warning-orange;
|
||||
}
|
||||
|
||||
&[data-phase='danger'] {
|
||||
color: $error-red;
|
||||
}
|
||||
|
||||
&[data-phase='overtime'] {
|
||||
color: $playback-negative;
|
||||
}
|
||||
|
||||
&[data-phase='pending'] {
|
||||
color: $ontime-roll;
|
||||
}
|
||||
|
||||
&[data-phase='none'] {
|
||||
color: $muted-gray;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MaybeNumber } from 'ontime-types';
|
||||
import { MaybeNumber, TimerPhase } from 'ontime-types';
|
||||
import { millisToString } from 'ontime-utils';
|
||||
|
||||
import { cx, timerPlaceholder } from '../../../../common/utils/styleUtils';
|
||||
@@ -7,19 +7,20 @@ import style from './TimerDisplay.module.scss';
|
||||
|
||||
interface TimerDisplayProps {
|
||||
time: MaybeNumber;
|
||||
phase: TimerPhase;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays time in ms in formatted timetag
|
||||
* Used in editor
|
||||
*/
|
||||
export default function TimerDisplay(props: TimerDisplayProps) {
|
||||
const { time } = props;
|
||||
export default function TimerDisplay({ time, phase, className }: TimerDisplayProps) {
|
||||
const display = millisToString(time, { fallback: timerPlaceholder }).replace('-', '');
|
||||
|
||||
const isNegative = (time ?? 0) < 0;
|
||||
const display =
|
||||
time == null ? timerPlaceholder : millisToString(time, { fallback: timerPlaceholder }).replace('-', '');
|
||||
const classes = cx([style.timer, isNegative ? style.finished : null, time === null && style.muted]);
|
||||
|
||||
return <div className={classes}>{display}</div>;
|
||||
return (
|
||||
<div className={cx([style.timer, className])} data-phase={phase}>
|
||||
{display}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
@use '../../../../theme/ontimeColours' as *;
|
||||
@use '../../../../theme/ontimeStyles' as *;
|
||||
|
||||
$element-height: 4.5rem; // matches go button height in PlaybackButtons
|
||||
|
||||
.container {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: $panel-gap $section-spacing;
|
||||
background: $bg-container-l2;
|
||||
border-radius: $panel-border-radius;
|
||||
}
|
||||
|
||||
.itemGroup {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: $element-spacing;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.goButton,
|
||||
.iconButtonWithLabel,
|
||||
.iconButton {
|
||||
width: $element-height;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
svg {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.goButton {
|
||||
height: $element-height;
|
||||
min-width: 8rem;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.goLabel {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.shortcutHint {
|
||||
font-size: calc(1rem - 4px);
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.addSection {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.separator {
|
||||
width: 1px;
|
||||
height: 1.5rem;
|
||||
background: $white-10;
|
||||
margin-inline: 0.25rem;
|
||||
}
|
||||
|
||||
.timerSection {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
min-width: 0;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.negativeIndicator {
|
||||
font-size: 2.25rem;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
color: $playback-negative;
|
||||
opacity: 0;
|
||||
|
||||
&[data-active='true'] {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
// -----> Aux timer section (right)
|
||||
|
||||
.auxSection {
|
||||
justify-self: end;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: $element-inner-spacing;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.auxControls {
|
||||
display: flex;
|
||||
gap: $element-inner-spacing;
|
||||
}
|
||||
|
||||
.auxTimeInput,
|
||||
.auxTimeDisplay {
|
||||
width: 6.5rem;
|
||||
min-width: 6.5rem;
|
||||
max-width: 6.5rem;
|
||||
height: $element-height;
|
||||
|
||||
text-align: center;
|
||||
background: $gray-1050;
|
||||
border-radius: $component-border-radius-md;
|
||||
color: $ui-white;
|
||||
}
|
||||
|
||||
.auxTimeDisplay {
|
||||
display: grid;
|
||||
place-content: center;
|
||||
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
color: $gray-200;
|
||||
font-variant-numeric: tabular-nums;
|
||||
letter-spacing: 0.5px;
|
||||
|
||||
padding-inline: 0.5em;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
// hardcoded value where the timer is over the buttons
|
||||
@media (max-width: 1048px) {
|
||||
.container {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
.timerSection {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
.auxSection {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
// hardcoded value where the timer is over the buttons
|
||||
@media (max-width: 728px) {
|
||||
.addSection {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
import { IoAdd, IoArrowDown, IoArrowUp, IoPause, IoPlay, IoPlaySkipForward, IoRemove, IoStop } from 'react-icons/io5';
|
||||
import { useHotkeys, useLocalStorage } from '@mantine/hooks';
|
||||
import { Playback, SimpleDirection, SimplePlayback, TimerPhase } from 'ontime-types';
|
||||
import { millisToString, parseUserTime } from 'ontime-utils';
|
||||
|
||||
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
||||
import {
|
||||
setAuxTimer,
|
||||
setPlayback,
|
||||
useAuxTimerControl,
|
||||
useAuxTimerTime,
|
||||
usePlaybackControl,
|
||||
useTimer,
|
||||
} from '../../../../common/hooks/useSocket';
|
||||
import { enDash } from '../../../../common/utils/styleUtils';
|
||||
import { formatDuration } from '../../../../common/utils/time';
|
||||
import { getPlaybackControlState } from '../playbackControl.utils';
|
||||
import TapButton from '../tap-button/TapButton';
|
||||
import TimerDisplay from '../timer-display/TimerDisplay';
|
||||
|
||||
import style from './TrackingPlaybackBar.module.scss';
|
||||
|
||||
export default function TrackingPlaybackBar() {
|
||||
const timer = useTimer();
|
||||
|
||||
const { playback, numEvents, selectedEventIndex } = usePlaybackControl();
|
||||
|
||||
const { playback: auxPlayback, direction: auxDirection } = useAuxTimerControl(1);
|
||||
const auxTime = useAuxTimerTime(1);
|
||||
|
||||
const [addTimeInMs] = useLocalStorage({ key: 'add-time', defaultValue: 300_000 });
|
||||
|
||||
const { disableGo, disableNext, disableAddTime, isPlaying, goAction, goLabel } = getPlaybackControlState({
|
||||
playback,
|
||||
numEvents,
|
||||
selectedEventIndex,
|
||||
timerPhase: timer.phase,
|
||||
});
|
||||
|
||||
const disableAddTimeWithAmount = disableAddTime || addTimeInMs === 0;
|
||||
|
||||
const handleAddTime = (direction: 'add' | 'remove') => {
|
||||
if (disableAddTimeWithAmount) return;
|
||||
if (direction === 'add') {
|
||||
setPlayback.addTime(addTimeInMs);
|
||||
} else {
|
||||
setPlayback.addTime(-1 * addTimeInMs);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAuxPlayPause = () => {
|
||||
if (auxPlayback === SimplePlayback.Start) {
|
||||
setAuxTimer.pause(1);
|
||||
} else {
|
||||
setAuxTimer.start(1);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAuxStop = () => {
|
||||
setAuxTimer.stop(1);
|
||||
};
|
||||
|
||||
const handleAuxDirectionToggle = () => {
|
||||
const newDirection =
|
||||
auxDirection === SimpleDirection.CountDown ? SimpleDirection.CountUp : SimpleDirection.CountDown;
|
||||
setAuxTimer.setDirection(1, newDirection);
|
||||
};
|
||||
|
||||
const handleAuxTimeChange = (_field: string, value: string) => {
|
||||
const newTimeInMs = parseUserTime(value);
|
||||
setAuxTimer.setDuration(1, newTimeInMs);
|
||||
};
|
||||
|
||||
useHotkeys([
|
||||
['Space', () => !disableGo && goAction(), { preventDefault: true }],
|
||||
['N', () => !disableNext && setPlayback.next(), { preventDefault: true }],
|
||||
['Escape', () => playback !== Playback.Stop && setPlayback.stop(), { preventDefault: true }],
|
||||
]);
|
||||
|
||||
const isWaiting = timer.phase === TimerPhase.Pending;
|
||||
const isOvertime = timer.phase === TimerPhase.Overtime;
|
||||
const displayTime = isWaiting ? timer.secondaryTimer : timer.current;
|
||||
|
||||
const addTimeLabel = formatDuration(addTimeInMs);
|
||||
|
||||
return (
|
||||
<div className={style.container}>
|
||||
<div className={style.itemGroup}>
|
||||
<TapButton
|
||||
onClick={goAction}
|
||||
disabled={disableGo}
|
||||
theme={Playback.Play}
|
||||
active={isPlaying}
|
||||
className={style.goButton}
|
||||
>
|
||||
<span className={style.goLabel}>{goLabel}</span>
|
||||
<span className={style.shortcutHint}>[space]</span>
|
||||
</TapButton>
|
||||
|
||||
<TapButton
|
||||
onClick={setPlayback.next}
|
||||
disabled={disableNext}
|
||||
className={style.iconButtonWithLabel}
|
||||
aspect='square'
|
||||
>
|
||||
<IoPlaySkipForward />
|
||||
<span className={style.shortcutHint}>[n]</span>
|
||||
</TapButton>
|
||||
|
||||
<TapButton
|
||||
onClick={setPlayback.stop}
|
||||
disabled={playback === Playback.Stop}
|
||||
className={style.iconButtonWithLabel}
|
||||
aspect='square'
|
||||
>
|
||||
<IoStop />
|
||||
<span className={style.shortcutHint}>[esc]</span>
|
||||
</TapButton>
|
||||
|
||||
<div className={style.addSection}>
|
||||
<div className={style.separator} />
|
||||
<TapButton
|
||||
onClick={() => handleAddTime('remove')}
|
||||
disabled={disableAddTimeWithAmount}
|
||||
className={style.iconButtonWithLabel}
|
||||
aspect='square'
|
||||
>
|
||||
<IoRemove />
|
||||
{addTimeLabel}
|
||||
</TapButton>
|
||||
<TapButton
|
||||
onClick={() => handleAddTime('add')}
|
||||
disabled={disableAddTimeWithAmount}
|
||||
className={style.iconButtonWithLabel}
|
||||
aspect='square'
|
||||
>
|
||||
<IoAdd />
|
||||
{addTimeLabel}
|
||||
</TapButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={style.timerSection}>
|
||||
<span className={style.negativeIndicator} data-active={isOvertime}>
|
||||
{enDash}
|
||||
</span>
|
||||
<TimerDisplay time={displayTime} phase={timer.phase} />
|
||||
</div>
|
||||
|
||||
<div className={style.auxSection}>
|
||||
<TapButton onClick={handleAuxPlayPause} className={style.iconButton} theme={Playback.Play} aspect='square'>
|
||||
{auxPlayback === SimplePlayback.Start ? <IoPause /> : <IoPlay />}
|
||||
</TapButton>
|
||||
<TapButton
|
||||
onClick={handleAuxStop}
|
||||
disabled={auxPlayback === SimplePlayback.Stop}
|
||||
className={style.iconButton}
|
||||
theme={Playback.Stop}
|
||||
aspect='square'
|
||||
>
|
||||
<IoStop />
|
||||
</TapButton>
|
||||
{auxPlayback !== SimplePlayback.Stop ? (
|
||||
<div className={style.auxTimeDisplay}>{millisToString(auxTime)}</div>
|
||||
) : (
|
||||
<TimeInput
|
||||
name='aux1-tracking'
|
||||
submitHandler={handleAuxTimeChange}
|
||||
time={auxTime}
|
||||
className={style.auxTimeInput}
|
||||
/>
|
||||
)}
|
||||
<TapButton
|
||||
onClick={handleAuxDirectionToggle}
|
||||
disabled={auxPlayback !== SimplePlayback.Stop}
|
||||
className={style.iconButton}
|
||||
aspect='square'
|
||||
>
|
||||
{auxDirection === SimpleDirection.CountDown ? <IoArrowDown /> : <IoArrowUp />}
|
||||
</TapButton>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user