Skip to content

Commit

Permalink
fix(timetable): handle each week separately
Browse files Browse the repository at this point in the history
could cause issues when requesting multiple weeks at once
  • Loading branch information
Vexcited committed Jul 12, 2024
1 parent 040038c commit 1ec97cf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/parser/timetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -132,11 +131,15 @@ export class TimetableOverview {
}

#makeSuperimposedCanceledClassesInvisible (classes: TimetableClassWithVisible[]): boolean {
const busyPositions: number[] = [];
/** key = week number, value */
const busyPositionsPerWeek: Record<number, number[]> = {};

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);

Expand All @@ -147,7 +150,7 @@ export class TimetableOverview {
}
else {
const superimposedClassesIndexes = this.#getSuperimposedClassesIndexes(
classes,
currentClass,
classIndex,
busyPositions
);
Expand Down

0 comments on commit 1ec97cf

Please sign in to comment.