Add src/client/types/search_drawer.ts
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
sora-ext 2025-03-10 17:24:22 +01:00
parent 5f80723fe9
commit 1c72e31ea8

View File

@ -0,0 +1,95 @@
import { search_flight, search_nominatim } from "../helper/api";
import { leg_template } from "./format";
declare global {
type query_type = "hotel" | "restaurant" | "place" | "flight"
type note_type = "notes"
type sub_type = "travel" | "other"
interface query {
type: query_type | note_type | "",
sub: sub_type | "",
query: String,
res: any[],
load: Boolean,
/* DELETE BELOW IF POSIBLE */
addmarker: Boolean,
}
interface map_override {
active: Boolean,
elements: geoloc[]
}
}
class search_drawer {
map_override: map_override = { active: false, elements: [] };
query: query = {
type: "", query: "", sub: "", res: [], load: false, addmarker: false,
}
resfresh_map: () => void = () => { }
get_bb: () => any[] = () => []
get_leg: () => leg = () => leg_template
constructor() {
}
show_drawer() {
return this.is_note() || this.is_query()
}
is_note() {
return ["notes"].includes(this.query.type)
}
is_query() {
return ["hotel", "restaurant", "place", "flight"].includes(this.query.type)
}
is_sub_travel() {
return ["travel"].includes(this.query.sub)
}
results(r: any[]) {
this.query.load = false;
this.query.res = r;
return r
}
reset() {
this.query.res = [];
this.query.type = "";
this.query.addmarker = false;
setTimeout(() => this.resfresh_map(), 500);
}
active(tpe: query_type) {
this.query.type = tpe;
this.query.load = this.is_query();
setTimeout(() => this.resfresh_map(), 500);
}
search(_e = null) {
const tpe = this.query.type;
const query = this.query.query;
switch (tpe) {
case 'flight':
return search_flight(tpe, query, this.get_leg());
default:
return search_nominatim(tpe, query, this.get_bb(), this.get_leg())
}
}
enable(f: query_type) {
this.active(f)
setTimeout(() => document.getElementById(this.is_note() ? 'query_note' : 'query_input')?.focus(), 500);
if (this.is_query()) this.search()
}
}
export default search_drawer;