From ad420b45280adc6443d6ced1e47fc7e5631289b1 Mon Sep 17 00:00:00 2001 From: sora-ext Date: Wed, 26 Feb 2025 16:55:29 +0100 Subject: [PATCH] Update src/client/api.ts --- src/client/api.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/client/api.ts b/src/client/api.ts index 26b5689..674d920 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -1,17 +1,18 @@ export const throttle = (func: () => void, wait: number) => { - let lastTime = 0; - let timeoutId: ReturnType | undefined; - let lastArgs: any[]; + var lastTime = 0; + var timeoutId: ReturnType | undefined; + var lastArgs: any[]; return function (...args: any[]) { const now = Date.now(); lastArgs = args; + if (timeoutId) clearTimeout(timeoutId); + timeoutId = undefined; if (now - lastTime >= wait) { lastTime = now; func.apply(this, lastArgs); } else { - if (timeoutId) clearTimeout(timeoutId); timeoutId = setTimeout( () => { lastTime = Date.now(); @@ -55,6 +56,7 @@ export const query_nominatim = ( bb: any, f: (v: string) => Boolean = () => true ) => { + if (q.length == 0) return Promise.resolve([]) let url = new URL("/api/place/" + q, window.location.origin); url.searchParams.append("id", q); url.searchParams.append("bb", JSON.stringify(bb)); @@ -95,7 +97,13 @@ export const is_attraction_type = (e: NominatimResult): boolean => "protected_area", ].indexOf(e.type) != -1; -export const icon_type = (item: NominatimResult): string => { +export const is_hotel_type = (e: NominatimResult): boolean => + ["hotel", "hostel", "guest_house"].indexOf(e.type) != -1 + +export const icon_type = (item: string | NominatimResult): string => { + if (typeof (item) == "string") { + return item + } let t = item.type; let c = item.category; let types = {