katja's git: oeffisearch

fast and simple tripplanner

commit 4be9355a0004b8875db19a30dc6bdf79b08b7762
parent 6be1a681c57e66aa60ecfd5596b273d9e2010100
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 17 Apr 2025 14:10:41 +0200

journeyView: better offline support
1 file changed, 13 insertions(+), 9 deletions(-)
M
src/journeyView.js
|
22
+++++++++++++---------
diff --git a/src/journeyView.js b/src/journeyView.js
@@ -76,7 +76,7 @@ class JourneyView extends BaseView {
 				<header>
 					<a id="back" class="icon-back ${history.length !== 1 ? '': 'invisible'}" title="${t('back')}" @click=${() => history.back()}></a>
 					<div class="container">
-						<a class="icon-reload ${this.isUpdating ? 'spinning' : ''}" title="${t("reload")}" @click=${this.refreshJourney}></a>
+						<a class="icon-reload ${this.isUpdating ? 'spinning' : ''} ${!this.isOffline ? '' : 'invisible'}" title="${t("reload")}" @click=${this.refreshJourney}></a>
 						${this.viewState !== null ? html`
 						<h3>${formatPoint(this.viewState.legs[0].origin)} → ${formatPoint(this.viewState.legs[this.viewState.legs.length - 1].destination)}</h3>
 						<p><b>${t('duration')}: ${formatDuration(this.viewState.duration)} | ${t('changes')}: ${this.viewState.changes-1} | ${t('date')}: ${this.viewState.legs[0].plannedDeparture.formatDate()}${this.settingsState.showPrices && this.viewState.price ? html` | ${t('price')}: <td><span>${formatPrice(this.viewState.price)}</span></td>` : nothing}</b></p>

@@ -212,13 +212,15 @@ class JourneyView extends BaseView {
 			this.viewState = viewState;
 
 			//fetch train types after setting the viewState
-			for (const leg of this.viewState.legs) {
-				if (leg.line && leg.line.name) {
-					const [category, number] = leg.line.name.split(' ');
-					const info               = await cachedCoachSequence(category, leg.line.fahrtNr || number, leg.origin.id, leg.plannedDeparture);
-
-					if (info) leg.line.trainType = formatTrainTypes(info);
-					this.requestUpdate();
+			if (!this.isOffline !== false) {
+				for (const leg of this.viewState.legs) {
+					if (leg.line && leg.line.name) {
+						const [category, number] = leg.line.name.split(' ');
+						const info               = await cachedCoachSequence(category, leg.line.fahrtNr || number, leg.origin.id, leg.plannedDeparture);
+
+						if (info) leg.line.trainType = formatTrainTypes(info);
+						this.requestUpdate();
+					}
 				}
 			}
 

@@ -231,6 +233,7 @@ class JourneyView extends BaseView {
 	}
 
 	async refreshJourney () {
+		if (this.isOffline !== false) return;
 		if (this.isUpdating !== false) return false;
 
 		this.isUpdating = true;

@@ -268,7 +271,8 @@ class JourneyView extends BaseView {
 	async showTicketsModal () {
 		try {
 			this.showLoaderOverlay();
-			await this.refreshJourney();
+
+			if (this.isOffline !== false) await this.refreshJourney();
 
 			if (this.viewState.tickets === undefined) {
 				await this.showAlertOverlay('No ticket data available');