dev merge (#163)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: soraefir Co-authored-by: sora-ext Reviewed-on: #163
This commit is contained in:
61
src/client/helper/api.ts
Normal file
61
src/client/helper/api.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
import { getGeoLine } from "../types/geom";
|
||||
import * as api from "../api";
|
||||
|
||||
const filter_existing = function (tpe: "nominatim" | "travel", leg: leg, r: geoloc[]) {
|
||||
switch (tpe) {
|
||||
case 'nominatim':
|
||||
return r.filter(e => {
|
||||
if (leg.hotel && leg.hotel.osm_id == e.osm_id) return false;
|
||||
if (leg.places.restaurants.find(i => i.osm_id == e.osm_id)) return false;
|
||||
if (leg.places.activities.find(i => i.osm_id == e.osm_id)) return false;
|
||||
return true
|
||||
})
|
||||
case 'travel':
|
||||
console.log(r)
|
||||
return r.filter(e => {
|
||||
if (leg.travel.find(i => `${(e as any).from}->${(e as any).to}` == `${(i as any).from}->${(i as any).to}`)) return false;
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const process_results = function (tpe: "nominatim" | "travel", r: geoloc[]) {
|
||||
switch (tpe) {
|
||||
case 'nominatim':
|
||||
return r.map((rr) => {
|
||||
rr.latlon = [parseFloat((rr as any).lat), parseFloat((rr as any).lon)];
|
||||
rr.title = (rr as any).display_name.split(",")[0];
|
||||
return rr;
|
||||
});
|
||||
case 'travel':
|
||||
console.log(r)
|
||||
return r.map(el => {
|
||||
(el as any).path = getGeoLine(
|
||||
{ lat: (el as any).from_geo.lat, lng: (el as any).from_geo.lon },
|
||||
{ lat: (el as any).to_geo.lat, lng: (el as any).to_geo.lon }, { dist: 2_500_000 }).map(v => [v.lat, v.lng]);
|
||||
(el as any).type = "flight";
|
||||
return el;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var _search_set_results: (...arg: any[]) => any;
|
||||
export const set_search_set_results = function (f: (...arg: any[]) => any) {
|
||||
_search_set_results = f;
|
||||
}
|
||||
export const search_nominatim = api.throttle(
|
||||
(f: string, q: string, bb: [[number, number], [number, number]], leg: leg) =>
|
||||
api.query_nominatim(q, bb, api.get_filter(f)).catch((_err) => console.log(_err)).then((r) => {
|
||||
r = process_results('nominatim', r)
|
||||
r = filter_existing('nominatim', leg, r)
|
||||
_search_set_results(r)
|
||||
}), 1000);
|
||||
|
||||
export const search_flight = api.throttle(
|
||||
(f: string, q: string, leg: leg) =>
|
||||
api.query_flight(q).then((r) => {
|
||||
r = process_results('travel', r)
|
||||
r = filter_existing('travel', leg, r)
|
||||
_search_set_results(r)
|
||||
}), 2000)
|
41
src/client/helper/journey.ts
Normal file
41
src/client/helper/journey.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import journey_wrapper from './types/wrapper';
|
||||
|
||||
/* LIST HELPERS */
|
||||
export const filter_selected = function (journey: journey_wrapper, list: geoloc[], step: boolean) {
|
||||
return list.filter((e) =>
|
||||
step ? e.step == journey.sel_day : e.step >= 0,
|
||||
);
|
||||
}
|
||||
|
||||
export const filter_unselected = function (list: geoloc[]) {
|
||||
return list.filter((e) => e.step == undefined || e.step < 0);
|
||||
}
|
||||
|
||||
export const remove_item = function (list: geoloc[], idx: number) {
|
||||
list[idx].step = -1;
|
||||
list.splice(idx, 1);
|
||||
}
|
||||
|
||||
|
||||
/* JOURNEY ADD/RM ITEM HELPER */
|
||||
export const journey_add_place = function (journey: journey_wrapper, tpe: String, item: geoloc) {
|
||||
switch (tpe) {
|
||||
case 'hotel': return journey.leg_get().hotel = item;
|
||||
case 'restaurant': return journey.leg_get().places.restaurants.push(item);
|
||||
case 'place': return journey.leg_get().places.activities.push(item);
|
||||
case 'other': return;
|
||||
case 'flight': return journey.leg_get().travel.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
export const journey_del_place = function (journey: journey_wrapper, tpe: String, idx: number) {
|
||||
console.log(tpe)
|
||||
switch (tpe) {
|
||||
case "hotel": return journey.leg_get().hotel = null;
|
||||
case "restaurants": return journey.leg_get().places.restaurants.splice(idx, 1);
|
||||
case "activities": return journey.leg_get().places.activities.splice(idx, 1);
|
||||
case "other": return;
|
||||
case "flight": return journey.leg_get().travel.splice(idx, 1);
|
||||
default: return true;
|
||||
}
|
||||
}
|
49
src/client/helper/nav.ts
Normal file
49
src/client/helper/nav.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import journey_wrapper from "../types/wrapper";
|
||||
|
||||
var nav = {
|
||||
scrollInterval: 0,
|
||||
scrollDir: 'none',
|
||||
};
|
||||
|
||||
|
||||
const sideScroll = function (element: Element, direction: 'left' | 'right' | 'none', speed: number, step: number) {
|
||||
nav.scrollDir = direction
|
||||
if (direction == 'none') return;
|
||||
nav.scrollInterval = setInterval(() => {
|
||||
element.scrollLeft += (direction == 'left') ? -step : step;
|
||||
}, speed);
|
||||
}
|
||||
|
||||
export const focus_leg = function (journey: journey_wrapper, idx: number | null = null) {
|
||||
const c = document.querySelector('.scroll-content.nav-leg')!!
|
||||
console.log(idx, c, journey)
|
||||
const item = c.children[(idx != null ? idx : journey.sel_leg) + 1];
|
||||
c.scrollLeft = (item as any).offsetLeft + ((item as any).offsetWidth / 2) - (c as any).offsetWidth / 2
|
||||
}
|
||||
|
||||
export const focus_day = function (journey: journey_wrapper, idx: number | null = null) {
|
||||
const c = document.querySelector('.scroll-content.nav-day')!!
|
||||
console.log(idx, c, journey)
|
||||
const item = c.children[(idx != null ? idx : journey.sel_day) + 1];
|
||||
c.scrollLeft = (item as any).offsetLeft + ((item as any).offsetWidth / 2) - (c as any).offsetWidth / 2;
|
||||
//focus_leg(journey) // We dont render both navs anymore
|
||||
}
|
||||
|
||||
export const nav_mousemove = function (e: PointerEvent) {
|
||||
if (e.pointerType != 'mouse') return;
|
||||
const c = (e.target as any).closest('.scroll-content') || (e.target as any).firstChild;
|
||||
const left = e.pageX - c.getBoundingClientRect().left;
|
||||
const newDir =
|
||||
left < c.offsetWidth * 0.1 ? 'left' :
|
||||
(left > c.offsetWidth * 0.9 ? 'right' : 'none')
|
||||
if (!nav.scrollInterval || nav.scrollDir != newDir) {
|
||||
if (nav.scrollInterval) clearInterval(nav.scrollInterval)
|
||||
sideScroll(c, newDir, 25, 10);
|
||||
}
|
||||
}
|
||||
export const nav_mouseleave = function (_e: PointerEvent) {
|
||||
clearInterval(nav.scrollInterval);
|
||||
nav.scrollDir = 'none'
|
||||
nav.scrollInterval = 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user