mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-22 20:52:18 +00:00
feat: Add service worker with offline support and route caching to web dashboard
- Add offline.html fallback page with gradient background, centered container, and retry button - Add sw.js service worker with telecom-dashboard-v1 cache for dashboard routes - Add install event handler caching /, /login, /dashboard, /services, /monitoring, /deploy, /plugins, /automation, /chaos, /billing, and /config routes - Add fetch event handler with cache-first strategy and offline.html fallback - Add activate event
This commit is contained in:
@@ -4,6 +4,7 @@ import "./globals.css";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Sidebar } from "@/components/sidebar";
|
||||
import { Providers } from "./providers";
|
||||
import { ServiceWorkerRegistration } from "@/components/service-worker-registration";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"], variable: "--font-sans" });
|
||||
|
||||
@@ -34,6 +35,7 @@ export default function RootLayout({
|
||||
>
|
||||
<body className="min-h-full flex">
|
||||
<Providers>
|
||||
<ServiceWorkerRegistration />
|
||||
<Sidebar />
|
||||
<main className="flex-1 overflow-auto">{children}</main>
|
||||
</Providers>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function ServiceWorkerRegistration() {
|
||||
useEffect(() => {
|
||||
if ("serviceWorker" in navigator && process.env.NEXT_PUBLIC_ENABLE_SW === "true") {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker
|
||||
.register("/sw.js")
|
||||
.then((registration) => {
|
||||
console.log("Service Worker registered: ", registration);
|
||||
})
|
||||
.catch((registrationError) => {
|
||||
console.log("Service Worker registration failed: ", registrationError);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user