From ae1caaa40f0266b9ae70382f293d747a4dc40b8b Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Tue, 23 Dec 2025 21:45:17 +0000 Subject: [PATCH] Fix handling new spots by SSE when there weren't the max number already #3 --- webassets/css/style.css | 4 ---- webassets/js/spots.js | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/webassets/css/style.css b/webassets/css/style.css index 7da2b7d..383c55e 100644 --- a/webassets/css/style.css +++ b/webassets/css/style.css @@ -90,10 +90,6 @@ div.appearing-panel { display: none; } -button#add-spot-button { - display: none; -} - .spothole-card-text { line-height: 2.5em !important; } diff --git a/webassets/js/spots.js b/webassets/js/spots.js index cde3b6b..13d443e 100644 --- a/webassets/js/spots.js +++ b/webassets/js/spots.js @@ -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(); });