feat: convert app to PWA with offline support and service worker

This commit is contained in:
2026-02-26 18:01:33 +01:00
parent 1d72f34b65
commit f20cedffd5
5 changed files with 129 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import { Toaster } from 'sonner';
import { useState } from 'react';
import { ThemeProvider } from './ThemeProvider';
import { TooltipProvider } from '@/components/ui/tooltip';
import { SWRegistration } from './SWRegistration';
export function Providers({ children }: { children: React.ReactNode }) {
const [queryClient] = useState(
@@ -23,6 +24,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
<ThemeProvider>
<QueryClientProvider client={queryClient}>
<TooltipProvider>
<SWRegistration />
{children}
</TooltipProvider>
<Toaster position="top-right" richColors />

View File

@@ -0,0 +1,22 @@
'use client';
import { useEffect } from 'react';
export function SWRegistration() {
useEffect(() => {
if ('serviceWorker' in navigator && process.env.NODE_ENV === 'production') {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/sw.js')
.then((registration) => {
console.log('SW registered:', registration);
})
.catch((error) => {
console.log('SW registration failed:', error);
});
});
}
}, []);
return null;
}