aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/components/OfflineBanner.tsx
blob: b33fc1472a08124cf2efa9a151d75c0a421da537 (plain)
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
import { faWifi } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useSync } from "../stores";

export function OfflineBanner() {
	const { isOnline, pendingCount } = useSync();

	if (isOnline) {
		return null;
	}

	return (
		<output
			data-testid="offline-banner"
			aria-live="polite"
			className="bg-slate text-white py-2 px-4 text-sm flex items-center justify-center gap-2"
		>
			<FontAwesomeIcon
				icon={faWifi}
				className="w-4 h-4 text-warning"
				aria-hidden="true"
			/>
			<span>
				You're offline. Changes will sync when you reconnect.
				{pendingCount > 0 && (
					<span data-testid="offline-pending-count" className="ml-1 opacity-80">
						({pendingCount} pending)
					</span>
				)}
			</span>
		</output>
	);
}