49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
'use client';
|
|||
|
|
|
||
|
|
import { useEffect, useState } from 'react';
|
||
|
|
import { AlertCircle, RefreshCw } from 'lucide-react';
|
||
|
|
import { Button } from '@/components/ui/button';
|
||
|
|
|
||
|
|
export function NetworkErrorBanner() {
|
||
|
|
const [isOffline, setIsOffline] = useState(false);
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
const handleOffline = () => setIsOffline(true);
|
||
|
|
const handleOnline = () => setIsOffline(false);
|
||
|
|
|
||
|
|
window.addEventListener('offline', handleOffline);
|
||
|
|
window.addEventListener('online', handleOnline);
|
||
|
|
|
||
|
|
setIsOffline(!navigator.onLine);
|
||
|
|
|
||
|
|
return () => {
|
||
|
|
window.removeEventListener('offline', handleOffline);
|
||
|
|
window.removeEventListener('online', handleOnline);
|
||
|
|
};
|
||
|
|
}, []);
|
||
|
|
|
||
|
|
if (!isOffline) return null;
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div
|
||
|
|
className="fixed top-0 left-0 right-0 z-50 flex items-center justify-center gap-3 bg-destructive px-4 py-2 text-destructive-foreground shadow-lg"
|
||
|
|
role="alert"
|
||
|
|
aria-live="assertive"
|
||
|
|
>
|
||
|
|
<AlertCircle className="h-4 w-4" aria-hidden="true" />
|
||
|
|
<span className="text-sm font-medium">
|
||
|
|
You're offline. Some features may not work.
|
||
|
|
</span>
|
||
|
|
<Button
|
||
|
|
variant="ghost"
|
||
|
|
size="sm"
|
||
|
|
className="h-7 gap-1 px-2 text-xs"
|
||
|
|
onClick={() => window.location.reload()}
|
||
|
|
>
|
||
|
|
<RefreshCw className="h-3 w-3" aria-hidden="true" />
|
||
|
|
Retry
|
||
|
|
</Button>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|