fixes sorting by difficulty
This commit is contained in:
@@ -51,9 +51,9 @@
|
||||
];
|
||||
|
||||
const difficultyItems: SelectItem[] = [
|
||||
{ text: $_("easy"), value: "easy" },
|
||||
{ text: $_("moderate"), value: "moderate" },
|
||||
{ text: $_("difficult"), value: "difficult" },
|
||||
{ text: $_("easy"), value: 0 },
|
||||
{ text: $_("moderate"), value: 1 },
|
||||
{ text: $_("difficult"), value: 2 },
|
||||
];
|
||||
|
||||
let searchDropdownItems: SearchItem[] = $state([]);
|
||||
|
||||
@@ -111,7 +111,7 @@ interface TrailFilter {
|
||||
q: string,
|
||||
category: string[],
|
||||
tags: string[],
|
||||
difficulty: ("easy" | "moderate" | "difficult")[]
|
||||
difficulty: (0 | 1 | 2)[]
|
||||
author?: string;
|
||||
public?: boolean;
|
||||
shared?: boolean;
|
||||
@@ -169,7 +169,7 @@ interface TrailSearchResult {
|
||||
elevation_gain: number;
|
||||
elevation_loss: number;
|
||||
duration: number;
|
||||
difficulty: "easy" | "moderate" | "difficult";
|
||||
difficulty: 0 | 1 | 2;
|
||||
category: string;
|
||||
completed: boolean;
|
||||
date: number;
|
||||
|
||||
@@ -457,7 +457,7 @@ export async function searchResultToTrailList(hits: Hits<TrailSearchResult>): Pr
|
||||
created: new Date(h.created * 1000).toISOString(),
|
||||
date: new Date(h.date * 1000).toISOString(),
|
||||
description: h.description,
|
||||
difficulty: h.difficulty,
|
||||
difficulty: h.difficulty == 0 ? "easy" : h.difficulty == 1 ? "moderate" : "difficult",
|
||||
distance: h.distance,
|
||||
duration: h.duration,
|
||||
elevation_gain: h.elevation_gain,
|
||||
|
||||
@@ -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