-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReconnectionBanner.tsx
More file actions
31 lines (26 loc) · 868 Bytes
/
Copy pathReconnectionBanner.tsx
File metadata and controls
31 lines (26 loc) · 868 Bytes
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
'use client';
import { useEffect, useState } from 'react';
import { messages } from '@/i18n';
/**
* Non-intrusive banner shown while the WebSocket is disconnected. To avoid
* flashing during the brief initial connect, it only appears after a short
* grace period of being disconnected, and dismisses immediately on reconnect.
*/
export function ReconnectionBanner({ connected }: { connected: boolean }) {
const [visible, setVisible] = useState(false);
useEffect(() => {
if (connected) {
setVisible(false);
return;
}
const timer = setTimeout(() => setVisible(true), 800);
return () => clearTimeout(timer);
}, [connected]);
if (!visible) return null;
return (
<div className="conn-banner" role="status" aria-live="polite">
<span aria-hidden="true">⚠ </span>
{messages.connection.banner}
</div>
);
}