prop/lib/microwaveprop_web/live/user_profile_live.ex
Graham McIntire fc245367e3
User profiles at /u/:callsign, flexible band input, assorted UX cleanup
Profile page:
  * New MicrowavepropWeb.UserProfileLive at /u/:callsign is a public
    page showing a user's contacts and beacons. Resolves case-
    insensitively so /u/w5isp and /u/W5ISP are the same thing; unknown
    callsigns redirect to /. Uses daisyUI card / stats / table
    components with an avatar-placeholder initial and hero icons.
  * Accounts.get_user_by_callsign/1 (case-insensitive) plus
    Radio.list_contacts_for_user/1 and Beacons.list_beacons_for_user/1
    back the page. Beacons list includes both approved and pending so
    owners see their drafts.
  * The top nav bar and the three LiveView sidebars (MapLive,
    WeatherMapLive, ContactMapLive) now render the logged-in callsign
    as a navigate link to /u/:callsign instead of a static label.
  * Nine new tests cover the lookup, the LiveView render, and the
    ownership-scoped queries.

Flexible band input:
  * New Microwaveprop.Radio.BandResolver module converts any of:
    ADIF wavelength labels ("33cm", "1.25cm", "6mm", case/whitespace
    insensitive), numeric frequency strings ("903.100", "10368.000"),
    and canonical MHz integers into the one of the site's known bands.
    Returns the nearest allowed band for numeric inputs >= 900 MHz,
    nil otherwise.
  * 902 MHz is added to Contact.@allowed_bands, ContactEdit.@allowed_bands,
    AdifImport.@allowed_bands, and the BandResolver list so "33cm"
    round-trips end-to-end.
  * AdifImport and CsvImport now delegate band resolution to
    BandResolver, and Radio.create_contact/2 normalizes the :band attr
    on the way in so the manual form and any API callers benefit too.
    CsvImport's "invalid band" tests previously used 99999 MHz which
    the new resolver snaps to the nearest allowed band; swapped to
    "notaband" which is truly unresolvable.

Contacts and beacons list UX:
  * Remove the "Submitted" column from /contacts — it duplicated info
    already visible on the detail page and was pushing the real
    columns off narrow viewports. submitted_cell/1 and its three
    column-specific tests go with it.
  * Hide the Lat / Lon columns from /beacons — six decimal places of
    coordinates weren't useful next to the grid square and took a
    disproportionate amount of row width.
2026-04-12 16:13:08 -05:00

170 lines
5.9 KiB
Elixir

defmodule MicrowavepropWeb.UserProfileLive do
@moduledoc false
use MicrowavepropWeb, :live_view
alias Microwaveprop.Accounts
alias Microwaveprop.Beacons
alias Microwaveprop.Beacons.Beacon
alias Microwaveprop.Radio
@impl true
def mount(%{"callsign" => raw_callsign}, _session, socket) do
case Accounts.get_user_by_callsign(raw_callsign) do
nil ->
{:ok,
socket
|> put_flash(:error, "No profile for #{raw_callsign}.")
|> push_navigate(to: ~p"/")}
user ->
contacts = Radio.list_contacts_for_user(user)
beacons = Beacons.list_beacons_for_user(user)
{:ok,
assign(socket,
page_title: user.callsign,
profile: user,
contacts: contacts,
beacons: beacons
)}
end
end
defp initial(%{name: name}) when is_binary(name) and name != "" do
name |> String.trim() |> String.first() |> String.upcase()
end
defp initial(%{callsign: callsign}) when is_binary(callsign), do: callsign |> String.first() |> String.upcase()
defp initial(_), do: "?"
@impl true
def render(assigns) do
~H"""
<Layouts.app flash={@flash} current_scope={@current_scope} max_width="max-w-5xl">
<div class="card bg-base-200 shadow-sm mb-6">
<div class="card-body flex-row items-center gap-4 py-5">
<div class="avatar placeholder">
<div class="bg-primary text-primary-content rounded-full w-16">
<span class="text-2xl font-mono">{initial(@profile)}</span>
</div>
</div>
<div class="flex-1 min-w-0">
<h1 class="card-title font-mono text-2xl">{@profile.callsign}</h1>
<p class="text-sm opacity-70">
<span :if={@profile.name}>{@profile.name} &middot;</span>
Member since {Calendar.strftime(@profile.inserted_at, "%B %Y")}
</p>
</div>
</div>
</div>
<div class="stats bg-base-200 shadow-sm mb-6 w-full">
<div class="stat">
<div class="stat-figure text-primary">
<.icon name="hero-radio" class="w-8 h-8" />
</div>
<div class="stat-title">Contacts submitted</div>
<div class="stat-value text-primary">{length(@contacts)}</div>
</div>
<div class="stat">
<div class="stat-figure text-secondary">
<.icon name="hero-signal" class="w-8 h-8" />
</div>
<div class="stat-title">Beacons submitted</div>
<div class="stat-value text-secondary">{length(@beacons)}</div>
</div>
</div>
<div class="card bg-base-200 shadow-sm mb-6">
<div class="card-body">
<h2 class="card-title">Contacts</h2>
<%= if @contacts == [] do %>
<div class="alert">
<.icon name="hero-information-circle" class="w-5 h-5" />
<span>No contacts submitted yet.</span>
</div>
<% else %>
<div class="overflow-x-auto">
<table class="table table-zebra table-sm">
<thead>
<tr>
<th>When</th>
<th>Stations</th>
<th>Band</th>
<th>Mode</th>
<th>Distance</th>
</tr>
</thead>
<tbody>
<tr :for={contact <- @contacts} class="hover">
<td class="whitespace-nowrap">
{Calendar.strftime(contact.qso_timestamp, "%Y-%m-%d %H:%M UTC")}
</td>
<td>
<.link navigate={~p"/contacts/#{contact.id}"} class="link link-hover font-mono">
{contact.station1} &harr; {contact.station2}
</.link>
</td>
<td>{contact.band && "#{contact.band} MHz"}</td>
<td>{contact.mode}</td>
<td>{contact.distance_km && "#{contact.distance_km} km"}</td>
</tr>
</tbody>
</table>
</div>
<% end %>
</div>
</div>
<div class="card bg-base-200 shadow-sm">
<div class="card-body">
<h2 class="card-title">Beacons</h2>
<%= if @beacons == [] do %>
<div class="alert">
<.icon name="hero-information-circle" class="w-5 h-5" />
<span>No beacons submitted yet.</span>
</div>
<% else %>
<div class="overflow-x-auto">
<table class="table table-zebra table-sm">
<thead>
<tr>
<th>Callsign</th>
<th>Frequency</th>
<th>Grid</th>
<th>Keying</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr :for={beacon <- @beacons} class="hover">
<td>
<.link navigate={~p"/beacons/#{beacon.id}"} class="link link-hover font-mono">
{beacon.callsign}
</.link>
</td>
<td class="whitespace-nowrap">
{Beacon.format_freq(beacon.frequency_mhz)} MHz
</td>
<td>{beacon.grid}</td>
<td>{Beacon.keying_label(beacon.keying)}</td>
<td>
<div class={[
"badge badge-sm",
if(beacon.approved, do: "badge-success", else: "badge-warning")
]}>
{if beacon.approved, do: "Approved", else: "Pending"}
</div>
</td>
</tr>
</tbody>
</table>
</div>
<% end %>
</div>
</div>
</Layouts.app>
"""
end
end