Init project
This commit is contained in:
39
web/journeys-search.js
Normal file
39
web/journeys-search.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { fetchJourneys } from './api.js';
|
||||
import { attachLocationsSearch } from './locations-search.js';
|
||||
|
||||
let element_from = document.querySelector("#journey-search-from");
|
||||
let element_to = document.querySelector("#journey-search-to");
|
||||
let element_submit = document.querySelector("#journey-search-submit");
|
||||
let element_result = document.querySelector("#journey-search-result");
|
||||
|
||||
export function setupJourneysSearch() {
|
||||
attachLocationsSearch(element_from);
|
||||
attachLocationsSearch(element_to);
|
||||
|
||||
element_submit.addEventListener("click", event => {
|
||||
element_result.innerText = "Loading…";
|
||||
fetchJourneys(element_from.dataset.locationId, element_to.dataset.locationId).then(result => {
|
||||
for (let journey of result.journeys) {
|
||||
element_result.appendChild(createJourneyElement(journey));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function createJourneyElement(journey) {
|
||||
let el = document.createElement("div");
|
||||
|
||||
for (let leg of journey.legs) {
|
||||
el.appendChild(createJourneyLegElement(leg));
|
||||
}
|
||||
|
||||
return el;
|
||||
|
||||
}
|
||||
|
||||
function createJourneyLegElement(leg) {
|
||||
let el = document.createElement("div");
|
||||
el.innerText = JSON.stringify(leg);
|
||||
el.innerText = leg?.line?.name + ": " + leg.origin.name + " > " + leg.destination.name;
|
||||
return el;
|
||||
}
|
Reference in New Issue
Block a user