fixes sorting by difficulty

This commit is contained in:
Christian Beutel
2025-09-07 17:59:35 +02:00
parent 8cc7029243
commit 3b7f30908c
8 changed files with 41 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ export const load: ServerLoad = async ({ params, locals, fetch }) => {
q: "",
category: [],
tags: [],
difficulty: ["easy", "moderate", "difficult"],
difficulty: [0, 1, 2],
author: "",
public: true,
shared: true,

View File

@@ -12,7 +12,7 @@ export const load: Load = async ({ params, fetch, parent }) => {
q: "",
category: [],
tags: [],
difficulty: ["easy", "moderate", "difficult"],
difficulty: [0, 1, 2],
author: actor.id,
public: true,
shared: true,

View File

@@ -25,7 +25,24 @@
export const snapshot: Snapshot<TrailFilter> = {
capture: () => filter,
restore: (value) => {
filter = value;
const difficultyMap: Record<string, 0 | 1 | 2> = {
easy: 0,
moderate: 1,
difficult: 2,
};
// defensive copy
const migrated = { ...value };
if (Array.isArray(migrated.difficulty)) {
migrated.difficulty = migrated.difficulty.map((d: any) => {
if (typeof d === "string" && d in difficultyMap) {
return difficultyMap[d];
}
return d;
});
}
filter = migrated;
handleFilterUpdate();
},
};

View File

@@ -10,7 +10,7 @@ export const load: ServerLoad = async ({ params, locals, url, fetch }) => {
q: "",
category: [],
tags: [],
difficulty: ["easy", "moderate", "difficult"],
difficulty: [0, 1, 2],
author: "",
public: true,
shared: true,