ctucx.git: trainsearch

web based trip-planner, fork of https://cyberchaos.dev/yuka/trainsearch

commit 9b7ead33fd5d6d0de4ac103e7958ef3cb1269888
parent f951410ab5ff2b846ed7eb478718583f1467f9ad
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 3 Feb 2025 06:42:25 +0100

tripView: add refresh-feature
1 file changed, 23 insertions(+), 3 deletions(-)
M
src/tripView.js
|
26
+++++++++++++++++++++++---
diff --git a/src/tripView.js b/src/tripView.js
@@ -9,7 +9,7 @@ import { go } from './router.js';
 import { getHafasClient, client } from './hafasClient.js';
 import { t } from './languages.js';
 
-const tripTemplate = (data, profile) => {
+const tripTemplate = (data, profile, refreshToken) => {
 	let changes = 0;
 	let lastArrival;
 

@@ -33,7 +33,7 @@ const tripTemplate = (data, profile) => {
 				<div class="container">
 					<h3>Trip of ${formatLineDisplayName(data.line)} to ${data.direction}</h3>
 				</div>
-				<a class="icon-reload invisible" title="${t('title')}"></a>
+				<a class="icon-reload" title="${t('title')}" @click=${() => refreshTripView(profile, refreshToken)}></a>
 			</header>
 		</div>
 

@@ -116,8 +116,28 @@ export const tripView = async (match, isUpdate) => {
 
 	hideOverlay();
 
-	render(tripTemplate(data.trip, profile), ElementById('content'));
+	render(tripTemplate(data.trip, profile, refreshToken), ElementById('content'));
 	setThemeColor(queryBackgroundColor('header'));
 
+	console.log(data)
+
 	if (history.length > 0) showElement(ElementById('back'));
 };
+
+const refreshTripView = async (profile, refreshToken) => {
+	document.querySelector('.icon-reload').classList.add('spinning');
+
+	let data;
+
+	try {
+		const client = await getHafasClient(profile);
+		data = await client.trip(refreshToken, {stopovers: true});
+		processLeg(data.trip);
+	} catch(e) {
+		showAlertModal(e.toString());
+		throw e;
+	}
+
+	render(tripTemplate(data.trip, profile, refreshToken), ElementById('content'));
+	document.querySelector('.icon-reload').classList.remove('spinning');
+};