Commit graph

1 commit

Author SHA1 Message Date
Roland
20d2bb8717
Add PWA: installable app, offline calculators, read-only Inventory
Make the React app an installable PWA whose app shell, calculators
(incl. the One Time Pad), and Inventory work offline. Driving use case:
reference an inventory (e.g. Fasteners) from an iPhone with no connection.

Phase 1 — service worker (Workbox InjectManifest, production build only):
- service-worker.js: precache the shell (calculators work offline),
  NavigationRoute for deep links, NetworkFirst cache of GET /api/inventory
  and /api/inventory/catalog (wrolpi-inventory), NetworkOnly /api/status.
- serviceWorkerRegistration.js + registration in index.js.
- Add workbox-* runtime deps (pinned 6.5.4 to match CRA's bundled plugin).

Phase 2 — offline hardening + read-only Inventory:
- api.js maps offline fetch failures (TypeError / timeout / !navigator.onLine)
  to ApiDownError so the existing nav apiDown indicator lights up.
- toast.js wrapper swallows error toasts while offline; repoint the toast
  import in the 13 files that raise them (App.js container left as-is).
- PwaContext (usePwa() -> {offline, isStandalone}), provider mounted in
  App.js inside StatusProvider. Default offline:false so components render
  without the provider in tests.
- Inventory is read-only offline: InventoryRoute disables the edit buttons
  and shows a banner; InventoryTable hides the new-item row, checkboxes and
  delete, and disables click-to-edit. Values stay visible for reference.

Phase 3 — iOS Add-to-Home-Screen meta tags in public/index.html.

Verified end-to-end against the real API: SW caches the inventory, then with
the origin stopped the cached inventory still renders read-only (reactively
and on cold reload). All 676 Jest tests pass (incl. new InventoryTable
offline tests).

Media "Save for offline" + a Downloads list are intentionally deferred.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 15:21:25 -06:00