|
|
|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
Android-only: react-native-health-connect is loaded lazily so the module's
|
|
|
|
|
absence (iOS, Expo Go) never crashes the app. */
|
|
|
|
|
import { Platform } from 'react-native';
|
|
|
|
|
import { FITBIT_SYNC_URL, load, postJson } from './api';
|
|
|
|
|
import { FITBIT_SYNC_URL, invalidate, load, postJson } from './api';
|
|
|
|
|
|
|
|
|
|
export interface SyncResult {
|
|
|
|
|
ok: boolean;
|
|
|
|
|
@@ -90,6 +90,7 @@ export async function syncFitbit(onProgress?: (msg: string) => void): Promise<Sy
|
|
|
|
|
await requestPermission(READ_PERMISSIONS.map((r) => ({ accessType: 'read', recordType: r })));
|
|
|
|
|
|
|
|
|
|
say('Checking server watermark…');
|
|
|
|
|
invalidate('fitbitLatest'); // watermark must be fresh, never the session-cached copy
|
|
|
|
|
const latest = await load<{
|
|
|
|
|
samples: Record<string, string | null>;
|
|
|
|
|
daily: Record<string, string | null>;
|
|
|
|
|
@@ -182,6 +183,9 @@ export async function syncFitbit(onProgress?: (msg: string) => void): Promise<Sy
|
|
|
|
|
ns += res.samples; nd += res.daily; nl += res.sleep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// new rows exist server-side — cached copies of these are now stale
|
|
|
|
|
invalidate('fitbitSummary', 'fitbitLatest');
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
ok: true, samples: ns, daily: nd, sleep: nl,
|
|
|
|
|
message: `Synced ${ns} samples, ${nd} daily rows, ${nl} sleep sessions`,
|
|
|
|
|
|