diff --git a/apps/server/src/services/timerUtils.ts b/apps/server/src/services/timerUtils.ts index 114236b08..dde94e466 100644 --- a/apps/server/src/services/timerUtils.ts +++ b/apps/server/src/services/timerUtils.ts @@ -1,5 +1,5 @@ import { MaybeNumber, MaybeString, OntimeEvent, TimerType } from 'ontime-types'; -import { dayInMs, sortArrayByProperty } from 'ontime-utils'; +import { dayInMs } from 'ontime-utils'; import { RuntimeState } from '../stores/runtimeState.js'; import { timerConfig } from '../config/config.js'; @@ -129,8 +129,7 @@ export const getRollTimers = (rundown: OntimeEvent[], timeNow: number): RollTime let timeToNext: number | null = null; // counter: time for next event let publicTimeToNext: number | null = null; // counter: time for next public event - const orderedEvents = sortArrayByProperty(rundown, 'timeStart'); - const lastEvent = orderedEvents[orderedEvents.length - 1]; + const lastEvent = rundown[rundown.length - 1]; const lastNormalEnd = normaliseEndTime(lastEvent.timeStart, lastEvent.timeEnd); let nextEvent: OntimeEvent | null = null; @@ -142,7 +141,7 @@ export const getRollTimers = (rundown: OntimeEvent[], timeNow: number): RollTime // we are past last end // preload first and find next - const firstEvent = orderedEvents[0]; + const firstEvent = rundown[0]; nextIndex = 0; nextEvent = firstEvent; timeToNext = firstEvent.timeStart + dayInMs - timeNow; @@ -154,7 +153,7 @@ export const getRollTimers = (rundown: OntimeEvent[], timeNow: number): RollTime // look for next public // dev note: we feel that this is more efficient than filtering // since the next event will likely be close to the one playing - for (const event of orderedEvents) { + for (const event of rundown) { if (event.isPublic) { nextPublicEvent = event; // we need the index before this was sorted @@ -169,7 +168,7 @@ export const getRollTimers = (rundown: OntimeEvent[], timeNow: number): RollTime // keep track of the end times when looking for public let publicTime = -1; - for (const event of orderedEvents) { + for (const event of rundown) { // When does the event end (handle midnight) const normalEnd = normaliseEndTime(event.timeStart, event.timeEnd); diff --git a/packages/utils/index.ts b/packages/utils/index.ts index ff1c08060..fd75a4356 100644 --- a/packages/utils/index.ts +++ b/packages/utils/index.ts @@ -52,7 +52,7 @@ export { dayInMs, mts } from './src/timeConstants.js'; export { deepmerge } from './src/externals/deepmerge.js'; // array utils -export { deleteAtIndex, insertAtIndex, reorderArray, sortArrayByProperty } from './src/array-utils/arrayUtils.js'; +export { deleteAtIndex, insertAtIndex, reorderArray } from './src/array-utils/arrayUtils.js'; // generic utilities export { getErrorMessage } from './src/generic/generic.js'; diff --git a/packages/utils/src/array-utils/arrayUtils.test.ts b/packages/utils/src/array-utils/arrayUtils.test.ts index bfb363344..e8397d06d 100644 --- a/packages/utils/src/array-utils/arrayUtils.test.ts +++ b/packages/utils/src/array-utils/arrayUtils.test.ts @@ -1,4 +1,4 @@ -import { insertAtIndex, reorderArray, sortArrayByProperty } from './arrayUtils.js'; +import { insertAtIndex, reorderArray } from './arrayUtils.js'; describe('insertAtIndex', () => { it('should insert an item at the beginning of the array', () => { @@ -52,37 +52,3 @@ describe('reorderArray', () => { expect(result).toEqual(['b', 'c', 'a']); }); }); - -describe('sortArrayByProperty()', () => { - it('sort array 1-5', () => { - const arr1 = [{ timeStart: 1 }, { timeStart: 5 }, { timeStart: 3 }, { timeStart: 2 }, { timeStart: 4 }]; - - const arr1Expected = [{ timeStart: 1 }, { timeStart: 2 }, { timeStart: 3 }, { timeStart: 4 }, { timeStart: 5 }]; - - const sorted = sortArrayByProperty(arr1, 'timeStart'); - expect(sorted).toStrictEqual(arr1Expected); - }); - - it('sort array 1-5 with null', () => { - const arr1 = [ - { timeStart: 1 }, - { timeStart: 5 }, - { timeStart: 3 }, - { timeStart: 2 }, - { timeStart: 4 }, - { timeStart: null }, - ]; - - const arr1Expected = [ - { timeStart: null }, - { timeStart: 1 }, - { timeStart: 2 }, - { timeStart: 3 }, - { timeStart: 4 }, - { timeStart: 5 }, - ]; - - const sorted = sortArrayByProperty(arr1, 'timeStart'); - expect(sorted).toStrictEqual(arr1Expected); - }); -}); diff --git a/packages/utils/src/array-utils/arrayUtils.ts b/packages/utils/src/array-utils/arrayUtils.ts index 1f42a230e..49cb8780a 100644 --- a/packages/utils/src/array-utils/arrayUtils.ts +++ b/packages/utils/src/array-utils/arrayUtils.ts @@ -48,18 +48,3 @@ export function reorderArray(array: T[], fromIndex: number, toIndex: number) modifiedArray.splice(toIndex, 0, reorderedItem); return modifiedArray; } - -/** - * @description Sorts an array of objects by given property - * @param {array} arr - array to be sorted - * @param {string} property - property to compare - * @returns {array} copy of array sorted in ascending order - */ - -export const sortArrayByProperty = (arr: T[], property: string): T[] => { - return [...arr].sort((a, b) => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore -- its ok - return a[property] - b[property]; - }); -};