defmodule MicrowavepropWeb.MapLive do @moduledoc false use MicrowavepropWeb, :live_view alias Microwaveprop.Propagation alias Microwaveprop.Propagation.BandConfig @default_band 10_000 @refresh_interval_ms to_timeout(minute: 5) @impl true def mount(_params, _session, socket) do bands = BandConfig.all_bands() scores = Propagation.latest_scores(@default_band) valid_time = Propagation.latest_valid_time() if connected?(socket) do Process.send_after(self(), :refresh, @refresh_interval_ms) end {:ok, assign(socket, page_title: "Propagation Map", bands: bands, selected_band: @default_band, scores: scores, valid_time: valid_time )} end @impl true def handle_event("select_band", %{"value" => band_str}, socket) do band = String.to_integer(band_str) scores = Propagation.latest_scores(band) socket = socket |> assign(:selected_band, band) |> assign(:scores, scores) |> push_event("update_scores", %{scores: scores}) {:noreply, socket} end @impl true def handle_info(:refresh, socket) do scores = Propagation.latest_scores(socket.assigns.selected_band) valid_time = Propagation.latest_valid_time() Process.send_after(self(), :refresh, @refresh_interval_ms) socket = socket |> assign(:scores, scores) |> assign(:valid_time, valid_time) |> push_event("update_scores", %{scores: scores}) {:noreply, socket} end defp selected_label(bands, selected_band) do case Enum.find(bands, &(&1.freq_mhz == selected_band)) do nil -> "Select Band" band -> band.label end end @impl true def render(assigns) do ~H"""
<%!-- Full-page map --%>
<%!-- Top-left controls overlay --%>
<.link navigate="/" class="btn btn-sm bg-base-100/90 shadow border-base-300"> <.icon name="hero-home" class="size-4" />
{Calendar.strftime(@valid_time, "%H:%M UTC")}
""" end end