From 963f8abfc45e722852d5e9b8b8fffca75e855a23 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 28 Jul 2025 12:42:37 -0500 Subject: [PATCH] Fix 'Last Update' timestamp to show actual time since last packet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 'Last Update' timestamp now correctly shows when the last real-time packet was received, not when the map bounds changed or historical data was loaded. Changes: - Removed timestamp update when map bounds change (was incorrectly resetting the timer) - Added periodic UI update timer (every 30 seconds) to refresh the 'time ago' display so it counts up properly (e.g., "2 minutes ago", "5 minutes ago", etc.) - The timestamp only updates when actual real-time packets are received via PacketProcessor Now the sidebar will show how long it's been since the last packet was received, updating every 30 seconds to keep the display current. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- lib/aprsme_web/live/map_live/index.ex | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/aprsme_web/live/map_live/index.ex b/lib/aprsme_web/live/map_live/index.ex index a21afea..018b473 100644 --- a/lib/aprsme_web/live/map_live/index.ex +++ b/lib/aprsme_web/live/map_live/index.ex @@ -108,6 +108,8 @@ defmodule AprsmeWeb.MapLive.Index do Phoenix.PubSub.subscribe(Aprsme.PubSub, "bad_packets") Process.send_after(self(), :cleanup_old_packets, 60_000) + # Schedule UI update timer to refresh "time ago" display every 30 seconds + Process.send_after(self(), :update_time_display, 30_000) socket |> assign(:spatial_client_id, client_id) @@ -656,6 +658,8 @@ defmodule AprsmeWeb.MapLive.Index do def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket) + def handle_info(:update_time_display, socket), do: handle_update_time_display(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) @@ -1405,6 +1409,15 @@ defmodule AprsmeWeb.MapLive.Index do {:noreply, assign(socket, packet_state: updated_packet_state)} end + defp handle_update_time_display(socket) do + # Schedule next update + Process.send_after(self(), :update_time_display, 30_000) + + # Simply triggering a re-render will cause time_ago_in_words to recalculate + # No need to update any assigns, just return the socket + {:noreply, socket} + end + defp handle_reload_historical_packets(socket) do require Logger @@ -1670,8 +1683,6 @@ defmodule AprsmeWeb.MapLive.Index do socket |> assign(map_bounds: map_bounds, packet_state: updated_packet_state) |> assign(needs_initial_historical_load: false) - # Update last update timestamp when map bounds change - this triggers data refresh - |> assign(last_update_at: DateTime.utc_now()) # Load historical packets for the new bounds (now socket.assigns.map_bounds is correct) Logger.debug("Starting progressive historical loading for new bounds")