pass data from ssocket

This commit is contained in:
arc-alex
2025-03-20 16:04:44 +01:00
parent 729c68e9e2
commit 7c642f3832
3 changed files with 19 additions and 9 deletions
+4 -1
View File
@@ -172,8 +172,11 @@ export const useTimelineStatus = createSelector((state: RuntimeStore) => ({
export const useTimeUntilData = createSelector((state: RuntimeStore) => ({ export const useTimeUntilData = createSelector((state: RuntimeStore) => ({
clock: state.clock, clock: state.clock,
offset: state.runtime.offset, offset: state.runtime.offsetMode === OffsetMode.Absolute ? state.runtime.offset : state.runtime.relativeOffset,
offsetMode: state.runtime.offsetMode,
currentDay: state.eventNow?.dayOffset ?? 0, //The day of the currently running event currentDay: state.eventNow?.dayOffset ?? 0, //The day of the currently running event
actualStart: state.runtime.actualStart,
plannedStart: state.runtime.plannedStart,
})); }));
export const useRuntimeOffset = createSelector((state: RuntimeStore) => ({ export const useRuntimeOffset = createSelector((state: RuntimeStore) => ({
@@ -54,6 +54,8 @@ describe('calculateTimeUntilStart()', () => {
clock: 90, clock: 90,
offset: 0, offset: 0,
offsetMode: OffsetMode.Absolute, offsetMode: OffsetMode.Absolute,
actualStart: null,
plannedStart: null,
}; };
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(10); expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(10);
@@ -70,6 +72,8 @@ describe('calculateTimeUntilStart()', () => {
clock: 90, clock: 90,
offset: -20, offset: -20,
offsetMode: OffsetMode.Absolute, offsetMode: OffsetMode.Absolute,
actualStart: null,
plannedStart: null,
}; };
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(30); expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(30);
@@ -86,6 +90,8 @@ describe('calculateTimeUntilStart()', () => {
clock: 80, clock: 80,
offset: 10, offset: 10,
offsetMode: OffsetMode.Absolute, offsetMode: OffsetMode.Absolute,
actualStart: null,
plannedStart: null,
}; };
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(20); // <-- when running ahead the unlinked timer stays put expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(20); // <-- when running ahead the unlinked timer stays put
@@ -102,6 +108,8 @@ describe('calculateTimeUntilStart()', () => {
clock: 50, clock: 50,
offset: -20, offset: -20,
offsetMode: OffsetMode.Absolute, offsetMode: OffsetMode.Absolute,
actualStart: null,
plannedStart: null,
}; };
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(50); expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(50);
@@ -118,6 +126,8 @@ describe('calculateTimeUntilStart()', () => {
clock: 50, clock: 50,
offset: -20, offset: -20,
offsetMode: OffsetMode.Absolute, offsetMode: OffsetMode.Absolute,
actualStart: 0,
plannedStart: 0,
}; };
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(60); expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(60);
+5 -8
View File
@@ -138,11 +138,10 @@ export function useTimeUntilStart(
data: Pick<OntimeEvent, 'timeStart' | 'dayOffset' | 'delay'> & { data: Pick<OntimeEvent, 'timeStart' | 'dayOffset' | 'delay'> & {
totalGap: number; totalGap: number;
isLinkedToLoaded: boolean; isLinkedToLoaded: boolean;
offsetMode: OffsetMode;
}, },
): number { ): number {
const { offset, clock, currentDay } = useTimeUntilData(); const { offset, clock, currentDay, offsetMode, actualStart, plannedStart } = useTimeUntilData();
return calculateTimeUntilStart({ ...data, currentDay, clock, offset }); return calculateTimeUntilStart({ ...data, currentDay, clock, offset, offsetMode, actualStart, plannedStart });
} }
/** /**
@@ -162,8 +161,8 @@ export function calculateTimeUntilStart(
clock: number; clock: number;
offset: number; offset: number;
offsetMode: OffsetMode; offsetMode: OffsetMode;
actualStart?: number; actualStart: MaybeNumber;
plannedStart?: number; plannedStart: MaybeNumber;
}, },
): number { ): number {
const { const {
@@ -191,9 +190,7 @@ export function calculateTimeUntilStart(
let relativeStartOffset = 0; let relativeStartOffset = 0;
if (offsetMode === OffsetMode.Relative) { if (offsetMode === OffsetMode.Relative) {
assert(actualStart !== undefined); relativeStartOffset = (actualStart ?? 0) - (plannedStart ?? 0);
assert(plannedStart !== undefined);
relativeStartOffset = actualStart - plannedStart;
} }
const scheduledTimeUntil = normalisedTimeStart - clock + relativeStartOffset; const scheduledTimeUntil = normalisedTimeStart - clock + relativeStartOffset;