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

30
app.py
View File

@@ -646,6 +646,36 @@ def health():
return jsonify({'status': 'healthy', 'service': 'citti'})
# --- PWA / offline: served from root so the service worker scope is '/' -------
@app.route('/sw.js')
def service_worker():
resp = send_from_directory(app.static_folder, 'sw.js')
resp.headers['Service-Worker-Allowed'] = '/'
resp.headers['Cache-Control'] = 'no-cache'
resp.headers['Content-Type'] = 'application/javascript'
return resp
@app.route('/offline.js')
def offline_js():
resp = send_from_directory(app.static_folder, 'offline.js')
resp.headers['Content-Type'] = 'application/javascript'
return resp
@app.route('/manifest.webmanifest')
def manifest():
resp = send_from_directory(app.static_folder, 'manifest.webmanifest')
resp.headers['Content-Type'] = 'application/manifest+json'
return resp
@app.route('/icon.svg')
def icon():
return send_from_directory(app.static_folder, 'icon.svg')
@app.route('/api/category', methods=['POST'])
def add_category():
d = request.json