Fix handling new spots by SSE when there weren't the max number already #3

This commit is contained in:
Ian Renton
2025-12-23 21:45:17 +00:00
parent 6116d19580
commit ae1caaa40f
2 changed files with 12 additions and 14 deletions

View File

@@ -42,12 +42,19 @@ function restartSSEConnection() {
// Add spot to internal data store
spots.unshift(newSpot);
spots = spots.slice(0, -1);
// Add spot to table
// Work out if we need to remove an old spot
if (spots.length > $("#spots-to-fetch option:selected").val()) {
spots = spots.slice(0, -1);
// Drop oldest spot off the end of the table. This is two rows because of the mobile view extra rows
$("#table tbody tr").last().remove();
$("#table tbody tr").last().remove();
}
// If we had zero spots before (i.e. one now), the table will have a "No spots" row that we need to remove now
// that we have one.
$("#table tbody tr").last().remove();
// Add the new spot to table
addSpotToTopOfTable(newSpot, true);
// Drop oldest spot off the end of the table. This is two rows because of the mobile view extra rows
$("#table tbody tr").last().remove();
$("#table tbody tr").last().remove();
};
evtSource.onerror = function(err) {
@@ -387,11 +394,6 @@ function loadOptions() {
$("#tableShowBearing").prop('checked', false);
}
// Show the Add Spot button if spotting is allowed
if (options["spot_allowed"]) {
$("#add-spot-button").show();
}
// Load spots (this will also set up the SSE connection to update them too)
loadSpots();
});