feat: add time left
Some checks failed
TrafficCue CI / check (push) Failing after 55s
TrafficCue CI / build (push) Successful in 1m34s
TrafficCue CI / build-android (push) Successful in 14m57s

This commit is contained in:
2025-09-18 10:47:51 +02:00
parent 4fcbd3cf13
commit 2aed03642d

View File

@ -121,9 +121,37 @@
if (dist < 1000) return `${dist} m`;
return `${dist / 1000} km`;
});
//
// Calculating time left
//
function formatTimeLeft(seconds: number) {
if (seconds < 60) return `${Math.round(seconds)} s`;
if (seconds < 3600) return `${Math.round(seconds / 60)} min`;
const h = Math.floor(seconds / 3600);
const m = Math.round((seconds % 3600) / 60);
if (m === 0) return `${h} h`;
return `${h} h ${m} min`;
}
function getTimeLeft(): number {
// TODO: include partial maneuver time
if (!routing.currentTrip) return 0;
let total = 0;
for (const [index, maneuver] of routing.currentTrip.legs[0].maneuvers.entries()) {
if (index >= routing.currentTripInfo.maneuverIdx) {
total += maneuver.time;
}
}
return total;
}
const timeLeft = $derived.by(() => {
return formatTimeLeft(getTimeLeft());
})
</script>
{fullDistanceText}
{fullDistanceText}, {timeLeft}
{m["sidebar.in-route.left"]()}
<Button