Skip to content

Commit

Permalink
refactor: show projected time
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Feb 18, 2025
1 parent f63c476 commit 24954fc
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 23 deletions.
4 changes: 4 additions & 0 deletions apps/client/src/common/hooks/useSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export const useTimelineStatus = createSelector((state: RuntimeStore) => ({
offset: state.runtime.offset,
}));

export const useRuntimeOffset = createSelector((state: RuntimeStore) => ({
offset: state.runtime.offset,
}));

export const usePing = createSelector((state: RuntimeStore) => ({
ping: state.ping,
}));
Expand Down
8 changes: 8 additions & 0 deletions apps/client/src/views/common/schedule/Schedule.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ $indeterminate-width: clamp(32px, 3vw, 48px);
&--delay {
color: $ontime-delay-text;
}

&--ahead {
color: $green-500;
}

&--behind {
color: $orange-500;
}
}

.entry-title {
Expand Down
118 changes: 95 additions & 23 deletions apps/client/src/views/common/schedule/ScheduleItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useRuntimeOffset } from '../../../common/hooks/useSocket';
import { cx } from '../../../common/utils/styleUtils';
import { formatTime } from '../../../common/utils/time';
import SuperscriptTime from '../../../features/viewers/common/superscript-time/SuperscriptTime';

import { useScheduleOptions } from './schedule.options';

import './Schedule.scss';

const formatOptions = {
Expand All @@ -21,36 +24,38 @@ interface ScheduleItemProps {

export default function ScheduleItem(props: ScheduleItemProps) {
const { timeStart, timeEnd, title, backstageEvent, colour, skip, delay } = props;
const { showProjected } = useScheduleOptions();

const start = formatTime(timeStart, formatOptions);
const end = formatTime(timeEnd, formatOptions);
if (showProjected) {
return (
<ProjectedScheduleItem
timeStart={timeStart}
timeEnd={timeEnd}
title={title}
colour={colour}
backstageEvent={backstageEvent}
skip={skip}
delay={delay}
/>
);
}

if (delay > 0) {
const delayedStart = formatTime(timeStart + delay, formatOptions);
const delayedEnd = formatTime(timeEnd + delay, formatOptions);

return (
<li className={cx(['entry', skip && 'entry--skip'])}>
<div className='entry-times'>
<span className='entry-times--delayed'>
<span className='entry-colour' style={{ backgroundColor: colour }} />
<SuperscriptTime time={start} />
<SuperscriptTime time={end} />
{backstageEvent && '*'}
</span>
<span className='entry-times--delay'>
<SuperscriptTime time={delayedStart} />
<SuperscriptTime time={delayedEnd} />
{backstageEvent && '*'}
</span>
</div>
<div className='entry-title'>{title}</div>
</li>
<DelayedScheduleItem
timeStart={timeStart}
timeEnd={timeEnd}
title={title}
colour={colour}
backstageEvent={backstageEvent}
skip={skip}
delay={delay}
/>
);
}

const start = formatTime(timeStart, formatOptions);
const end = formatTime(timeEnd, formatOptions);
return (
<li className={cx(['entry', skip && 'entry--skip'])}>
<div className='entry-times'>
Expand All @@ -64,3 +69,70 @@ export default function ScheduleItem(props: ScheduleItemProps) {
</li>
);
}

function DelayedScheduleItem(props: ScheduleItemProps) {
const { timeStart, timeEnd, title, backstageEvent, colour, skip, delay } = props;

const start = formatTime(timeStart, formatOptions);
const end = formatTime(timeEnd, formatOptions);
const delayedStart = formatTime(timeStart + delay, formatOptions);
const delayedEnd = formatTime(timeEnd + delay, formatOptions);

return (
<li className={cx(['entry', skip && 'entry--skip'])}>
<div className='entry-times'>
<span className='entry-times--delayed'>
<span className='entry-colour' style={{ backgroundColor: colour }} />
<SuperscriptTime time={start} />
<SuperscriptTime time={end} />
{backstageEvent && '*'}
</span>
<span className='entry-times--delay'>
<SuperscriptTime time={delayedStart} />
<SuperscriptTime time={delayedEnd} />
{backstageEvent && '*'}
</span>
</div>
<div className='entry-title'>{title}</div>
</li>
);
}

function ProjectedScheduleItem(props: ScheduleItemProps) {
const { timeStart, timeEnd, title, backstageEvent, colour, skip, delay } = props;

return (
<li className={cx(['entry', skip && 'entry--skip'])}>
<div className='entry-times'>
<span className='entry-colour' style={{ backgroundColor: colour }} />
<ProjectedTime time={timeStart} delay={delay} />
<ProjectedTime time={timeEnd} delay={delay} />
{backstageEvent && '*'}
</div>
<div className='entry-title'>{title}</div>
</li>
);
}

interface OffsetTimeProps {
time: number;
delay: number;
}

function ProjectedTime(props: OffsetTimeProps) {
const { time, delay } = props;
const { offset } = useRuntimeOffset();

const projectedOffset = offset - delay;
const projectedTime = formatTime(time - offset, formatOptions);

return (
<SuperscriptTime
className={cx([projectedOffset > 0 && 'entry-times--ahead', projectedOffset < 0 && 'entry-times--behind'])}
time={projectedTime}
/>
);
}
9 changes: 9 additions & 0 deletions apps/client/src/views/common/schedule/schedule.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ export const scheduleOptions: ViewOption = {
type: 'number',
defaultValue: 10,
},
{
id: 'showProjected',
title: 'Show projected time',
description: 'Whether scheduled times should account for runtime offset.',
type: 'boolean',
defaultValue: false,
},
],
};

type ScheduleOptions = {
cycleInterval: number;
stopCycle: boolean;
showProjected: boolean;
};

function getScheduleOptionsFromParams(searchParams: URLSearchParams): ScheduleOptions {
return {
cycleInterval: Number(searchParams.get('cycleInterval')) || 10,
stopCycle: isStringBoolean(searchParams.get('stopCycle')),
showProjected: isStringBoolean(searchParams.get('showProjected')),
};
}

Expand Down

0 comments on commit 24954fc

Please sign in to comment.