Skip to content

Commit 605b1e9

Browse files
authored
Add latest quarter filter (#323)
Resolves #322
1 parent ab3dcd5 commit 605b1e9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/components/PEClassTable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ function ClassInput(props: {
204204
const filtersNonFlags = {
205205
fits: (state, cls) => state.fitsSchedule(cls),
206206
starred: (state, cls) => state.isPEClassStarred(cls),
207+
latest: (state, cls) => cls.rawClass.quarter === state.latestQuarter,
207208
} satisfies Record<string, (state: State, cls: PEClass) => boolean>;
208209

209210
type Filter = keyof PEFlags | keyof typeof filtersNonFlags;
@@ -212,6 +213,7 @@ type FilterGroup = [Filter, string, ReactNode?][];
212213
/** List of top filter IDs and their displayed names. */
213214
const CLASS_FLAGS_1: FilterGroup = [
214215
["starred", "Starred", <LuStar fill="currentColor" />],
216+
["latest", "Latest quarter"],
215217
["nofee", "No fee"],
216218
["nopreq", "No prereq"],
217219
["fits", "Fits schedule"],

src/lib/state.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,31 @@ export class State {
405405
this.updateState();
406406
}
407407

408+
/** Get latest quarter of PE classes */
409+
get latestQuarter(): number {
410+
const allQuarters = new Set<number>();
411+
this.peClasses.forEach((cls) => {
412+
const quarter = cls.rawClass.quarter;
413+
allQuarters.add(quarter);
414+
});
415+
416+
// for 1 < 2 < 5 < 3 < 4
417+
const quarterOrder: Record<number, number> = {
418+
1: 0,
419+
2: 1,
420+
// 5 is iap for some reason :(
421+
5: 2,
422+
3: 3,
423+
4: 4,
424+
};
425+
426+
const sortedQuarters = Array.from(allQuarters).sort((a, b) => {
427+
return quarterOrder[a] - quarterOrder[b];
428+
});
429+
430+
return sortedQuarters[sortedQuarters.length - 1];
431+
}
432+
408433
//========================================================================
409434
// Loading and saving
410435

0 commit comments

Comments
 (0)