forked from Creditra/Creditra-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOfflineBanner.tsx
More file actions
43 lines (39 loc) · 1.16 KB
/
Copy pathOfflineBanner.tsx
File metadata and controls
43 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { useEffect, useState } from 'react';
import { useOnline } from '../hooks/useOnline';
import './OfflineBanner.css';
export function OfflineBanner() {
const { isOnline, checkOnlineStatus } = useOnline();
const [show, setShow] = useState(false);
useEffect(() => {
if (!isOnline) {
setShow(true);
} else if (show) {
// Hide after a brief delay when connection is restored
const timer = setTimeout(() => setShow(false), 3000);
return () => clearTimeout(timer);
}
}, [isOnline, show]);
if (!show && isOnline) return null;
return (
<div
className={`offline-banner ${isOnline ? 'offline-banner--restored' : ''}`}
role="alert"
aria-live="assertive"
>
<div className="offline-banner__content">
<span>
{isOnline ? 'Connection restored.' : 'You are currently offline. Actions will be queued.'}
</span>
{!isOnline && (
<button
onClick={checkOnlineStatus}
className="offline-banner__retry-button"
aria-label="Retry connection"
>
Retry
</button>
)}
</div>
</div>
);
}