feat(pwa): offline support so the list works in-store with no net

No signal inside the store made the server-rendered app unusable. Make it
an installable PWA:
- service worker (static/sw.js) caches pages (network-first, cache fallback)
  and assets, served from root so scope is /
- offline.js: cittiFetch() queues check-off / price / qty / pick POSTs in
  localStorage when offline and replays them in order on reconnect, with an
  optimistic response and an Offline/Syncing status badge
- manifest + icon for add-to-home-screen; PWA meta tags on the in-store pages
- in-store mutations (saveToServer, pick/unpick) go through cittiFetch;
  archive/refresh/add still need net by design
- Dockerfile copies static/
Open once online first so the SW can cache; then it works offline.
This commit is contained in:
Henrik Jess Nielsen
2026-10-30 11:54:38 +01:00
parent 1dec3b7bd8
commit b640d9950c
9 changed files with 206 additions and 3 deletions

View File

@@ -3,6 +3,13 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#c84b2f">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="Citti">
<link rel="manifest" href="/manifest.webmanifest">
<link rel="apple-touch-icon" href="/icon.svg">
<link rel="icon" href="/icon.svg">
<script src="/offline.js" defer></script>
<title>Citti Indkøbsseddel — Uge 23-25</title>
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
@@ -502,7 +509,7 @@ function saveToServer(key, price, checked) {
const row = document.querySelector(`.item-row[data-key="${key}"]`);
const qtyInput = row ? row.querySelector('.item-qty input') : null;
const qty = qtyInput ? qtyInput.value.trim() || null : null;
fetch('/api/price', {
(window.cittiFetch || fetch)('/api/price', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({key, price, checked, qty})
@@ -680,7 +687,7 @@ function toggleOffer(cb) {
}
async function removeOffer(id) {
await fetch('/api/offers/pick', {
await (window.cittiFetch || fetch)('/api/offers/pick', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({id, picked: false})