forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse-sync-coordinator.ts
More file actions
41 lines (34 loc) · 956 Bytes
/
Copy pathuse-sync-coordinator.ts
File metadata and controls
41 lines (34 loc) · 956 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
32
33
34
35
36
37
38
39
40
41
import { useState, useEffect } from 'react';
import { syncCoordinator, type SyncStatus } from '../lib/sync-coordinator';
/**
* Hook to access sync coordinator status and trigger sync operations
* Provides reactive updates when sync status changes
*/
export function useSyncCoordinator() {
const [status, setStatus] = useState<SyncStatus>(syncCoordinator.getStatus());
useEffect(() => {
const unsubscribe = syncCoordinator.subscribe((newStatus) => {
setStatus(newStatus);
});
return unsubscribe;
}, []);
const triggerSync = async () => {
await syncCoordinator.triggerSync();
};
const getHistory = async () => {
return await syncCoordinator.getSyncHistory();
};
const clearHistory = async () => {
await syncCoordinator.clearHistory();
};
const reset = async () => {
await syncCoordinator.reset();
};
return {
status,
triggerSync,
getHistory,
clearHistory,
reset,
};
}