Skip to content

Commit

Permalink
Merge pull request #1 from nav800/647-fix-nav800
Browse files Browse the repository at this point in the history
Fix: Default Colors deplete too Rapidly
  • Loading branch information
nav800 authored Sep 30, 2024
2 parents 559b615 + a647adc commit bcc3b36
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions apps/antalmanac/src/stores/scheduleHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,19 @@ export function getColorForNewSection(newSection: ScheduleCourse, sectionsInSche
// If the same courseTitle exists, but not the same sectionType, return a close color
if (existingSections.length > 0) return generateCloseColor(existingSections[0].section.color, usedColors);

// If there are no existing sections with the same course title, generate a new color. If we run out of unique colors, return a random one that's been used already.
return (
defaultColors.find((materialColor) => !usedColors.has(materialColor)) ||
defaultColors[Math.floor(Math.random() * defaultColors.length)]
);
// If there are no existing sections with the same course title, generate a new color.
// If we run out of unique colors, reuse the earliest assigned default color, treating it as an unused color.

let unusedColor: defaultColors.find((materialColor) => !usedColors.has(materialColor));
if (!unusedColor) return unusedColor;

for (const usedColor of usedColors) {
if (usedColor in defaultColors) {
usedColors.delete(usedColor);
break;
}
}

return defaultColors.find((materialColor) => !usedColors.has(materialColor));

}

0 comments on commit bcc3b36

Please sign in to comment.