diff --git a/lib/microwaveprop_web/live/pskr_spots_live.ex b/lib/microwaveprop_web/live/pskr_spots_live.ex index 5845db61..40d546ee 100644 --- a/lib/microwaveprop_web/live/pskr_spots_live.ex +++ b/lib/microwaveprop_web/live/pskr_spots_live.ex @@ -16,18 +16,35 @@ defmodule MicrowavepropWeb.PskrSpotsLive do _ = if connected?(socket), do: schedule_refresh() spots = fetch_recent_spots() + socket = start_async(socket, :total_spots, fn -> fetch_total_spots() end) + socket = start_async(socket, :band_counts, fn -> fetch_band_counts() end) {:ok, socket |> assign( page_title: "PSK Reporter Spots", limit: @limit, - total_spots: fetch_total_spots(), - band_counts: fetch_band_counts() + total_spots: nil, + band_counts: [], + spots_empty: spots == [] ) |> stream(:spots, spots, reset: true)} end + @impl true + def handle_async(:total_spots, {:ok, total}, socket) do + {:noreply, assign(socket, total_spots: total)} + end + + def handle_async(:band_counts, {:ok, counts}, socket) do + {:noreply, assign(socket, band_counts: counts)} + end + + def handle_async(slot, {:exit, reason}, socket) do + Logger.warning("PskrSpotsLive async #{slot} failed: #{inspect(reason)}") + {:noreply, socket} + end + @impl true def handle_info(:refresh_spots, socket) do _ = schedule_refresh() @@ -37,7 +54,8 @@ defmodule MicrowavepropWeb.PskrSpotsLive do socket |> assign( total_spots: fetch_total_spots(), - band_counts: fetch_band_counts() + band_counts: fetch_band_counts(), + spots_empty: spots == [] ) |> stream(:spots, spots, reset: true)} end @@ -112,13 +130,6 @@ defmodule MicrowavepropWeb.PskrSpotsLive do - - No spots yet - {fmt_dt(spot.last_spot_at)} {spot.band} @@ -141,7 +152,7 @@ defmodule MicrowavepropWeb.PskrSpotsLive do -

+

No PSK Reporter spots received yet. The MQTT listener is running — spots will appear here as they arrive.