diff --git a/assets/js/map.ts b/assets/js/map.ts index adf1d13..07c7f86 100644 --- a/assets/js/map.ts +++ b/assets/js/map.ts @@ -1968,6 +1968,12 @@ let MapAPRSMap = { self.programmaticMoveTimeout = undefined; } + // Clear initialization timeout + if (self.initializationTimeout !== undefined) { + clearTimeout(self.initializationTimeout); + self.initializationTimeout = undefined; + } + // Clear any dimension check timeouts if (self.cleanupTimeouts !== undefined) { self.cleanupTimeouts.forEach((timeout: number) => { diff --git a/assets/js/types/map.d.ts b/assets/js/types/map.d.ts index 7267e95..5ab9cbf 100644 --- a/assets/js/types/map.d.ts +++ b/assets/js/types/map.d.ts @@ -36,6 +36,7 @@ export interface LiveViewHookContext { markerClusterGroup?: MarkerClusterGroup; cleanupTimeouts?: ReturnType[]; pendingMarkers?: MarkerData[]; + initializationTimeout?: ReturnType; } export interface MarkerData { diff --git a/lib/aprsme_web/live/map_live/components.ex b/lib/aprsme_web/live/map_live/components.ex index 37fa25a..72ad543 100644 --- a/lib/aprsme_web/live/map_live/components.ex +++ b/lib/aprsme_web/live/map_live/components.ex @@ -5,6 +5,8 @@ defmodule AprsmeWeb.MapLive.Components do """ use AprsmeWeb, :html + import AprsmeWeb.TimeHelpers, only: [time_ago_in_words: 1] + attr :flash, :map, default: %{} attr :slideover_open, :boolean, default: false attr :map_center, :map, required: true @@ -194,7 +196,7 @@ defmodule AprsmeWeb.MapLive.Components do <%= if @tracked_callsign_latest_packet do %>
- Last seen: {format_time_ago(@tracked_callsign_latest_packet.received_at)} + Last seen: {time_ago_in_words(@tracked_callsign_latest_packet.received_at)}
<% end %> @@ -235,7 +237,7 @@ defmodule AprsmeWeb.MapLive.Components do <% end %>
- via {@packet.path || "direct"} • {format_time_ago(@packet.received_at)} + via {@packet.path || "direct"} • {time_ago_in_words(@packet.received_at)}
<%= if @packet.has_position do %> @@ -256,18 +258,8 @@ defmodule AprsmeWeb.MapLive.Components do end # Helper functions - defp format_time_ago(datetime) do - # Implement time ago formatting - case DateTime.diff(DateTime.utc_now(), datetime, :second) do - seconds when seconds < 60 -> "#{seconds}s ago" - seconds when seconds < 3600 -> "#{div(seconds, 60)}m ago" - seconds when seconds < 86_400 -> "#{div(seconds, 3600)}h ago" - seconds -> "#{div(seconds, 86_400)}d ago" - end - end - defp format_coordinates(lat, lon) when is_number(lat) and is_number(lon) do - "#{Float.round(lat * 1.0, 4)}, #{Float.round(lon * 1.0, 4)}" + "#{Float.round(lat, 4)}, #{Float.round(lon, 4)}" end defp format_coordinates(_, _), do: "Unknown location" diff --git a/lib/aprsme_web/live/map_live/index.ex b/lib/aprsme_web/live/map_live/index.ex index f2a8d0e..912ee65 100644 --- a/lib/aprsme_web/live/map_live/index.ex +++ b/lib/aprsme_web/live/map_live/index.ex @@ -1007,8 +1007,8 @@ defmodule AprsmeWeb.MapLive.Index do ~H""" <.map_styles /> - <.map_container - slideover_open={@slideover_open} + <.map_container + slideover_open={@slideover_open} map_center={@map_center} map_zoom={@map_zoom} />