feat: add time left
This commit is contained in:
@ -121,9 +121,37 @@
|
|||||||
if (dist < 1000) return `${dist} m`;
|
if (dist < 1000) return `${dist} m`;
|
||||||
return `${dist / 1000} km`;
|
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>
|
</script>
|
||||||
|
|
||||||
{fullDistanceText}
|
{fullDistanceText}, {timeLeft}
|
||||||
{m["sidebar.in-route.left"]()}
|
{m["sidebar.in-route.left"]()}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user