fixes sorting by difficulty
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user