defmodule AmmopricesWeb.HomeLive do @moduledoc false use AmmopricesWeb, :live_view import AmmopricesWeb.PriceComponents alias Ammoprices.Catalog alias Ammoprices.Prices @categories [ %{id: "handgun", label: "Handgun", icon: "hero-bolt"}, %{id: "rifle", label: "Rifle", icon: "hero-signal"}, %{id: "rimfire", label: "Rimfire", icon: "hero-fire"}, %{id: "shotgun", label: "Shotgun", icon: "hero-shield-check"} ] @impl true def mount(_params, _session, socket) do calibers = Catalog.list_calibers() cheapest = Prices.cheapest_per_caliber() cheapest_map = Map.new(cheapest, fn r -> {r.caliber_id, r.min_ppr} end) grouped = calibers |> Enum.group_by(& &1.category) |> Map.new(fn {cat, cals} -> {cat, Enum.sort_by(cals, & &1.name)} end) {:ok, assign(socket, page_title: "Ammo Price Tracker", categories: @categories, calibers_by_category: grouped, cheapest_map: cheapest_map )} end @impl true def render(assigns) do ~H"""
<%!-- Hero --%>

Ammo Price Tracker

Real-time ammunition prices from top retailers. Find the cheapest rounds, track price history.

<%!-- Category grid --%>
<.icon name={cat.icon} class="w-5 h-5 text-primary" />

{cat.label}

<.link :for={cal <- Map.get(@calibers_by_category, cat.id, [])} navigate={~p"/calibers/#{cal.slug}"} id={"caliber-#{cal.slug}"} class="group flex items-center justify-between gap-2 px-3 py-2.5 rounded-lg border border-base-300 bg-base-100 hover:border-primary/40 hover:bg-primary/5 transition-all duration-150" > {cal.name} <.price_per_round cents={@cheapest_map[cal.id]} />
""" end end