Skip to content

Commit

Permalink
Merge pull request #30 from cupoftea4/fix-sorting-name-group
Browse files Browse the repository at this point in the history
group names sorting
  • Loading branch information
cupoftea4 authored Nov 23, 2024
2 parents 7dd0921 + 6926c8d commit ce3ef84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/data/TimetableManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type TimetableType,
} from "@/types/timetable";
import type { ActualPromise, OptimisticPromise, RenderPromises } from "@/types/utils";
import { sortGroups } from "@/utils/timetable";
import { DEVELOP } from "../constants";
import storage from "../storage";
import * as Util from "../timetable";
Expand Down Expand Up @@ -63,8 +64,8 @@ class TimetableManager {
});

// request data from server if needed
this.groups = 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 ce3ef84

Please sign in to comment.