commit c24eb76a5c5f7dce8951561b56b041c0ecfbc24b
parent 9b7ead33fd5d6d0de4ac103e7958ef3cb1269888
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 3 Feb 2025 06:42:57 +0100
parent 9b7ead33fd5d6d0de4ac103e7958ef3cb1269888
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 3 Feb 2025 06:42:57 +0100
departuresView: add refresh-feature
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/src/departuresView.js b/src/departuresView.js @@ -9,7 +9,7 @@ import { go } from './router.js'; import { getHafasClient, client } from './hafasClient.js'; import { t } from './languages.js'; -const departuresTemplate = (data, profile) => { +const departuresTemplate = (data, profile, stopId, when) => { let changes = 0; let lastArrival; @@ -20,7 +20,7 @@ const departuresTemplate = (data, profile) => { <div class="container"> <h3>Departures from ${data.name}</h3> </div> - <a id="reload" class="icon-reload invisible" title="${t("reload")}"></a> + <a id="reload" class="icon-reload" title="${t("reload")}" @click=${() => refreshDeparturesView(profile, stopId, when)}></a> </header> </div> <div class="container departuresView"> @@ -81,8 +81,34 @@ export const departuresView = async (match, isUpdate) => { hideOverlay(); - render(departuresTemplate(data, profile), ElementById('content')); + render(departuresTemplate(data, profile, stopId, when), ElementById('content')); setThemeColor(queryBackgroundColor('header')); if (history.length > 0) ElementById('back').classList.remove('invisible'); }; + +const refreshDeparturesView = async (profile, stopId, when) => { + document.querySelector('.icon-reload').classList.add('spinning'); + + let data; + + try { + const client = await getHafasClient(profile); + const [ {departures}, stopInfo ] = await Promise.all([ + client.departures(stopId, { when }), + client.stop(stopId), + ]); + + for (let departure of departures) { + processLeg(departure); + }; + + data = { ...stopInfo, departures }; + } catch(e) { + showAlertModal(e.toString()); + throw e; + } + + render(departuresTemplate(data, profile, stopId, when), ElementById('content')); + document.querySelector('.icon-reload').classList.remove('spinning'); +};