Paginate the shipments list

Angular · Angular · beginner · modification

Moves the shipments screen off the load-everything endpoint onto the paged API. The component keeps a zero-based page index for the pager math, tracks an in-flight flag so the buttons can't double-fire, and shows the human page number in the label. Paged back and forth on the staging account and the list updates as expected.

Ops accounts hold thousands of shipments, which is why the endpoint was paginated; typical accounts span dozens of pages.

Requirements

Files touched

--- src/app/shipments/shipment-list.component.ts
 import { Component, OnInit, inject, signal } from '@angular/core';
-import { Shipment, ShipmentsService } from './shipments.service';
+import { ShipmentPage, ShipmentsService } from './shipments.service';
 
 @Component({
   template: `
     <ul class="shipments">
-      @for (shipment of shipments(); track shipment.id) {
+      @for (shipment of page()?.items ?? []; track shipment.id) {
         <li>{{ shipment.reference }} — {{ shipment.status }}</li>
       }
     </ul>
+    <nav class="pager">
+      <button (click)="goTo(pageIndex() - 1)" [disabled]="loading() || pageIndex() === 0">
+        Prev
+      </button>
+      <span>Page {{ pageIndex() + 1 }} of {{ page()?.totalPages ?? 1 }}</span>
+      <button
+        (click)="goTo(pageIndex() + 1)"
+        [disabled]="loading() || pageIndex() + 1 >= (page()?.totalPages ?? 1)"
+      >
+        Next
+      </button>
+    </nav>
   `,
 })
   private service = inject(ShipmentsService);
 
-  protected shipments = signal<Shipment[]>([]);

Review this PR

Angular practice