adds list search
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
import { categories } from "$lib/stores/category_store";
|
||||
import {
|
||||
searchMulti,
|
||||
type ListSearchResult,
|
||||
type LocationSearchResult,
|
||||
type TrailSearchResult,
|
||||
} from "$lib/stores/search_store.js";
|
||||
@@ -32,6 +33,11 @@
|
||||
q: q,
|
||||
limit: 3,
|
||||
},
|
||||
{
|
||||
indexUid: "lists",
|
||||
q: q,
|
||||
limit: 3,
|
||||
},
|
||||
{
|
||||
indexUid: "locations",
|
||||
q: q,
|
||||
@@ -46,19 +52,27 @@
|
||||
value: t.id,
|
||||
icon: "route",
|
||||
}));
|
||||
const cityItems = r[1].hits.map((c: LocationSearchResult) => ({
|
||||
const listItems = r[1].hits.map((t: ListSearchResult) => ({
|
||||
text: t.name,
|
||||
description: `List, ${t.trails.length} ${$_("trail", { values: { n: t.trails.length } })}`,
|
||||
value: t.id,
|
||||
icon: "layer-group",
|
||||
}));
|
||||
const cityItems = r[2].hits.map((c: LocationSearchResult) => ({
|
||||
text: c.name,
|
||||
description: c.description,
|
||||
value: c,
|
||||
icon: getIconForLocation(c),
|
||||
}));
|
||||
|
||||
searchDropdownItems = [...trailItems, ...cityItems];
|
||||
searchDropdownItems = [...trailItems, ...listItems, ...cityItems];
|
||||
}
|
||||
|
||||
function handleSearchClick(item: SearchItem) {
|
||||
if (item.icon == "route") {
|
||||
goto(`/trail/view/${item.value}`);
|
||||
} else if (item.icon == "layer-group") {
|
||||
goto(`/lists?list=${item.value}`);
|
||||
} else {
|
||||
goto(`/map/?lat=${item.value.lat}&lon=${item.value.lon}`);
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
|
||||
import { env } from "$env/dynamic/private";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.json()
|
||||
|
||||
try {
|
||||
const r = await event.fetch(`${env.NOMINATIM_URL}/search?q=${data.q}&format=geocodejson&limit=${data.limit}`)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
console.log(e);
|
||||
|
||||
throw error(e.httpStatus, e)
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,11 @@
|
||||
import UserSearch from "$lib/components/user_search.svelte";
|
||||
import { List, type ListFilter } from "$lib/models/list";
|
||||
import type { Trail } from "$lib/models/trail";
|
||||
import { lists_delete, lists_index } from "$lib/stores/list_store";
|
||||
import {
|
||||
lists_delete,
|
||||
lists_index,
|
||||
lists_search_filter,
|
||||
} from "$lib/stores/list_store";
|
||||
import { fetchGPX } from "$lib/stores/trail_store";
|
||||
import { currentUser } from "$lib/stores/user_store";
|
||||
import * as M from "maplibre-gl";
|
||||
@@ -53,7 +57,7 @@
|
||||
let showMap: boolean = true;
|
||||
|
||||
let selectedList: List | null = $state(
|
||||
page.url.searchParams.get("list") ? lists.items[0] : null,
|
||||
page.url.searchParams.get("list") ? data.lists.items[0] : null,
|
||||
);
|
||||
let selectedTrail: Trail | null = $state(null);
|
||||
|
||||
@@ -191,8 +195,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
pagination.page = 0;
|
||||
lists = await lists_index(filter, pagination.page);
|
||||
pagination.page = 1;
|
||||
lists = await lists_search_filter(filter, pagination.page);
|
||||
loading = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import { categories } from "$lib/stores/category_store";
|
||||
import {
|
||||
searchMulti,
|
||||
type ListSearchResult,
|
||||
type LocationSearchResult,
|
||||
type TrailSearchResult,
|
||||
} from "$lib/stores/search_store";
|
||||
@@ -56,6 +57,11 @@
|
||||
q: q,
|
||||
limit: 3,
|
||||
},
|
||||
{
|
||||
indexUid: "lists",
|
||||
q: q,
|
||||
limit: 3,
|
||||
},
|
||||
{
|
||||
indexUid: "locations",
|
||||
q: q,
|
||||
@@ -70,19 +76,29 @@
|
||||
value: t,
|
||||
icon: "route",
|
||||
}));
|
||||
const cityItems = r[1].hits.map((c: LocationSearchResult) => ({
|
||||
const listItems = r[1].hits.map((t: ListSearchResult) => ({
|
||||
text: t.name,
|
||||
description: `List, ${t.trails.length} ${$_("trail", { values: { n: t.trails.length } })}`,
|
||||
value: t.id,
|
||||
icon: "layer-group",
|
||||
}));
|
||||
const cityItems = r[2].hits.map((c: LocationSearchResult) => ({
|
||||
text: c.name,
|
||||
description: c.description,
|
||||
value: c,
|
||||
icon: getIconForLocation(c),
|
||||
}));
|
||||
|
||||
searchDropdownItems = [...trailItems, ...cityItems];
|
||||
searchDropdownItems = [...trailItems, ...listItems, ...cityItems];
|
||||
}
|
||||
|
||||
function handleSearchClick(item: SearchItem) {
|
||||
map?.setCenter([item.value.lon, item.value.lat]);
|
||||
map?.setZoom(14);
|
||||
if (item.icon === "layer-group") {
|
||||
goto(`/lists?list=${item.value}`);
|
||||
} else {
|
||||
map?.setCenter([item.value.lon, item.value.lat]);
|
||||
map?.setZoom(14);
|
||||
}
|
||||
}
|
||||
|
||||
async function searchTrails(northEast: M.LngLat, southWest: M.LngLat) {
|
||||
|
||||
Reference in New Issue
Block a user