import { useEffect } from 'react'; import { useSyncClient, useOnlineStatus, useCachedQuery, useDb, Page, Block, List, ListItem, Button, ConflictResolver } from '@cap-rel/smartcommon'; function ThirdpartyList() { const db = useDb({ name: 'myApp', version: 1, stores: { queryCache: 'key', pendingChanges: 'id++, entity, action' } }); const { isOnline } = useOnlineStatus({ healthCheckUrl: '/api/health' }); const { sync, isSyncing, pendingCount, getConflicts } = useSyncClient({ apiUrl: '/api/smartauth', getAccessToken: () => localStorage.getItem('access_token'), scope: ['thirdparty'] }); const { data: thirdparties, isLoading, isFromCache, refetch } = useCachedQuery({ db: db.instance, store: 'queryCache', key: 'thirdparties', fetchFn: () => api.get('thirdparties').json(), strategy: 'swr' }); // Synchroniser automatiquement quand on revient en ligne useEffect(() => { if (isOnline && pendingCount > 0) { sync(); } }, [isOnline]); return (
{isOnline ? 'En ligne' : 'Hors ligne'} {isFromCache && ' (cache)'} {pendingCount > 0 && ( )}
{thirdparties?.map(t => ( {t.name} ))}
); }