register PWA and fix css in prod
This commit is contained in:
parent
7c161ecd89
commit
9b14798539
8 changed files with 160 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ Timetracker is a time tracking application for a German fire brigade. It consist
|
|||
- manual editing of personal entries and personal statistics
|
||||
- admin dashboard with member statistics, function statistics, and PDF export
|
||||
- admin management for trackable functions
|
||||
- installable PWA with offline app-shell caching
|
||||
|
||||
## Project structure
|
||||
|
||||
|
|
@ -115,6 +116,12 @@ yarn build
|
|||
|
||||
This writes the SPA bundle to `frontend/dist`.
|
||||
|
||||
The frontend is packaged as a Progressive Web App with:
|
||||
|
||||
- `manifest.webmanifest` for install metadata
|
||||
- SVG app icons and favicon
|
||||
- a service worker that caches the app shell and static assets for offline startup
|
||||
|
||||
### Backend
|
||||
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@
|
|||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<meta name="theme-color" content="#101820" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Timetracker" />
|
||||
<title>Timetracker</title>
|
||||
<meta
|
||||
name="description"
|
||||
|
|
|
|||
24
frontend/public/manifest.webmanifest
Normal file
24
frontend/public/manifest.webmanifest
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "Timetracker",
|
||||
"short_name": "Timetracker",
|
||||
"description": "OIDC based time tracking and statistics for fire brigades.",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#101820",
|
||||
"theme_color": "#101820",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/pwa-192.svg",
|
||||
"sizes": "192x192",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any maskable"
|
||||
},
|
||||
{
|
||||
"src": "/pwa-512.svg",
|
||||
"sizes": "512x512",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
23
frontend/public/pwa-192.svg
Normal file
23
frontend/public/pwa-192.svg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 192" role="img" aria-labelledby="title desc">
|
||||
<title id="title">Timetracker App Icon</title>
|
||||
<desc id="desc">Shield and clock icon for the Timetracker progressive web app.</desc>
|
||||
<rect width="192" height="192" rx="44" fill="#101820" />
|
||||
<defs>
|
||||
<linearGradient id="shieldGradient" x1="36" y1="22" x2="156" y2="170" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#F4511E" />
|
||||
<stop offset="1" stop-color="#B71C1C" />
|
||||
</linearGradient>
|
||||
<linearGradient id="dialGradient" x1="62" y1="56" x2="130" y2="124" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFF7E8" />
|
||||
<stop offset="1" stop-color="#F4DFC0" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<path d="M96 18 149 39v42c0 38.2-21.7 67.8-53 85-31.3-17.2-53-46.8-53-85V39l53-21Z" fill="url(#shieldGradient)" />
|
||||
<path d="M96 32 136 48v32.8c0 27.9-15.2 50.4-40 65.4-24.8-15-40-37.5-40-65.4V48l40-16Z" fill="none" stroke="rgba(255,255,255,0.26)" stroke-width="5" />
|
||||
<circle cx="96" cy="82" r="34" fill="url(#dialGradient)" />
|
||||
<circle cx="96" cy="82" r="27" fill="none" stroke="#7A1C1C" stroke-opacity=".22" stroke-width="4" />
|
||||
<path d="M96 65v18l13 8" fill="none" stroke="#17212A" stroke-linecap="round" stroke-linejoin="round" stroke-width="8" />
|
||||
<circle cx="96" cy="82" r="4.5" fill="#17212A" />
|
||||
<path d="M96 48v9M130 82h-9M96 116v-9M62 82h9" fill="none" stroke="#7A1C1C" stroke-linecap="round" stroke-width="5" />
|
||||
<path d="M72 136h48" fill="none" stroke="#F9A825" stroke-linecap="round" stroke-width="8" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
23
frontend/public/pwa-512.svg
Normal file
23
frontend/public/pwa-512.svg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" role="img" aria-labelledby="title desc">
|
||||
<title id="title">Timetracker App Icon</title>
|
||||
<desc id="desc">Shield and clock icon for the Timetracker progressive web app.</desc>
|
||||
<rect width="512" height="512" rx="120" fill="#101820" />
|
||||
<defs>
|
||||
<linearGradient id="shieldGradient" x1="96" y1="58" x2="416" y2="450" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#F4511E" />
|
||||
<stop offset="1" stop-color="#B71C1C" />
|
||||
</linearGradient>
|
||||
<linearGradient id="dialGradient" x1="165" y1="150" x2="347" y2="332" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#FFF7E8" />
|
||||
<stop offset="1" stop-color="#F4DFC0" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<path d="M256 48 398 104v112c0 102.5-58 181.7-142 227-84-45.3-142-124.5-142-227V104l142-56Z" fill="url(#shieldGradient)" />
|
||||
<path d="M256 86 364 129v88c0 74.6-41.2 135-108 175-66.8-40-108-100.4-108-175v-88l108-43Z" fill="none" stroke="rgba(255,255,255,0.26)" stroke-width="13" />
|
||||
<circle cx="256" cy="219" r="92" fill="url(#dialGradient)" />
|
||||
<circle cx="256" cy="219" r="73" fill="none" stroke="#7A1C1C" stroke-opacity=".22" stroke-width="10" />
|
||||
<path d="M256 174v48l35 21" fill="none" stroke="#17212A" stroke-linecap="round" stroke-linejoin="round" stroke-width="22" />
|
||||
<circle cx="256" cy="219" r="12" fill="#17212A" />
|
||||
<path d="M256 129v24M346 219h-24M256 309v-24M166 219h24" fill="none" stroke="#7A1C1C" stroke-linecap="round" stroke-width="13" />
|
||||
<path d="M191 366h130" fill="none" stroke="#F9A825" stroke-linecap="round" stroke-width="21" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
68
frontend/public/sw.js
Normal file
68
frontend/public/sw.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
const CACHE_NAME = "timetracker-pwa-v1";
|
||||
const APP_SHELL = ["/", "/manifest.webmanifest", "/logo.svg", "/pwa-192.svg", "/pwa-512.svg"];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)).then(() => self.skipWaiting())
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) =>
|
||||
Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key)))
|
||||
)
|
||||
.then(() => self.clients.claim())
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const { request } = event;
|
||||
|
||||
if (request.method !== "GET") {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.origin !== self.location.origin) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.mode === "navigate") {
|
||||
event.respondWith(
|
||||
fetch(request)
|
||||
.then((response) => {
|
||||
const copy = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put("/", copy));
|
||||
return response;
|
||||
})
|
||||
.catch(() => caches.match(request).then((cached) => cached || caches.match("/")))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
url.pathname.startsWith("/assets/") ||
|
||||
url.pathname === "/manifest.webmanifest" ||
|
||||
url.pathname === "/logo.svg" ||
|
||||
url.pathname === "/pwa-192.svg" ||
|
||||
url.pathname === "/pwa-512.svg"
|
||||
) {
|
||||
event.respondWith(
|
||||
caches.match(request).then((cached) => {
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
return fetch(request).then((response) => {
|
||||
const copy = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
|
||||
return response;
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
@ -8,3 +8,11 @@ ReactDOM.createRoot(document.getElementById("root")).render(
|
|||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("/sw.js").catch((error) => {
|
||||
console.error("Service worker registration failed", error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ export default defineConfig(({ mode }) => {
|
|||
}
|
||||
},
|
||||
build: {
|
||||
outDir: "dist"
|
||||
outDir: "dist",
|
||||
cssMinify: false
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue