From 18c78e37a47d010871fc2e03b5240f666336db70 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Sun, 26 Jan 2025 17:21:30 +0100 Subject: [PATCH] In progress: offline fuel record creation --- TODO.md | 17 +++--- app/views/dashboard/index.php | 6 ++- public/css/global.css | 1 + public/js/offline-records.js | 98 +++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 public/js/offline-records.js diff --git a/TODO.md b/TODO.md index 42b1da9..a75f5a2 100644 --- a/TODO.md +++ b/TODO.md @@ -6,13 +6,10 @@ - [ ] edit user data - change password, mail... ## Core of the app -- [ ] header and navbar -- [ ] dashboard - - [x] css - - [ ] its just plain - - [ ] graphs -- [x] Habits list - - [ ] css -- [ ] Habits create - - [ ] validate cron input -- [ ] Habits track +- [ ] intro tutorial when no car exist or just dont show anything +- [ ] change/set default car +- [ ] specific car view - charts, fuel records +- [ ] remove/edit fuel record + +- [ ] IndexDB + - [ ] diff --git a/app/views/dashboard/index.php b/app/views/dashboard/index.php index 4d91474..4e8d959 100644 --- a/app/views/dashboard/index.php +++ b/app/views/dashboard/index.php @@ -5,6 +5,7 @@
Add new refuel record! List all vehicles +
@@ -43,8 +44,8 @@
- - + + diff --git a/public/css/global.css b/public/css/global.css index 12b07e7..357c3c0 100644 --- a/public/css/global.css +++ b/public/css/global.css @@ -27,6 +27,7 @@ h1 { cursor: pointer; border-radius: var(--border-radious); border: var(--borderWidth-thin) solid var(--clr-border); + color: white; } .btn-secondary { diff --git a/public/js/offline-records.js b/public/js/offline-records.js new file mode 100644 index 0000000..95b5744 --- /dev/null +++ b/public/js/offline-records.js @@ -0,0 +1,98 @@ +async function checkOnline() { + if (!navigator.onLine) { + console.log("Offline (no network connection)"); + return false; + } + + try { + const response = await fetch( + "https://www.google.com/favicon.ico?" + new Date().getTime(), + { + mode: "no-cors", + }, + ); + return true; + } catch (error) { + console.log("Connected to network but no internet access"); + return false; + } +} + +setInterval(async () => { + const isOnline = await checkOnline(); + if (!isOnline) { + console.log("OFFLINE!!!"); + } +}, 5000); + +const offbtn = document.querySelector("#btn-offline-add"); +offbtn.addEventListener("click", (e) => { + e.preventDefault(); + document.querySelector("section.dashboard").style.display = "none"; + const offline = document.createElement("div"); + offline.classList.add("offline"); + offline.innerHTML = ` + You're Offline +

You can create an fuel record locally on your device and sync it later

+
+

get('title') ?>

+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ `; + document.querySelector("main").appendChild(offline); +});