forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkStatus.js
More file actions
61 lines (52 loc) · 1.29 KB
/
Copy pathNetworkStatus.js
File metadata and controls
61 lines (52 loc) · 1.29 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useState, useEffect } from 'react';
export default function NetworkStatus() {
const [isOnline, setIsOnline] = useState(true);
const [showBanner, setShowBanner] = useState(false);
useEffect(() => {
setIsOnline(navigator.onLine);
const handleOnline = () => {
setIsOnline(true);
setShowBanner(true);
setTimeout(() => setShowBanner(false), 3000);
};
const handleOffline = () => {
setIsOnline(false);
setShowBanner(true);
};
window.addEventListener('online', handleOnline);
window.addEventListener('offline', handleOffline);
return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
};
}, []);
if (!showBanner) return null;
return (
<div style={{
...styles.banner,
backgroundColor: isOnline ? '#10b981' : '#ef4444',
}}>
<p style={styles.text}>
{isOnline ? '✓ Back online' : '⚠ You are offline'}
</p>
</div>
);
}
const styles = {
banner: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
padding: '0.75rem',
textAlign: 'center',
zIndex: 9999,
transition: 'all 0.3s ease',
},
text: {
margin: 0,
color: 'white',
fontSize: '0.875rem',
fontWeight: '500',
},
};