From 1ec97cfac72b752ad07f789c50205a1d5881d431 Mon Sep 17 00:00:00 2001 From: Mikkel ALMONTE--RINGAUD Date: Sat, 13 Jul 2024 00:11:02 +0200 Subject: [PATCH] fix(timetable): handle each week separately could cause issues when requesting multiple weeks at once --- src/parser/timetable.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/parser/timetable.ts b/src/parser/timetable.ts index 096533f..f670842 100644 --- a/src/parser/timetable.ts +++ b/src/parser/timetable.ts @@ -107,15 +107,14 @@ export class TimetableOverview { } #getSuperimposedClassesIndexes( - classes: TimetableClass[], + classItem: TimetableClass, classIndex: number, busyPositions: number[] ) { - const classFromIndex = classes[classIndex]; const classesSuperimposed = [classIndex]; - const startBlockPosition = classFromIndex.blockPosition; - const endBlockPosition = this.#getClassEndBlockPosition(classFromIndex); + const startBlockPosition = classItem.blockPosition; + const endBlockPosition = this.#getClassEndBlockPosition(classItem); for (let currentBlockPosition = startBlockPosition; currentBlockPosition <= endBlockPosition; currentBlockPosition++) { const busyClassIndex = busyPositions[currentBlockPosition]; @@ -132,11 +131,15 @@ export class TimetableOverview { } #makeSuperimposedCanceledClassesInvisible (classes: TimetableClassWithVisible[]): boolean { - const busyPositions: number[] = []; + /** key = week number, value */ + const busyPositionsPerWeek: Record = {}; for (let classIndex = 0; classIndex < classes.length; classIndex++) { const currentClass = classes[classIndex]; + if (!(currentClass.weekNumber in busyPositionsPerWeek)) busyPositionsPerWeek[currentClass.weekNumber] = []; + const busyPositions = busyPositionsPerWeek[currentClass.weekNumber]; + const startBlockPosition = currentClass.blockPosition; const endBlockPosition = this.#getClassEndBlockPosition(currentClass); @@ -147,7 +150,7 @@ export class TimetableOverview { } else { const superimposedClassesIndexes = this.#getSuperimposedClassesIndexes( - classes, + currentClass, classIndex, busyPositions );