mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Log flights offline: the form is kept by the service worker, flights queue on the device (IndexedDB) and send when back online; one-time keys prevent duplicates
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
08ba017c7e
commit
191eb030e8
14 files changed
+314
-14
No files matched your search
+5
-1
@@ -19,6 +19,7 @@
|
||||
img { width: 72px; height: 72px; }
|
||||
h1 { font-size: 1.25rem; margin: 16px 0 8px; }
|
||||
p { margin: 0 0 24px; color: var(--muted); }
|
||||
#forms a { display: block; margin-top: 8px; color: var(--accent); font-weight: 600; }
|
||||
button { font: inherit; font-weight: 600; color: #fff; background: var(--accent); border: 0; border-radius: 6px; padding: 10px 20px; cursor: pointer; }
|
||||
</style>
|
||||
</head>
|
||||
@@ -28,7 +29,10 @@
|
||||
<h1>You're offline</h1>
|
||||
<p>Simple Aircraft Manager needs a connection to load your aircraft. Check your signal and try again.</p>
|
||||
<button type="button" onclick="location.reload()">Try again</button>
|
||||
<div id="forms" hidden>
|
||||
<p style="margin:24px 0 8px">You can still log a flight; it's sent when you're back online:</p>
|
||||
</div>
|
||||
</main>
|
||||
<script>window.addEventListener("online", function () { location.reload() })</script>
|
||||
<script src="/offline.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,15 @@
|
||||
// The offline page: reload when the connection is back, and link to the Log
|
||||
// Flight forms this device has kept (so a flight can be logged offline).
|
||||
window.addEventListener("online", function () { location.reload() })
|
||||
try {
|
||||
var forms = JSON.parse(localStorage.getItem("sam-offline-forms") || "{}")
|
||||
var box = document.getElementById("forms")
|
||||
Object.keys(forms).forEach(function (path) {
|
||||
if (!/^\/aircraft\/\d+\/flight_logs\/new$/.test(path)) return
|
||||
var a = document.createElement("a")
|
||||
a.href = path
|
||||
a.textContent = "Log a flight: " + forms[path]
|
||||
box.appendChild(a)
|
||||
box.hidden = false
|
||||
})
|
||||
} catch (e) { /* storage off */ }
|
||||
Reference in new issue
Block a user