From 15d6284602c4f080a95f7635d1ad48edb2ecc0fe Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 2 Aug 2026 12:50:51 -0500 Subject: [PATCH] refactor: extract shared admin_links component, add to map sidebar --- lib/microwaveprop_web/components/layouts.ex | 69 ++++++++++++--------- lib/microwaveprop_web/live/map_live.ex | 10 +++ 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/lib/microwaveprop_web/components/layouts.ex b/lib/microwaveprop_web/components/layouts.ex index 8d313029..2ec65078 100644 --- a/lib/microwaveprop_web/components/layouts.ex +++ b/lib/microwaveprop_web/components/layouts.ex @@ -74,12 +74,7 @@ defmodule MicrowavepropWeb.Layouts do tabindex="0" class="dropdown-content menu bg-base-100 rounded-box z-[1] w-44 p-2 shadow-lg" > -
  • <.link href="/admin/dashboard">Dashboard
  • -
  • <.link navigate="/users">Users
  • -
  • <.link navigate="/admin/beacon-monitors">Beacon monitors
  • -
  • <.link navigate="/admin/contact-edits">Contact edits
  • -
  • <.link navigate="/status">Status
  • -
  • <.link href="/admin/oban">Oban
  • + <.admin_links variant={:dropdown} /> <%= if @current_scope && @current_scope.user do %> @@ -173,30 +168,7 @@ defmodule MicrowavepropWeb.Layouts do
    Admin
    - <.link - href="/admin/dashboard" - class="block px-3 py-2.5 rounded-lg hover:bg-base-200 transition-colors text-sm font-medium" - >Dashboard - <.link - navigate="/users" - class="block px-3 py-2.5 rounded-lg hover:bg-base-200 transition-colors text-sm font-medium" - >Users - <.link - navigate="/admin/beacon-monitors" - class="block px-3 py-2.5 rounded-lg hover:bg-base-200 transition-colors text-sm font-medium" - >Beacon monitors - <.link - navigate="/admin/contact-edits" - class="block px-3 py-2.5 rounded-lg hover:bg-base-200 transition-colors text-sm font-medium" - >Contact edits - <.link - navigate="/status" - class="block px-3 py-2.5 rounded-lg hover:bg-base-200 transition-colors text-sm font-medium" - >Status - <.link - href="/admin/oban" - class="block px-3 py-2.5 rounded-lg hover:bg-base-200 transition-colors text-sm font-medium" - >Oban + <.admin_links variant={:mobile} />
    <%= if @current_scope && @current_scope.user do %> @@ -420,4 +392,41 @@ defmodule MicrowavepropWeb.Layouts do """ end + + @doc """ + Renders admin navigation links. Use `variant` to control markup for each context: + + * `:dropdown` — `
  • ` items for daisyUI dropdown menus + * `:mobile` — styled block links for the mobile hamburger menu + * `:sidebar` — `
  • ` items for daisyUI menu lists (map sidebar) + """ + attr :variant, :atom, default: :dropdown, values: [:dropdown, :mobile, :sidebar] + + @spec admin_links(assigns :: map()) :: Rendered.t() + def admin_links(assigns) do + ~H""" + <%= for link <- [ + %{label: "Dashboard", href: "/admin/dashboard"}, + %{label: "Users", navigate: "/users"}, + %{label: "Beacon monitors", navigate: "/admin/beacon-monitors"}, + %{label: "Contact edits", navigate: "/admin/contact-edits"}, + %{label: "Status", navigate: "/status"}, + %{label: "Oban", href: "/admin/oban"} + ] do %> + <%= if @variant == :dropdown do %> +
  • <.link navigate={link[:navigate]} href={link[:href]}>{link.label}
  • + <% end %> + <%= if @variant == :mobile do %> + <.link + navigate={link[:navigate]} + href={link[:href]} + class="block px-3 py-2.5 rounded-lg hover:bg-base-200 transition-colors text-sm font-medium" + >{link.label} + <% end %> + <%= if @variant == :sidebar do %> +
  • <.link navigate={link[:navigate]} href={link[:href]}>{link.label}
  • + <% end %> + <% end %> + """ + end end diff --git a/lib/microwaveprop_web/live/map_live.ex b/lib/microwaveprop_web/live/map_live.ex index b1d18b80..946604ec 100644 --- a/lib/microwaveprop_web/live/map_live.ex +++ b/lib/microwaveprop_web/live/map_live.ex @@ -3,6 +3,8 @@ defmodule MicrowavepropWeb.MapLive do use MicrowavepropWeb, :live_view use LiveStash, stored_keys: [:selected_band, :selected_time] + import MicrowavepropWeb.Layouts, only: [admin_links: 1] + alias Microwaveprop.Propagation alias Microwaveprop.Propagation.BandConfig alias Microwaveprop.Propagation.PipelineStatus @@ -995,6 +997,14 @@ defmodule MicrowavepropWeb.MapLive do + <%!-- Admin --%> + + <%!-- Auth --%>