feat: convert app to PWA with offline support and service worker
This commit is contained in:
@@ -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 />
|
||||
|
||||
22
components/providers/SWRegistration.tsx
Normal file
22
components/providers/SWRegistration.tsx
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user