feat: implement arrival refresh functionality with timer

This commit is contained in:
2026-06-06 21:27:16 +08:00
parent 97c97f3f3a
commit 31d435c7b1
+16
View File
@@ -2,6 +2,7 @@
import { onDestroy, onMount } from "svelte";
const RAW_API_BASE = import.meta.env.VITE_API_BASE ?? "";
const ARRIVAL_REFRESH_MS = 30000;
function resolveApiBase() {
const base = RAW_API_BASE.trim().replace(/\/+$/, "");
@@ -44,6 +45,7 @@
let linkLine;
let nearbyStopMarkers = [];
let isMapClickPicking = false;
let arrivalRefreshTimer;
$: mapArrivals =
selectedStop && arrivalsStopCode === selectedStop.code
@@ -409,6 +411,14 @@
}
}
async function refreshArrivalsIfReady() {
if (!selectedStop || loadingArrivals || locating) {
return;
}
await runArrival();
}
async function selectBusStop(stop, loadArrivals = false) {
selectedStop = stop;
locationMessage = `Selected stop: ${stop.description} (${stop.code})`;
@@ -456,11 +466,17 @@
}
onMount(async () => {
arrivalRefreshTimer = setInterval(() => {
refreshArrivalsIfReady();
}, ARRIVAL_REFRESH_MS);
await updateMap();
await resolveLocationAndNearestStop();
});
onDestroy(() => {
clearInterval(arrivalRefreshTimer);
if (map) {
map.remove();
map = null;