Improvements to spot timing display #3

This commit is contained in:
Ian Renton
2025-12-22 20:44:50 +00:00
parent 1f66da062b
commit fb935138a1
4 changed files with 16 additions and 5 deletions

View File

@@ -30,8 +30,17 @@ function restartSSEConnection() {
// Store last updated time
lastUpdateTime = moment.utc();
updateRefreshDisplay();
// Add spot to internal data store
// Get the new spot
newSpot = JSON.parse(event.data);
// Awful fudge to ensure new incoming spots at the top of the list don't have timestamps that make them look
// like they belong further down the list. If the spot is older than the latest one we already have, bump its
// time up to match it. This isn't great but since we poll spot providers every 2 minutes anyway, it shouldn't
// be too far wrong.
if (spots.length > 0) {
newSpot["time"] = Math.max(newSpot["time"], Math.max(...spots.map(s => s["time"])))
}
// Add spot to internal data store
spots.unshift(newSpot);
spots = spots.slice(0, -1);
// Add spot to table