diff --git a/apps/client/src/views/common/schedule/ScheduleContext.tsx b/apps/client/src/views/common/schedule/ScheduleContext.tsx index 7359b16a2..c260c1958 100644 --- a/apps/client/src/views/common/schedule/ScheduleContext.tsx +++ b/apps/client/src/views/common/schedule/ScheduleContext.tsx @@ -7,6 +7,7 @@ import { useCallback, useEffect, useLayoutEffect, + useMemo, useRef, useState, } from 'react'; @@ -140,25 +141,23 @@ export const ScheduleProvider = ({ children, selectedEventId }: PropsWithChildre return () => clearInterval(paginator.current); }, [cycleInterval, numPages, stopCycle, visiblePage]); - let selectedEventIndex = events.findIndex((event) => event.id === selectedEventId); - // we want to show the event after the current - const viewEvents = events.slice(selectedEventIndex + 1); - selectedEventIndex = 0; + const viewEvents = useMemo(() => { + const selectedEventIndex = events.findIndex((event) => event.id === selectedEventId); + return (events as ExtendedEntry[]).slice(selectedEventIndex + 1); + }, [events, selectedEventId]); - return ( - [], - selectedEventId, - numPages, - visiblePage, - containerRef, - }} - > - {children} - - ); + const value = useMemo(() => { + return { + events: viewEvents, + selectedEventId, + numPages, + visiblePage, + containerRef, + }; + }, [viewEvents, selectedEventId, numPages, visiblePage, containerRef]); + + return {children}; }; export const useSchedule = () => { diff --git a/apps/client/src/views/cuesheet/__tests__/cuesheet.utils.test.ts b/apps/client/src/views/cuesheet/__tests__/cuesheet.utils.test.ts deleted file mode 100644 index cd54fe9f5..000000000 --- a/apps/client/src/views/cuesheet/__tests__/cuesheet.utils.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { parseField } from '../cuesheet.utils'; - -describe('parseField()', () => { - it('returns a string from given millis on timeStart, TimeEnd and duration', () => { - const testData1 = 1000; - const testData2 = 60000; - const testData3 = 600000; - expect(parseField('timeStart', testData1)).toBe('00:00:01'); - expect(parseField('timeEnd', testData2)).toBe('00:01:00'); - expect(parseField('duration', testData3)).toBe('00:10:00'); - }); - - it('returns an empty string on undefined fields', () => { - // @ts-expect-error -- testing user data with missing fields - expect(parseField('title')).toBe(''); - }); - - describe('simply returns any other value in any other field', () => { - const testFields = [ - { field: 'nothing', value: '123' }, - { field: 'title', value: 'test' }, - { field: 'note', value: 'test' }, - { field: 'colour', value: 'test' }, - ]; - - testFields.forEach((testCase) => { - test(`${testCase.field}:${testCase.value}`, () => { - expect(parseField(testCase.field, testCase.value)).toBe(testCase.value); - }); - }); - }); -}); diff --git a/apps/client/src/views/cuesheet/cuesheet.utils.ts b/apps/client/src/views/cuesheet/cuesheet.utils.ts deleted file mode 100644 index b2b200021..000000000 --- a/apps/client/src/views/cuesheet/cuesheet.utils.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CustomFields, MaybeNumber, OntimeEntryCommonKeys } from 'ontime-types'; -import { millisToString } from 'ontime-utils'; - -type CsvHeaderKey = OntimeEntryCommonKeys | keyof CustomFields; - -/** - * @description parses a field for export - * @param {string} field - * @param {*} data - * @return {string} - */ - -export const parseField = (field: CsvHeaderKey, data: unknown): string => { - if (field === 'timeStart' || field === 'timeEnd' || field === 'duration') { - return millisToString(data as MaybeNumber, { fallback: '' }); - } - - if (field === 'skip') { - return data ? 'x' : ''; - } - - return String(data ?? ''); -};