Skip to content

Commit

Permalink
[refactor] simplify sorting method
Browse files Browse the repository at this point in the history
  • Loading branch information
cupoftea4 committed Nov 23, 2024
1 parent 439418f commit 6926c8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 61 deletions.
58 changes: 0 additions & 58 deletions src/utils/data/SortGroups.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/utils/data/TimetableManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type TimetableType,
} from "@/types/timetable";
import type { ActualPromise, OptimisticPromise, RenderPromises } from "@/types/utils";
import { sortingGroupsArray } from "@/utils/data/SortGroups";
import { sortGroups } from "@/utils/timetable";
import { DEVELOP } from "../constants";
import storage from "../storage";
import * as Util from "../timetable";
Expand Down Expand Up @@ -64,8 +64,8 @@ class TimetableManager {
});

// request data from server if needed
this.groups = sortingGroupsArray(await this.getData(GROUPS, FallbackData.getGroups));
this.selectiveGroups = await this.getData(SELECTIVE_GROUPS, FallbackData.getSelectiveGroups);
this.groups = sortGroups(await this.getData(GROUPS, FallbackData.getGroups));
this.selectiveGroups = sortGroups(await this.getData(SELECTIVE_GROUPS, FallbackData.getSelectiveGroups));
this.lecturers = await this.getData(LECTURERS, FallbackData.getLecturers);
}

Expand Down
9 changes: 9 additions & 0 deletions src/utils/timetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,12 @@ export function generateSaturdayLessons(originalTimetable: TimetableItem[]) {
}
return [];
}

export function sortGroups(groups: string[]) {
return groups.toSorted((g1, g2) => {
const r = /^(.*-\d)(\d+).*$/;
const [, year1 = "", groupNumber1 = ""] = g1.split(r);
const [, year2 = "", groupNumber2 = ""] = g2.split(r);
return `${year1}${groupNumber1.padStart(2, "0")}`.localeCompare(`${year2}${groupNumber2.padStart(2, "0")}`);
});
}

0 comments on commit 6926c8d

Please sign in to comment.