mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-02-04 01:04:33 +00:00
Fix SSE connections not respecting filters #3
This commit is contained in:
@@ -5,6 +5,12 @@ let rowCount = 0;
|
||||
|
||||
// Load spots and populate the table.
|
||||
function loadSpots() {
|
||||
// If we have an ongoing SSE connection, stop it so it doesn't interfere with our reload
|
||||
if (evtSource != null) {
|
||||
evtSource.close();
|
||||
}
|
||||
|
||||
// Make the new query
|
||||
$.getJSON('/api/v1/spots' + buildQueryString(), function(jsonData) {
|
||||
// Store last updated time
|
||||
lastUpdateTime = moment.utc();
|
||||
@@ -14,17 +20,14 @@ function loadSpots() {
|
||||
// Update table
|
||||
updateTable();
|
||||
// Start SSE connection to fetch updates in the background
|
||||
restartSSEConnection();
|
||||
startSSEConnection();
|
||||
});
|
||||
}
|
||||
|
||||
// Start an SSE connection (closing an existing one if it exists). This will then be used to add to the table on the
|
||||
// fly.
|
||||
function restartSSEConnection() {
|
||||
if (evtSource != null) {
|
||||
evtSource.close();
|
||||
}
|
||||
evtSource = new EventSource('/api/v1/spots/stream');
|
||||
function startSSEConnection() {
|
||||
evtSource = new EventSource('/api/v1/spots/stream' + buildQueryString());
|
||||
|
||||
evtSource.onmessage = function(event) {
|
||||
// Store last updated time
|
||||
@@ -74,8 +77,8 @@ function buildQueryString() {
|
||||
}
|
||||
});
|
||||
str = str + "limit=" + $("#spots-to-fetch option:selected").val();
|
||||
if ($("#filter-dx-call").val() != "") {
|
||||
str = str + "&dx_call_includes=" + encodeURIComponent($("#filter-dx-call").val());
|
||||
if ($("#search").val() != "") {
|
||||
str = str + "&text_includes=" + encodeURIComponent($("#search").val());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user