feat(contacts): show total contact count in list header

This commit is contained in:
Graham McIntire 2026-04-17 13:08:35 -05:00
parent 24eebcea63
commit 48cbf40b9d
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
2 changed files with 29 additions and 2 deletions

View file

@ -3,6 +3,9 @@ defmodule MicrowavepropWeb.ContactLive.Index do
use MicrowavepropWeb, :live_view use MicrowavepropWeb, :live_view
use LiveTable.LiveResource, schema: Microwaveprop.Radio.Contact use LiveTable.LiveResource, schema: Microwaveprop.Radio.Contact
alias Microwaveprop.Radio.Contact
alias Microwaveprop.Repo
def table_options do def table_options do
%{ %{
sorting: %{default_sort: [inserted_at: :desc]}, sorting: %{default_sort: [inserted_at: :desc]},
@ -45,7 +48,12 @@ defmodule MicrowavepropWeb.ContactLive.Index do
@impl true @impl true
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
{:ok, assign(socket, :page_title, "Contacts")} total = Repo.aggregate(Contact, :count, :id)
{:ok,
socket
|> assign(:page_title, "Contacts")
|> assign(:total_contacts, total)}
end end
@enrichment_fields [ @enrichment_fields [
@ -96,6 +104,14 @@ defmodule MicrowavepropWeb.ContactLive.Index do
defp flag_cell(_), do: "" defp flag_cell(_), do: ""
defp format_count(n) when is_integer(n) do
n
|> Integer.to_string()
|> String.reverse()
|> String.replace(~r/(\d{3})(?=\d)/, "\\1,")
|> String.reverse()
end
defp format_ts(nil), do: "" defp format_ts(nil), do: ""
defp format_ts(%DateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M") defp format_ts(%DateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M")
defp format_ts(%NaiveDateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M") defp format_ts(%NaiveDateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M")
@ -107,7 +123,9 @@ defmodule MicrowavepropWeb.ContactLive.Index do
<Layouts.app flash={@flash} current_scope={@current_scope} max_width="max-w-7xl"> <Layouts.app flash={@flash} current_scope={@current_scope} max_width="max-w-7xl">
<.header> <.header>
Contacts Contacts
<:subtitle>Sort or search by callsign, grid, or mode.</:subtitle> <:subtitle>
{format_count(@total_contacts)} total sort or search by callsign, grid, or mode.
</:subtitle>
<:actions> <:actions>
<.link navigate={~p"/submit"} class="btn btn-primary"> <.link navigate={~p"/submit"} class="btn btn-primary">
<.icon name="hero-plus" class="w-5 h-5" /> Submit Contact <.icon name="hero-plus" class="w-5 h-5" /> Submit Contact

View file

@ -55,6 +55,15 @@ defmodule MicrowavepropWeb.ContactLiveTest do
assert html =~ "Contacts" assert html =~ "Contacts"
end end
test "shows total contact count in subtitle", %{conn: conn} do
create_contact()
create_contact(%{station1: "N5AC"})
create_contact(%{station1: "K5TR"})
{:ok, _lv, html} = live(conn, ~p"/contacts")
assert html =~ "3 total"
end
test "table shows contact data", %{conn: conn} do test "table shows contact data", %{conn: conn} do
create_contact() create_contact()