add pagination across all admin and shop views
All checks were successful
deploy / deploy (push) Successful in 1m38s

URL-based offset pagination with ?page=N for bookmarkable pages.
Admin views use push_patch, shop collection uses navigate links.
Responsive on mobile with horizontal-scroll tables and stacking
pagination controls. Includes dev seed script for testing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-03-01 09:42:34 +00:00
parent 7f6fd012a5
commit 3480b326a9
21 changed files with 1485 additions and 211 deletions

View File

@@ -7,32 +7,38 @@ defmodule BerrypodWeb.Admin.Orders do
@impl true
def mount(_params, _session, socket) do
counts = Orders.count_orders_by_status()
orders = Orders.list_orders()
socket =
socket
|> assign(:page_title, "Orders")
|> assign(:status_filter, "all")
|> assign(:status_counts, counts)
|> assign(:order_count, length(orders))
|> stream(:orders, orders)
{:ok, socket}
end
@impl true
def handle_event("filter", %{"status" => status}, socket) do
orders = Orders.list_orders(status: status)
def handle_params(params, _uri, socket) do
page_num = Berrypod.Pagination.parse_page(params)
page = Orders.list_orders_paginated(status: socket.assigns.status_filter, page: page_num)
socket =
socket
|> assign(:status_filter, status)
|> assign(:order_count, length(orders))
|> stream(:orders, orders, reset: true)
|> assign(:pagination, page)
|> assign(:order_count, page.total_count)
|> stream(:orders, page.items, reset: true)
{:noreply, socket}
end
@impl true
def handle_event("filter", %{"status" => status}, socket) do
{:noreply,
socket
|> assign(:status_filter, status)
|> push_patch(to: ~p"/admin/orders")}
end
@impl true
def render(assigns) do
~H"""
@@ -90,6 +96,8 @@ defmodule BerrypodWeb.Admin.Orders do
</:col>
</.table>
<.admin_pagination :if={@order_count > 0} page={@pagination} patch={~p"/admin/orders"} />
<div :if={@order_count == 0} class="text-center py-12 text-base-content/60">
<.icon name="hero-inbox" class="size-12 mx-auto mb-4" />
<p class="text-lg font-medium">No orders yet</p>