Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Commit fbe4978

Browse files
committed
refactor: enhance sorting logic for lessons and resources using Intl.Collator
1 parent 0923ffc commit fbe4978

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/components/common/lessons/lessons.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ export class LessonListContainer {
6969

7070
const lessons = await LessonsAPI.getByOutcome(this.outcome.outcomeId);
7171

72-
const entries = Object.entries(lessons?.data ?? {});
72+
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
73+
74+
const entries = Object.entries(lessons?.data ?? {}).sort(([, a], [, b]) => {
75+
const nameCompare = collator.compare(a.data.name, b.data.name);
76+
if (nameCompare !== 0) return nameCompare;
77+
78+
return collator.compare(a.data.topic, b.data.topic);
79+
});
80+
7381
if (entries.length === 0) {
7482
this.showEmptyMessage("No lessons have been added yet.");
7583
return;

src/components/common/resources/resource.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export class ResourceListContainer {
6868

6969
const resources = await ResourceAPI.getByOutcome(this.outcome.outcomeId);
7070

71-
const items = resources?.data ?? [];
71+
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
72+
73+
const items = (resources?.data ?? []).sort((a, b) => collator.compare(a, b));
7274
if (!items.length) {
7375
this.showEmptyMessage("No resources linked to this outcome yet.");
7476
return;

src/pages/library/library.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ document.addEventListener("DOMContentLoaded", async () => {
4444
function render(list: Record<string, LessonRecord>) {
4545
libraryDiv.innerHTML = "";
4646

47-
const entries = Object.entries(list).sort(([, a], [, b]) =>
48-
a.data.name.localeCompare(b.data.name, undefined, { numeric: true })
49-
);
47+
const entries = Object.entries(list).sort(([, a], [, b]) => {
48+
const nameCompare = a.data.topic.localeCompare(b.data.topic, undefined, { numeric: true });
49+
if (nameCompare !== 0) return nameCompare;
50+
return a.data.name.localeCompare(b.data.name, undefined, { numeric: true });
51+
});
5052

5153
if (!entries.length) {
5254
const p = document.createElement("p");

0 commit comments

Comments
 (0)