diff --git a/lib/aprs_web/live/map_live/index.ex b/lib/aprs_web/live/map_live/index.ex
index 897b82e..547adb6 100644
--- a/lib/aprs_web/live/map_live/index.ex
+++ b/lib/aprs_web/live/map_live/index.ex
@@ -211,13 +211,29 @@ defmodule AprsWeb.MapLive.Index do
end
@impl true
- def handle_event("update_trail_duration", %{"target" => %{"value" => duration}}, socket) do
- {:noreply, assign(socket, trail_duration: duration)}
+ def handle_event("update_trail_duration", %{"trail_duration" => duration}, socket) do
+ # Convert duration string to hours and calculate new threshold
+ hours = String.to_integer(duration)
+ new_threshold = DateTime.add(DateTime.utc_now(), -hours * 3600, :second)
+
+ socket = assign(socket, trail_duration: duration, packet_age_threshold: new_threshold)
+
+ # Trigger cleanup to remove packets that are now outside the new duration
+ send(self(), :cleanup_old_packets)
+
+ {:noreply, socket}
end
@impl true
- def handle_event("update_historical_hours", %{"target" => %{"value" => hours}}, socket) do
- {:noreply, assign(socket, historical_hours: hours)}
+ def handle_event("update_historical_hours", %{"historical_hours" => hours}, socket) do
+ socket = assign(socket, historical_hours: hours)
+
+ # Trigger a reload of historical packets with the new time range
+ if socket.assigns.map_ready do
+ send(self(), :reload_historical_packets)
+ end
+
+ {:noreply, socket}
end
@impl true
@@ -312,6 +328,8 @@ defmodule AprsWeb.MapLive.Index do
def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket)
+ def handle_info(:reload_historical_packets, socket), do: handle_reload_historical_packets(socket)
+
def handle_info({:postgres_packet, packet}, socket), do: handle_info_postgres_packet(packet, socket)
def handle_info(%Phoenix.Socket.Broadcast{topic: "aprs_messages", event: "packet", payload: packet}, socket),
@@ -631,9 +649,9 @@ defmodule AprsWeb.MapLive.Index do
Trail Duration
-
+
-
+