diff --git a/lib/microwaveprop_web/live/beacon_live/show.ex b/lib/microwaveprop_web/live/beacon_live/show.ex index afde66cc..9ea631f9 100644 --- a/lib/microwaveprop_web/live/beacon_live/show.ex +++ b/lib/microwaveprop_web/live/beacon_live/show.ex @@ -60,14 +60,21 @@ defmodule MicrowavepropWeb.BeaconLive.Show do
-
@@ -161,17 +168,28 @@ defmodule MicrowavepropWeb.BeaconLive.Show do |> assign(:page_title, "Beacon") |> assign(:beacon, beacon) |> assign(:show_coverage, false) + |> assign(:coverage_supported, coverage_supported?(beacon)) |> assign(:estimate, RangeEstimate.estimate(beacon))} end + # Estimated current coverage only makes sense from 5.76 GHz upward, + # where atmospheric attenuation meaningfully shapes the reach. Below + # that the free-space-loss-dominated map is misleading. + defp coverage_supported?(%{frequency_mhz: mhz}) when is_number(mhz), do: mhz >= 5760 + defp coverage_supported?(_), do: false + @impl true def handle_event("toggle_coverage", _params, socket) do - show = not socket.assigns.show_coverage + if socket.assigns.coverage_supported do + show = not socket.assigns.show_coverage - {:noreply, - socket - |> assign(:show_coverage, show) - |> push_event("toggle_coverage", %{show: show})} + {:noreply, + socket + |> assign(:show_coverage, show) + |> push_event("toggle_coverage", %{show: show})} + else + {:noreply, socket} + end end def handle_event("approve", _params, socket) do @@ -189,9 +207,13 @@ defmodule MicrowavepropWeb.BeaconLive.Show do @impl true def handle_info({:updated, %Beacon{id: id} = beacon}, %{assigns: %{beacon: %{id: id}}} = socket) do + supported = coverage_supported?(beacon) + {:noreply, socket |> assign(:beacon, beacon) + |> assign(:coverage_supported, supported) + |> assign(:show_coverage, socket.assigns.show_coverage and supported) |> assign(:estimate, RangeEstimate.estimate(beacon))} end