commit b18e85ca752e3c37be4537e074fad700cbfb6e58
parent bcdcd6efd74d8dd919b13870a0c3ebd7e8c90b82
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 21 Apr 2025 17:13:54 +0200
parent bcdcd6efd74d8dd919b13870a0c3ebd7e8c90b82
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 21 Apr 2025 17:13:54 +0200
journeysView: refresh coach sequences on journeys-refresh
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/coach-sequence/index.js b/src/coach-sequence/index.js @@ -20,15 +20,17 @@ const rawDBCoachSequence = async (category, number, evaNumber, date, retry = 2) } } -export const cachedCoachSequence = (category, number, evaNumber, departure, onlyCached) => { +export const cachedCoachSequence = (category, number, evaNumber, departure, mode) => { if (!category || !number || !evaNumber || !departure) return null; const key = `${category}-${number}-${evaNumber}-${departure.toISOString()}`; let rawSequence = sessionStorage.getItem(key); let cachedResponse = true; + if (mode === 'noCache') rawSequence = null; + if (!rawSequence) { - if (onlyCached === true) return null; + if (mode === 'onlyCached') return null; cachedResponse = false; rawSequence = (async () => { try {
diff --git a/src/journeysCanvas.js b/src/journeysCanvas.js @@ -218,11 +218,12 @@ export class JourneysCanvas extends BaseView { } }; - getCoachSequences = async () => { + getCoachSequences = async mode => { if (this.isOffline !== false) return; if (!['db', 'rmv'].includes(this.viewState.profile)) return; if (isDevServer) console.info('JourneysCanvas(getCoachSequences): fetch start'); + const wasUpdating = this.isUpdating; this.isUpdating = true; let timeout = 500; for (const journey of this.viewState.journeys) { @@ -233,21 +234,21 @@ export class JourneysCanvas extends BaseView { await sleep(timeout); - const coachSequence = cachedCoachSequence(category, leg.line.fahrtNr || number, leg.origin.id, leg.plannedDeparture); + const coachSequence = cachedCoachSequence(category, leg.line.fahrtNr || number, leg.origin.id, leg.plannedDeparture, mode); timeout = !coachSequence.cachedResponse ? 1000 : 0; this.renderCanvas(); } } - this.isUpdating = false; if (isDevServer) console.info('JourneysCanvas(getCoachSequences): fetch end'); + if (!wasUpdating) this.isUpdating = false; }; getTrainTypeTexts = leg => { if (!leg.line || !leg.line.name) return []; const [category, number] = leg.line.name.split(" "); - const info = cachedCoachSequence(category, leg.line.fahrtNr || number, leg.origin.id, leg.plannedDeparture, true); + const info = cachedCoachSequence(category, leg.line.fahrtNr || number, leg.origin.id, leg.plannedDeparture, 'onlyCached'); if (!info) return []; return formatTrainTypes(info).split(" + ");
diff --git a/src/journeysView.js b/src/journeysView.js @@ -58,15 +58,12 @@ export class JourneysView extends JourneysCanvas { if (this.settingsState.journeysViewMode !== this.mode) this.settingsState.setJourneysViewMode(this.mode); } - if (!this.viewState && !this.overlayState.visible) await this.updateViewState(); - - if (this.mode === 'canvas') { - this.connectCanvas(); - - if (previous.has('viewState') && this.viewState) { - if (previous.get('viewState') !== null) await this.getCoachSequences(); - } + if (!this.viewState && !this.overlayState.visible) { + await this.updateViewState(); + if (this.mode === 'canvas' && this.viewState) await this.getCoachSequences(); } + + if (this.mode === 'canvas') this.connectCanvas(); } updated (previous) { @@ -98,7 +95,7 @@ export class JourneysView extends JourneysCanvas { </a> </div> </div> - <a class="icon-reload ${classMap({ spinning: this.isUpdating, invisible: this.isOffline })}" tabindex=0 title=${t("refresh")} + <a class="icon-reload ${classMap({ spinning: this.isUpdating, invisible: this.isOffline })}" title=${t("refresh")} @keydown=${this.keyClickHandler} @click=${this.refreshJourneys}></a> </header> </div> @@ -233,10 +230,13 @@ export class JourneysView extends JourneysCanvas { try { this.isUpdating = true; - await refreshJourneys(this.slug); - this.isUpdating = false; + await refreshJourneys(this.slug); await this.updateViewState(); + + if (this.mode === 'canvas') await this.getCoachSequences('noCache'); + + this.isUpdating = false; } catch(e) { this.isUpdating = false; this.showAlertOverlay(e.toString()); @@ -250,19 +250,23 @@ export class JourneysView extends JourneysCanvas { return; } - this.showLoaderOverlay(); try { this.isUpdating = true; - await getMoreJourneys(this.slug, mode); - this.isUpdating = false; + this.showLoaderOverlay(); + await getMoreJourneys(this.slug, mode); await this.updateViewState(); + this.hideOverlay(); + + if (this.mode === 'canvas') await this.getCoachSequences(); + this.isUpdating = false; } catch(e) { this.isUpdating = false; + this.hideOverlay(); + this.showAlertOverlay(e.toString()); console.error(e); } - this.hideOverlay(); }; }