@burdenoff/microfe-healthybowl 2026.1015.1 → 2026.1015.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/healthybowl/index.js +1 -0
- package/dist/healthybowl/offline/OfflineStatusPill.js +30 -29
- package/dist/healthybowl/offline/OfflineSyncProvider.js +288 -171
- package/dist/healthybowl/offline/sessionGuard.js +16 -0
- package/dist/healthybowl/offline/store.js +333 -86
- package/dist/healthybowl/offline/syncEngine.js +123 -83
- package/dist/healthybowl/offline/syncOutcome.js +4 -0
- package/dist/healthybowl/pages/field-capture/NeedsReviewPanel.js +135 -0
- package/dist/healthybowl/pages/field-capture/OfflineSettingsPage.js +83 -82
- package/dist/healthybowl/pages/field-capture/PendingSyncPage.js +46 -41
- package/dist/healthybowl/pages/field-capture/SyncQueuePanel.js +1 -1
- package/dist/index.js +6 -5
- package/package.json +3 -1
|
@@ -2,6 +2,7 @@ import "./context/HealthyBowlContext.js";
|
|
|
2
2
|
import "../components/assistant/AIAssistantPanel.js";
|
|
3
3
|
import "../components/assistant/index.js";
|
|
4
4
|
import "./events/rybbit.js";
|
|
5
|
+
import "./offline/store.js";
|
|
5
6
|
import "./HealthyBowlRoot.js";
|
|
6
7
|
import "./public/PublicTracePage.js";
|
|
7
8
|
import "./public/PublicSeedLotPage.js";
|
|
@@ -2,46 +2,47 @@ import { useBasePath as e } from "../hooks/useBasePath.js";
|
|
|
2
2
|
import { useOfflineSync as t } from "./OfflineSyncProvider.js";
|
|
3
3
|
import { relativeTime as n } from "./observationMeta.js";
|
|
4
4
|
import { compactLabel as r } from "./headerSlot.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { useI18n as i } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
6
|
+
import { AlertTriangle as a, CheckCircle2 as o, RefreshCw as s, Wifi as c, WifiOff as l } from "lucide-react";
|
|
7
|
+
import { Link as u } from "react-router";
|
|
8
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
8
9
|
//#region src/healthybowl/offline/OfflineStatusPill.tsx
|
|
9
|
-
var
|
|
10
|
-
let { buildPath:
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
let
|
|
10
|
+
var p = ({ inline: p, compact: m, className: h }) => {
|
|
11
|
+
let { buildPath: g } = e(), { t: _ } = i(), { online: v, syncing: y, queuedCount: b, conflictCount: x, needsReviewCount: S, lastSyncedAt: C, storageBlocked: w, syncNow: T } = t(), E = !v, D = b > 0, O = "ok";
|
|
12
|
+
E ? O = "offline" : (w || D || x > 0 || S > 0) && (O = "warning");
|
|
13
|
+
let k = O === "offline" || O === "warning" ? "bg-status-warning-bgSubtle text-status-warning-text border-status-warning-border" : "bg-status-success-bgSubtle text-status-success-text border-status-success-border", A = w ? a : E ? l : x > 0 || S > 0 ? a : D ? c : o, j;
|
|
14
|
+
j = w ? _("healthybowl.offline.pill.storageBlocked", "Close other HealthyBowl tabs · offline storage is finishing an update") : E ? D ? `Offline — ${b} record${b > 1 ? "s" : ""} queued` : "Offline — working locally" : y ? "Online — syncing…" : x > 0 ? `Online — ${x} conflict${x > 1 ? "s" : ""} to review` : D ? `Online — ${b} record${b > 1 ? "s" : ""} queued` : S > 0 ? S === 1 ? _("healthybowl.offline.pill.needsReviewOne", "Online — 1 record to review") : _("healthybowl.offline.pill.needsReviewMany", "Online — {{count}} records to review", { count: S }) : C ? `Online — all synced · last synced ${n(C)}` : "Online — all synced";
|
|
15
|
+
let M = /* @__PURE__ */ f("button", {
|
|
15
16
|
type: "button",
|
|
16
|
-
onClick: () => void
|
|
17
|
-
disabled:
|
|
18
|
-
title:
|
|
19
|
-
className: `inline-flex shrink-0 items-center gap-1.5 rounded-lg bg-bg-surface px-2.5 py-1 text-xs font-semibold text-text-primary shadow-sm ring-1 ring-border-subtle transition hover:bg-bg-sunken disabled:cursor-not-allowed disabled:opacity-50 ${
|
|
20
|
-
children: [/* @__PURE__ */
|
|
17
|
+
onClick: () => void T({ manual: !0 }),
|
|
18
|
+
disabled: y || !v,
|
|
19
|
+
title: v ? "Sync now" : "Reconnect to sync",
|
|
20
|
+
className: `inline-flex shrink-0 items-center gap-1.5 rounded-lg bg-bg-surface px-2.5 py-1 text-xs font-semibold text-text-primary shadow-sm ring-1 ring-border-subtle transition hover:bg-bg-sunken disabled:cursor-not-allowed disabled:opacity-50 ${m ? "hidden lg:inline-flex" : ""}`,
|
|
21
|
+
children: [/* @__PURE__ */ d(s, { className: `h-3.5 w-3.5 ${y ? "animate-spin" : ""}` }), "Sync Now"]
|
|
21
22
|
});
|
|
22
|
-
return
|
|
23
|
-
className: `flex max-w-[13rem] items-center gap-2 rounded-full border px-3 py-1 xl:max-w-[22rem] ${
|
|
23
|
+
return m ? /* @__PURE__ */ f("div", {
|
|
24
|
+
className: `flex max-w-[13rem] items-center gap-2 rounded-full border px-3 py-1 xl:max-w-[22rem] ${k} ${h ?? ""}`,
|
|
24
25
|
role: "status",
|
|
25
26
|
"aria-live": "polite",
|
|
26
|
-
children: [/* @__PURE__ */
|
|
27
|
-
to:
|
|
28
|
-
title:
|
|
29
|
-
"aria-label":
|
|
27
|
+
children: [/* @__PURE__ */ f(u, {
|
|
28
|
+
to: g("field-capture/pending"),
|
|
29
|
+
title: j,
|
|
30
|
+
"aria-label": j,
|
|
30
31
|
className: "flex min-w-0 flex-1 items-center gap-2 text-left transition hover:opacity-90",
|
|
31
|
-
children: [/* @__PURE__ */
|
|
32
|
+
children: [/* @__PURE__ */ d(A, { className: "h-4 w-4 shrink-0" }), /* @__PURE__ */ d("span", {
|
|
32
33
|
className: "truncate text-xs font-medium",
|
|
33
|
-
children: r(
|
|
34
|
+
children: r(j)
|
|
34
35
|
})]
|
|
35
|
-
}),
|
|
36
|
-
}) : /* @__PURE__ */
|
|
37
|
-
className: `flex items-center justify-between gap-3 rounded-xl border px-3.5 py-2 ${
|
|
36
|
+
}), M]
|
|
37
|
+
}) : /* @__PURE__ */ f("div", {
|
|
38
|
+
className: `flex items-center justify-between gap-3 rounded-xl border px-3.5 py-2 ${k} ${p ? "" : "shadow-sm"} ${h ?? ""}`,
|
|
38
39
|
role: "status",
|
|
39
40
|
"aria-live": "polite",
|
|
40
|
-
children: [/* @__PURE__ */
|
|
41
|
+
children: [/* @__PURE__ */ f("span", {
|
|
41
42
|
className: "flex items-center gap-2 text-sm font-medium",
|
|
42
|
-
children: [/* @__PURE__ */
|
|
43
|
-
}),
|
|
43
|
+
children: [/* @__PURE__ */ d(A, { className: "h-4 w-4 shrink-0" }), j]
|
|
44
|
+
}), M]
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
//#endregion
|
|
47
|
-
export {
|
|
48
|
+
export { p as OfflineStatusPill };
|
|
@@ -2,152 +2,235 @@ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
|
|
|
2
2
|
import { getNetworkState as t, isCellular as n, subscribeNetwork as r } from "./network.js";
|
|
3
3
|
import { useToast as i } from "../hooks/useToast.js";
|
|
4
4
|
import { DEFAULT_SETTINGS as a } from "./types.js";
|
|
5
|
-
import {
|
|
6
|
-
import { CAPTURE_DATA_META as
|
|
7
|
-
import { downscaleImage as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
5
|
+
import { claimUnattributedObservation as o, claimUnattributedPendingMutation as s, clearSyncedCache as c, deleteObservation as l, deletePendingMutation as u, discardUnattributedObservation as ee, discardUnattributedPendingMutation as te, estimateLocalUsage as ne, getAllObservations as d, getAllPendingMutations as f, getHistory as p, getObservation as re, getPendingMutation as ie, getPhotosFor as ae, getScopedMeta as m, getUnattributedObservations as h, getUnattributedPendingMutations as g, isOfflineStoreBlocked as _, loadSettings as oe, lockOfflineActor as se, saveObservation as ce, savePendingMutation as le, savePhoto as ue, saveSettings as de, setScopedMeta as fe, subscribeOfflineStoreBlocked as pe, toOfflineScope as me, unlockOfflineActor as he, updateObservation as ge } from "./store.js";
|
|
6
|
+
import { CAPTURE_DATA_META as _e, CAPTURE_PHOTO_MAX_DIM as ve, CAPTURE_PHOTO_QUALITY as ye, autoResolutionFor as be, conflictsToAutoResolve as xe, isUsableCaptureCache as Se, shouldCompressPhotos as Ce, toCachedCaptureData as we } from "./captureCache.js";
|
|
7
|
+
import { downscaleImage as Te } from "../utils/imageDownscale.js";
|
|
8
|
+
import { sendIfSessionCurrent as Ee } from "./sessionGuard.js";
|
|
9
|
+
import { fetchFieldCaptureData as De, resolveConflict as Oe } from "./graphql.js";
|
|
10
|
+
import { drainQueue as ke } from "./syncEngine.js";
|
|
11
|
+
import { describeDrain as Ae } from "./syncOutcome.js";
|
|
12
|
+
import { createContext as v, useCallback as y, useContext as b, useEffect as x, useMemo as S, useRef as C, useState as w } from "react";
|
|
13
|
+
import { jsx as je } from "react/jsx-runtime";
|
|
14
|
+
import { useSaveToFiles as Me } from "@burdenoff/fe-libs/storage";
|
|
14
15
|
//#region src/healthybowl/offline/OfflineSyncProvider.tsx
|
|
15
|
-
var
|
|
16
|
-
function
|
|
17
|
-
let e =
|
|
16
|
+
var T = v(null);
|
|
17
|
+
function E() {
|
|
18
|
+
let e = b(T);
|
|
18
19
|
if (!e) throw Error("useOfflineSync must be used within an OfflineSyncProvider");
|
|
19
20
|
return e;
|
|
20
21
|
}
|
|
21
|
-
var
|
|
22
|
-
function
|
|
22
|
+
var D = "lastSyncedAt", O = "Sign in and open a workspace to save field records on this device.", k = "This record is not available in the current session.";
|
|
23
|
+
function A(e) {
|
|
24
|
+
return {
|
|
25
|
+
key: e,
|
|
26
|
+
loaded: !1,
|
|
27
|
+
observations: [],
|
|
28
|
+
pendingMutations: [],
|
|
29
|
+
unattributedObservations: [],
|
|
30
|
+
unattributedMutations: [],
|
|
31
|
+
history: [],
|
|
32
|
+
lastSyncedAt: null,
|
|
33
|
+
captureData: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function Ne(e) {
|
|
37
|
+
return e ? JSON.stringify([e.workspaceId, e.actorId]) : "";
|
|
38
|
+
}
|
|
39
|
+
async function j(e) {
|
|
40
|
+
let [t, n, r, i, a] = await Promise.all([
|
|
41
|
+
d(e),
|
|
42
|
+
p(e),
|
|
43
|
+
f(e),
|
|
44
|
+
h(e),
|
|
45
|
+
g(e)
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
observations: t,
|
|
49
|
+
history: n,
|
|
50
|
+
pendingMutations: r,
|
|
51
|
+
unattributedObservations: i,
|
|
52
|
+
unattributedMutations: a
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function M() {
|
|
23
56
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
24
57
|
}
|
|
25
|
-
function
|
|
58
|
+
function N(e) {
|
|
26
59
|
return `${e}-${typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.round(Math.random() * 1e9)}`}`;
|
|
27
60
|
}
|
|
28
|
-
var
|
|
29
|
-
let { workspaceId:
|
|
30
|
-
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
var P = ({ children: f }) => {
|
|
62
|
+
let { workspaceId: p, currentUser: h } = e(), g = h?.id ?? "", { save: v } = Me(), { toast: b } = i(), E = S(() => me(p, g), [p, g]), P = Ne(E), [F, Pe] = w(() => t()), [Fe, I] = w(!1), [L, R] = w(a), [z, Ie] = w(() => A(P)), [Le, B] = w(!1), [Re, ze] = w(() => _());
|
|
63
|
+
x(() => (ze(_()), pe(ze)), []);
|
|
64
|
+
let V = C(L), H = C(F), U = C(!1), Be = C(v), W = C({
|
|
65
|
+
key: P,
|
|
66
|
+
generation: 0,
|
|
67
|
+
scope: E
|
|
68
|
+
});
|
|
69
|
+
W.current.key !== P && (W.current = {
|
|
70
|
+
key: P,
|
|
71
|
+
generation: W.current.generation + 1,
|
|
72
|
+
scope: E
|
|
73
|
+
});
|
|
74
|
+
let Ve = C(() => Promise.resolve());
|
|
75
|
+
V.current = L, H.current = F, Be.current = v, x(() => {
|
|
76
|
+
let e = W;
|
|
77
|
+
return () => {
|
|
78
|
+
e.current = {
|
|
79
|
+
...e.current,
|
|
80
|
+
generation: e.current.generation + 1
|
|
81
|
+
};
|
|
82
|
+
};
|
|
48
83
|
}, []);
|
|
49
|
-
y(() => {
|
|
50
|
-
|
|
84
|
+
let G = y((e, t) => {
|
|
85
|
+
W.current.generation === e.generation && Ie((n) => ({
|
|
86
|
+
...n.key === e.key ? n : A(e.key),
|
|
87
|
+
...t
|
|
88
|
+
}));
|
|
89
|
+
}, []), K = y(async () => {
|
|
90
|
+
let e = W.current;
|
|
91
|
+
G(e, await j(e.scope));
|
|
92
|
+
}, [G]), q = y(async () => {
|
|
93
|
+
let e = W.current;
|
|
94
|
+
if (!e.scope || !H.current.online) return;
|
|
95
|
+
let t = e.scope;
|
|
96
|
+
B(!0);
|
|
97
|
+
try {
|
|
98
|
+
let n = await De({ workspaceId: t.workspaceId });
|
|
99
|
+
n && W.current.generation === e.generation && (G(e, { captureData: n }), await fe(t, _e, we(n, t.workspaceId, Date.now())).catch(() => void 0));
|
|
100
|
+
} finally {
|
|
101
|
+
B(!1);
|
|
102
|
+
}
|
|
103
|
+
}, [G]), He = C("");
|
|
104
|
+
x(() => {
|
|
105
|
+
let e = He.current;
|
|
106
|
+
He.current = g, e && e !== g && se(e);
|
|
107
|
+
}, [g]), x(() => {
|
|
108
|
+
let e = !1, t = W.current;
|
|
51
109
|
return (async () => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
d(m)
|
|
110
|
+
t.scope && await he(t.scope.actorId);
|
|
111
|
+
let [n, r, i, a] = await Promise.all([
|
|
112
|
+
j(t.scope),
|
|
113
|
+
oe(),
|
|
114
|
+
m(t.scope, D),
|
|
115
|
+
m(t.scope, _e)
|
|
59
116
|
]);
|
|
60
|
-
e || (
|
|
117
|
+
e || (R(r), G(t, {
|
|
118
|
+
...n,
|
|
119
|
+
lastSyncedAt: i ?? null,
|
|
120
|
+
captureData: Se(a, t.scope?.workspaceId, Date.now()) ? a.data : null,
|
|
121
|
+
loaded: !0
|
|
122
|
+
}));
|
|
61
123
|
})(), () => {
|
|
62
124
|
e = !0;
|
|
63
125
|
};
|
|
64
|
-
}, []),
|
|
65
|
-
|
|
66
|
-
}, [
|
|
67
|
-
let
|
|
68
|
-
if (
|
|
69
|
-
let t =
|
|
70
|
-
if (!
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
126
|
+
}, [P, G]), x(() => {
|
|
127
|
+
q();
|
|
128
|
+
}, [q, P]);
|
|
129
|
+
let J = y(async (e) => {
|
|
130
|
+
if (U.current) return;
|
|
131
|
+
let t = W.current, r = H.current;
|
|
132
|
+
if (!t.scope || !r.online) return;
|
|
133
|
+
let i = t.scope;
|
|
134
|
+
if (!e?.manual && !V.current.syncOverMobileData && n(r)) return;
|
|
135
|
+
let a = () => W.current.generation === t.generation;
|
|
136
|
+
U.current = !0, I(!0);
|
|
137
|
+
try {
|
|
138
|
+
let n = await ke({
|
|
139
|
+
scope: i,
|
|
140
|
+
isCurrent: a,
|
|
141
|
+
saveToFiles: Be.current,
|
|
142
|
+
settings: V.current,
|
|
143
|
+
network: r
|
|
144
|
+
});
|
|
145
|
+
if (n.aborted || !a()) return;
|
|
146
|
+
let o = Date.now();
|
|
147
|
+
G(t, { lastSyncedAt: o }), await fe(i, D, o), await K(), q();
|
|
148
|
+
let s = be(V.current.conflictHandling), c = n.conflict;
|
|
149
|
+
if (s && n.conflict > 0) {
|
|
150
|
+
let e = xe(await d(i), i.workspaceId), r = 0;
|
|
151
|
+
for (let n of e) {
|
|
152
|
+
if (!a()) break;
|
|
153
|
+
await Ve.current(n.clientId, s, void 0, {
|
|
154
|
+
silent: !0,
|
|
155
|
+
session: t
|
|
156
|
+
}).then(() => !0, () => !1) && (r += 1);
|
|
89
157
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
conflict:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
e?.manual && O({
|
|
97
|
-
title: "Sync failed",
|
|
98
|
-
description: "Please try again.",
|
|
99
|
-
variant: "error"
|
|
100
|
-
});
|
|
101
|
-
} finally {
|
|
102
|
-
G.current = !1, j(!1);
|
|
158
|
+
if (!a()) return;
|
|
159
|
+
c = Math.max(0, n.conflict - r), r > 0 && (await K(), b({
|
|
160
|
+
title: `${r} conflict${r > 1 ? "s" : ""} resolved`,
|
|
161
|
+
description: s === "KEEP_MINE" ? "Your offline version was kept, as set in Offline Settings." : "The server version was kept, as set in Offline Settings.",
|
|
162
|
+
variant: "info"
|
|
163
|
+
}));
|
|
103
164
|
}
|
|
165
|
+
let l = Ae({
|
|
166
|
+
...n,
|
|
167
|
+
conflict: c
|
|
168
|
+
}, { manual: e?.manual });
|
|
169
|
+
l && b(l);
|
|
170
|
+
} catch {
|
|
171
|
+
e?.manual && a() && b({
|
|
172
|
+
title: "Sync failed",
|
|
173
|
+
description: "Please try again.",
|
|
174
|
+
variant: "error"
|
|
175
|
+
});
|
|
176
|
+
} finally {
|
|
177
|
+
U.current = !1, I(!1);
|
|
104
178
|
}
|
|
105
179
|
}, [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
180
|
+
G,
|
|
181
|
+
K,
|
|
182
|
+
q,
|
|
183
|
+
b
|
|
109
184
|
]);
|
|
110
|
-
|
|
111
|
-
let e =
|
|
185
|
+
x(() => {
|
|
186
|
+
let e = H.current.online;
|
|
112
187
|
return r((t) => {
|
|
113
|
-
|
|
188
|
+
Pe(t);
|
|
114
189
|
let n = !e && t.online;
|
|
115
|
-
e = t.online, n &&
|
|
190
|
+
e = t.online, n && V.current.autoSyncOnReconnect && J();
|
|
116
191
|
});
|
|
117
|
-
}, [
|
|
192
|
+
}, [J]), x(() => {
|
|
118
193
|
if (!L.autoSyncOnReconnect || L.syncFrequencyMs <= 0) return;
|
|
119
194
|
let e = window.setInterval(() => {
|
|
120
|
-
|
|
195
|
+
H.current.online && J();
|
|
121
196
|
}, L.syncFrequencyMs);
|
|
122
197
|
return () => window.clearInterval(e);
|
|
123
198
|
}, [
|
|
124
199
|
L.autoSyncOnReconnect,
|
|
125
200
|
L.syncFrequencyMs,
|
|
126
|
-
|
|
201
|
+
J
|
|
127
202
|
]);
|
|
128
|
-
let
|
|
129
|
-
let t =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
203
|
+
let Ue = y(async (e) => {
|
|
204
|
+
let t = W.current.scope;
|
|
205
|
+
if (!t) throw b({
|
|
206
|
+
title: "Not saved",
|
|
207
|
+
description: O,
|
|
208
|
+
variant: "error"
|
|
209
|
+
}), Error(O);
|
|
210
|
+
let n = N("obs"), r = [], i = Ce(V.current);
|
|
211
|
+
for (let a of e.photos ?? []) {
|
|
212
|
+
let e = N("photo"), o = a, s = a.name || `photo-${e}.jpg`, c = a.type || "image/jpeg";
|
|
213
|
+
if (i) try {
|
|
214
|
+
let e = await Te(a, {
|
|
215
|
+
maxDim: ve,
|
|
216
|
+
quality: ye,
|
|
136
217
|
encodeFallback: !1
|
|
137
218
|
});
|
|
138
|
-
e.downscaled && e.blob && (
|
|
219
|
+
e.downscaled && e.blob && (o = e.blob, s = e.filename ?? s, c = e.mimeType ?? "image/jpeg");
|
|
139
220
|
} catch {}
|
|
140
|
-
await
|
|
221
|
+
await ue({
|
|
141
222
|
id: e,
|
|
142
|
-
clientId:
|
|
143
|
-
blob:
|
|
144
|
-
filename:
|
|
145
|
-
mimeType:
|
|
146
|
-
createdAt: Date.now()
|
|
147
|
-
|
|
223
|
+
clientId: n,
|
|
224
|
+
blob: o,
|
|
225
|
+
filename: s,
|
|
226
|
+
mimeType: c,
|
|
227
|
+
createdAt: Date.now(),
|
|
228
|
+
workspaceId: t.workspaceId,
|
|
229
|
+
actorId: t.actorId
|
|
230
|
+
}), r.push(e);
|
|
148
231
|
}
|
|
149
|
-
let
|
|
150
|
-
clientId:
|
|
232
|
+
let a = {
|
|
233
|
+
clientId: n,
|
|
151
234
|
observationType: e.observationType,
|
|
152
235
|
fieldId: e.fieldId ?? null,
|
|
153
236
|
fieldName: e.fieldName ?? null,
|
|
@@ -160,25 +243,35 @@ var O = ({ children: g }) => {
|
|
|
160
243
|
latitude: e.latitude ?? null,
|
|
161
244
|
longitude: e.longitude ?? null,
|
|
162
245
|
gpsAccuracy: e.gpsAccuracy ?? null,
|
|
163
|
-
photoLocalIds:
|
|
246
|
+
photoLocalIds: r,
|
|
164
247
|
photoFileIds: [],
|
|
165
|
-
capturedAt:
|
|
166
|
-
capturedOffline: !
|
|
248
|
+
capturedAt: M(),
|
|
249
|
+
capturedOffline: !H.current.online,
|
|
167
250
|
status: "QUEUED",
|
|
168
251
|
baseVersion: null,
|
|
169
252
|
attempts: 0,
|
|
170
253
|
createdAt: Date.now(),
|
|
171
254
|
updatedAt: Date.now(),
|
|
172
|
-
workspaceId:
|
|
255
|
+
workspaceId: t.workspaceId,
|
|
256
|
+
actorId: t.actorId
|
|
173
257
|
};
|
|
174
|
-
return await
|
|
175
|
-
}, [
|
|
176
|
-
|
|
258
|
+
return await ce(a), await K(), H.current.online && V.current.autoSyncOnReconnect && J(), a;
|
|
259
|
+
}, [
|
|
260
|
+
K,
|
|
261
|
+
J,
|
|
262
|
+
b
|
|
263
|
+
]), We = y(async (e, t, n, r) => {
|
|
264
|
+
let i = r?.session ?? W.current, a = () => W.current.generation === i.generation;
|
|
177
265
|
try {
|
|
178
|
-
let o = await
|
|
266
|
+
let o = i.scope, s = o ? await re(o, e) : void 0;
|
|
267
|
+
if (!o || !s) throw Error(k);
|
|
268
|
+
let c = s.serverVersion?.version ?? s.baseVersion ?? 0, l = await Ee({
|
|
269
|
+
scope: o,
|
|
270
|
+
isCurrent: a
|
|
271
|
+
}, () => Oe({ workspaceId: o.workspaceId }, {
|
|
179
272
|
clientId: e,
|
|
180
273
|
resolution: t,
|
|
181
|
-
baseVersion:
|
|
274
|
+
baseVersion: c,
|
|
182
275
|
fieldId: n?.fieldId,
|
|
183
276
|
note: n?.note,
|
|
184
277
|
severity: n?.severity,
|
|
@@ -189,23 +282,31 @@ var O = ({ children: g }) => {
|
|
|
189
282
|
latitude: n?.latitude,
|
|
190
283
|
longitude: n?.longitude,
|
|
191
284
|
photoFileIds: n?.photoFileIds
|
|
192
|
-
});
|
|
193
|
-
|
|
285
|
+
}));
|
|
286
|
+
if (!l.sent) throw Error(k);
|
|
287
|
+
let u = l.result;
|
|
288
|
+
if (s.status = "SYNCED", s.serverVersion = null, s.baseVersion = u.version, s.serverId = u.id, s.syncedAt = M(), s.message = null, s.note = u.note ?? s.note, s.severity = u.severity ?? s.severity, s.updatedAt = Date.now(), await ge(s), !a()) return;
|
|
289
|
+
await K(), r?.silent || b({
|
|
194
290
|
title: "Conflict resolved",
|
|
195
291
|
variant: "success"
|
|
196
292
|
});
|
|
197
293
|
} catch (e) {
|
|
198
294
|
let t = e instanceof Error ? e.message : "Could not resolve the conflict";
|
|
199
|
-
throw r?.silent
|
|
295
|
+
throw !r?.silent && a() && b({
|
|
200
296
|
title: "Resolve failed",
|
|
201
297
|
description: t,
|
|
202
298
|
variant: "error"
|
|
203
299
|
}), e;
|
|
204
300
|
}
|
|
205
|
-
}, [
|
|
206
|
-
let n =
|
|
207
|
-
if (
|
|
208
|
-
|
|
301
|
+
}, [K, b]), Ge = y(async (e, t) => {
|
|
302
|
+
let n = W.current.scope;
|
|
303
|
+
if (!n) return {
|
|
304
|
+
status: "FAILED",
|
|
305
|
+
message: O
|
|
306
|
+
};
|
|
307
|
+
let r = N("scheme");
|
|
308
|
+
if (await le({
|
|
309
|
+
clientId: r,
|
|
209
310
|
kind: "SCHEME_APPLICATION",
|
|
210
311
|
payload: e,
|
|
211
312
|
label: t,
|
|
@@ -213,63 +314,79 @@ var O = ({ children: g }) => {
|
|
|
213
314
|
attempts: 0,
|
|
214
315
|
createdAt: Date.now(),
|
|
215
316
|
updatedAt: Date.now(),
|
|
216
|
-
workspaceId:
|
|
217
|
-
|
|
218
|
-
await
|
|
219
|
-
|
|
220
|
-
|
|
317
|
+
workspaceId: n.workspaceId,
|
|
318
|
+
actorId: n.actorId
|
|
319
|
+
}), await K(), !H.current.online) return { status: "QUEUED" };
|
|
320
|
+
await J();
|
|
321
|
+
let i = await ie(n, r);
|
|
322
|
+
return await K(), i?.status === "SYNCED" && i.serverId ? {
|
|
221
323
|
status: "SYNCED",
|
|
222
|
-
serverId:
|
|
223
|
-
} :
|
|
324
|
+
serverId: i.serverId
|
|
325
|
+
} : i?.status === "FAILED" ? {
|
|
224
326
|
status: "FAILED",
|
|
225
|
-
message:
|
|
327
|
+
message: i.message ?? "The server rejected this application."
|
|
226
328
|
} : { status: "QUEUED" };
|
|
227
|
-
}, [
|
|
228
|
-
|
|
229
|
-
let
|
|
230
|
-
await
|
|
231
|
-
}, [
|
|
232
|
-
await
|
|
233
|
-
|
|
329
|
+
}, [K, J]);
|
|
330
|
+
Ve.current = We;
|
|
331
|
+
let Ke = y(async (e) => {
|
|
332
|
+
await u(W.current.scope, e), await K();
|
|
333
|
+
}, [K]), qe = y(async (e) => {
|
|
334
|
+
let t = await l(W.current.scope, e);
|
|
335
|
+
if (await K(), !t) throw Error(k);
|
|
336
|
+
}, [K]), Je = y(async (e, t) => {
|
|
337
|
+
let n = W.current, r = e === "observation" ? await o(n.scope, t) : await s(n.scope, t);
|
|
338
|
+
return await K(), r && H.current.online && V.current.autoSyncOnReconnect && J(), r !== null;
|
|
339
|
+
}, [K, J]), Ye = y(async (e, t) => {
|
|
340
|
+
let n = W.current.scope, r = e === "observation" ? await ee(n, t) : await te(n, t);
|
|
341
|
+
return await K(), r;
|
|
342
|
+
}, [K]), Xe = y(async (e) => {
|
|
234
343
|
R((t) => {
|
|
235
344
|
let n = {
|
|
236
345
|
...t,
|
|
237
346
|
...e
|
|
238
347
|
};
|
|
239
|
-
return
|
|
348
|
+
return de(n), n;
|
|
240
349
|
});
|
|
241
|
-
}, []),
|
|
242
|
-
ready:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
350
|
+
}, []), Ze = y((e) => ae(W.current.scope, e), []), Qe = y(() => ne(W.current.scope), []), $e = y(() => c(W.current.scope), []), Y = z.key === P ? z : A(P), { observations: X, pendingMutations: Z, unattributedObservations: et, unattributedMutations: Q, history: tt, lastSyncedAt: nt } = Y, $ = Y.captureData, rt = S(() => X.filter((e) => e.status === "QUEUED" || e.status === "UPLOADING" || e.status === "FAILED").length + Z.filter((e) => e.status === "QUEUED" || e.status === "UPLOADING" || e.status === "FAILED").length, [X, Z]), it = S(() => X.filter((e) => e.status === "CONFLICT").length, [X]), at = {
|
|
351
|
+
ready: Y.loaded,
|
|
352
|
+
storageBlocked: Re,
|
|
353
|
+
online: F.online,
|
|
354
|
+
connectionType: F.connectionType,
|
|
355
|
+
syncing: Fe,
|
|
356
|
+
lastSyncedAt: nt,
|
|
357
|
+
observations: X,
|
|
358
|
+
pendingMutations: Z,
|
|
359
|
+
unattributedObservations: et,
|
|
360
|
+
unattributedMutations: Q,
|
|
361
|
+
needsReviewCount: et.length + Q.length,
|
|
362
|
+
queuedCount: rt,
|
|
363
|
+
conflictCount: it,
|
|
364
|
+
history: tt,
|
|
252
365
|
settings: L,
|
|
253
|
-
fields:
|
|
254
|
-
serverRecent:
|
|
255
|
-
stats:
|
|
256
|
-
loadingCaptureData:
|
|
257
|
-
capture:
|
|
258
|
-
queueSchemeApplication:
|
|
259
|
-
discardPendingMutation:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
366
|
+
fields: $?.fields ?? [],
|
|
367
|
+
serverRecent: $?.recentObservations ?? [],
|
|
368
|
+
stats: $?.stats ?? null,
|
|
369
|
+
loadingCaptureData: Le,
|
|
370
|
+
capture: Ue,
|
|
371
|
+
queueSchemeApplication: Ge,
|
|
372
|
+
discardPendingMutation: Ke,
|
|
373
|
+
claimUnattributed: Je,
|
|
374
|
+
discardUnattributed: Ye,
|
|
375
|
+
estimateLocalUsage: Qe,
|
|
376
|
+
clearSyncedCache: $e,
|
|
377
|
+
syncNow: J,
|
|
378
|
+
resolve: We,
|
|
379
|
+
remove: qe,
|
|
380
|
+
updateSettings: Xe,
|
|
264
381
|
refresh: async () => {
|
|
265
|
-
await
|
|
382
|
+
await K(), await q();
|
|
266
383
|
},
|
|
267
|
-
loadLocalPhotos:
|
|
384
|
+
loadLocalPhotos: Ze
|
|
268
385
|
};
|
|
269
|
-
return /* @__PURE__ */
|
|
270
|
-
value:
|
|
271
|
-
children:
|
|
386
|
+
return /* @__PURE__ */ je(T.Provider, {
|
|
387
|
+
value: at,
|
|
388
|
+
children: f
|
|
272
389
|
});
|
|
273
390
|
};
|
|
274
391
|
//#endregion
|
|
275
|
-
export {
|
|
392
|
+
export { P as OfflineSyncProvider, E as useOfflineSync };
|