aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/components/SyncButton.tsx
blob: 1ebfa2ea2664663aac075c5dcd3a99bd58b045ef (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
34
35
36
37
38
39
import { useSync } from "../stores";

export function SyncButton() {
	const { isOnline, isSyncing, sync } = useSync();

	const handleSync = async () => {
		await sync();
	};

	const isDisabled = !isOnline || isSyncing;

	const getButtonText = (): string => {
		if (isSyncing) {
			return "Syncing...";
		}
		return "Sync";
	};

	return (
		<button
			type="button"
			data-testid="sync-button"
			onClick={handleSync}
			disabled={isDisabled}
			title={!isOnline ? "Cannot sync while offline" : undefined}
			style={{
				padding: "0.25rem 0.5rem",
				borderRadius: "4px",
				border: "1px solid #dee2e6",
				backgroundColor: isDisabled ? "#e9ecef" : "#007bff",
				color: isDisabled ? "#6c757d" : "white",
				cursor: isDisabled ? "not-allowed" : "pointer",
				fontSize: "0.875rem",
			}}
		>
			{getButtonText()}
		</button>
	);
}