@adminide-stack/yantra-mobile 12.0.100-alpha.0 → 12.0.101-alpha.0
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/lib/screens/Devices/index.js +729 -670
- package/lib/screens/Devices/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -15,6 +15,7 @@ var __spreadValues = (a, b) => {
|
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
17
|
const IS_IOS = Platform.OS === "ios";
|
|
18
|
+
const CARD_EDGE = "rgba(148,163,184,0.3)";
|
|
18
19
|
const STORE_NAME = IS_IOS ? "Apple Health" : "Health Connect";
|
|
19
20
|
const WORKOUT_TYPES = [{
|
|
20
21
|
id: "run",
|
|
@@ -35,673 +36,6 @@ const WORKOUT_TYPES = [{
|
|
|
35
36
|
id: "other",
|
|
36
37
|
label: "Other"
|
|
37
38
|
}];
|
|
38
|
-
function DevicesScreen() {
|
|
39
|
-
var _a, _b, _c, _d, _e, _f;
|
|
40
|
-
const navigation = useNavigation();
|
|
41
|
-
const route = useRoute();
|
|
42
|
-
const {
|
|
43
|
-
isDark
|
|
44
|
-
} = useAppTheme();
|
|
45
|
-
const colors = mobileColors(isDark);
|
|
46
|
-
const insets = useSafeAreaInsets();
|
|
47
|
-
const devices = useDevices();
|
|
48
|
-
const [stack, setStack] = useState(() => {
|
|
49
|
-
var _a2;
|
|
50
|
-
return ((_a2 = route == null ? void 0 : route.params) == null ? void 0 : _a2.add) ? [{
|
|
51
|
-
name: "home"
|
|
52
|
-
}, {
|
|
53
|
-
name: "pick"
|
|
54
|
-
}] : [{
|
|
55
|
-
name: "home"
|
|
56
|
-
}];
|
|
57
|
-
});
|
|
58
|
-
const step = stack[stack.length - 1];
|
|
59
|
-
const units = (_b = (_a = devices.person) == null ? void 0 : _a.units) != null ? _b : "metric";
|
|
60
|
-
const orgName = useMemo(() => {
|
|
61
|
-
var _a2, _b2;
|
|
62
|
-
const raw = (_b2 = (_a2 = route == null ? void 0 : route.params) == null ? void 0 : _a2.orgName) != null ? _b2 : "";
|
|
63
|
-
return typeof raw === "string" && raw.trim() ? raw.trim() : null;
|
|
64
|
-
}, [(_c = route == null ? void 0 : route.params) == null ? void 0 : _c.orgName]);
|
|
65
|
-
const push = useCallback((next) => setStack((s) => [...s, next]), []);
|
|
66
|
-
const pop = useCallback(() => {
|
|
67
|
-
var _a2, _b2;
|
|
68
|
-
if (stack.length > 1) {
|
|
69
|
-
setStack((s) => s.slice(0, -1));
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
if ((_a2 = navigation == null ? void 0 : navigation.canGoBack) == null ? void 0 : _a2.call(navigation)) {
|
|
73
|
-
navigation.goBack();
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
(_b2 = navigation == null ? void 0 : navigation.dispatch) == null ? void 0 : _b2.call(navigation, CommonActions.navigate({
|
|
77
|
-
name: "MainStack.Account",
|
|
78
|
-
params: orgName ? {
|
|
79
|
-
orgName
|
|
80
|
-
} : void 0
|
|
81
|
-
}));
|
|
82
|
-
return true;
|
|
83
|
-
}, [stack.length, navigation, orgName]);
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
const sub = BackHandler.addEventListener("hardwareBackPress", pop);
|
|
86
|
-
return () => sub.remove();
|
|
87
|
-
}, [pop]);
|
|
88
|
-
const openHealth = useCallback(() => {
|
|
89
|
-
var _a2;
|
|
90
|
-
(_a2 = navigation == null ? void 0 : navigation.navigate) == null ? void 0 : _a2.call(navigation, "MainStack.Health", orgName ? {
|
|
91
|
-
orgName
|
|
92
|
-
} : void 0);
|
|
93
|
-
}, [navigation, orgName]);
|
|
94
|
-
const title = step.name === "pick" ? "Add a device" : step.name === "measure" ? deviceKind(step.kind).title : step.name === "device" ? (_e = (_d = devices.devices.find((d) => d.id === step.id)) == null ? void 0 : _d.name) != null ? _e : "Device" : "Devices";
|
|
95
|
-
return /* @__PURE__ */ jsxs(SafeAreaView, { edges: ["top", "left", "right"], style: [styles.safe, {
|
|
96
|
-
backgroundColor: colors.bg
|
|
97
|
-
}], children: [
|
|
98
|
-
/* @__PURE__ */ jsxs(View, { style: [styles.header, {
|
|
99
|
-
paddingTop: insets.top > 0 ? 4 : 10
|
|
100
|
-
}], children: [
|
|
101
|
-
/* @__PURE__ */ jsx(Pressable, { onPress: pop, accessibilityRole: "button", accessibilityLabel: "Go back", style: ({
|
|
102
|
-
pressed
|
|
103
|
-
}) => [styles.backCircle, {
|
|
104
|
-
backgroundColor: colors.surface
|
|
105
|
-
}, pressed && styles.pressed], children: /* @__PURE__ */ jsx(Ionicons, { name: "chevron-back", size: 22, color: colors.text }) }),
|
|
106
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.headerTitle, {
|
|
107
|
-
color: colors.text
|
|
108
|
-
}], numberOfLines: 1, children: title }),
|
|
109
|
-
/* @__PURE__ */ jsx(View, { style: styles.headerSpacer })
|
|
110
|
-
] }),
|
|
111
|
-
step.name === "home" ? /* @__PURE__ */ jsx(Home, { colors, isDark, units, onAdd: () => push({
|
|
112
|
-
name: "pick"
|
|
113
|
-
}), onOpen: (id) => push({
|
|
114
|
-
name: "device",
|
|
115
|
-
id
|
|
116
|
-
}), onHealth: openHealth }) : null,
|
|
117
|
-
step.name === "pick" ? /* @__PURE__ */ jsx(PickKind, { colors, isDark, onPick: (kind) => push({
|
|
118
|
-
name: "measure",
|
|
119
|
-
kind
|
|
120
|
-
}) }) : null,
|
|
121
|
-
step.name === "measure" ? /* @__PURE__ */ jsx(Measure, { kind: step.kind, deviceId: step.deviceId, colors, units, onDone: () => setStack([{
|
|
122
|
-
name: "home"
|
|
123
|
-
}]), onHealth: openHealth }, `${step.kind}:${(_f = step.deviceId) != null ? _f : ""}`) : null,
|
|
124
|
-
step.name === "device" ? /* @__PURE__ */ jsx(DeviceDetail, { id: step.id, colors, units, onMeasure: (kind) => push({
|
|
125
|
-
name: "measure",
|
|
126
|
-
kind,
|
|
127
|
-
deviceId: step.id
|
|
128
|
-
}), onForgot: () => setStack([{
|
|
129
|
-
name: "home"
|
|
130
|
-
}]) }) : null
|
|
131
|
-
] });
|
|
132
|
-
}
|
|
133
|
-
function Home({
|
|
134
|
-
colors,
|
|
135
|
-
isDark,
|
|
136
|
-
units,
|
|
137
|
-
onAdd,
|
|
138
|
-
onOpen,
|
|
139
|
-
onHealth
|
|
140
|
-
}) {
|
|
141
|
-
const devices = useDevices();
|
|
142
|
-
const now = Date.now();
|
|
143
|
-
if (!devices.loaded) return /* @__PURE__ */ jsx(ActivityIndicator, { style: styles.loading, color: colors.primary });
|
|
144
|
-
const latestOf = (d) => devices.readings.filter((r) => r.deviceId === d.id).reduce((a, b) => !a || b.at > a.at ? b : a, void 0);
|
|
145
|
-
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
146
|
-
devices.devices.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
147
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.sectionTitle, {
|
|
148
|
-
color: colors.textMuted
|
|
149
|
-
}], children: "MY DEVICES" }),
|
|
150
|
-
/* @__PURE__ */ jsx(View, { style: [styles.card, {
|
|
151
|
-
backgroundColor: colors.surface
|
|
152
|
-
}], children: devices.devices.map((d, i) => {
|
|
153
|
-
const latest = latestOf(d);
|
|
154
|
-
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
155
|
-
i > 0 ? /* @__PURE__ */ jsx(View, { style: [styles.rowLine, {
|
|
156
|
-
backgroundColor: colors.border
|
|
157
|
-
}] }) : null,
|
|
158
|
-
/* @__PURE__ */ jsxs(Pressable, { onPress: () => onOpen(d.id), accessibilityRole: "button", accessibilityLabel: d.name, style: ({
|
|
159
|
-
pressed
|
|
160
|
-
}) => [styles.deviceRow, pressed && {
|
|
161
|
-
backgroundColor: colors.surfaceMuted
|
|
162
|
-
}], children: [
|
|
163
|
-
/* @__PURE__ */ jsx(KindIcon, { kind: d.kind, colors }),
|
|
164
|
-
/* @__PURE__ */ jsxs(View, { style: styles.deviceText, children: [
|
|
165
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.deviceName, {
|
|
166
|
-
color: colors.text
|
|
167
|
-
}], numberOfLines: 1, children: d.name }),
|
|
168
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.deviceMeta, {
|
|
169
|
-
color: colors.textMuted
|
|
170
|
-
}], numberOfLines: 1, children: latest ? `${describeReading(latest, units)} \xB7 ${whenLabel(latest.at, now)}` : "No readings yet" })
|
|
171
|
-
] }),
|
|
172
|
-
/* @__PURE__ */ jsx(Ionicons, { name: "chevron-forward", size: 16, color: isDark ? "#64748b" : "#c4c4c4" })
|
|
173
|
-
] })
|
|
174
|
-
] }, d.id);
|
|
175
|
-
}) })
|
|
176
|
-
] }) : /* @__PURE__ */ jsxs(View, { style: styles.hero, children: [
|
|
177
|
-
/* @__PURE__ */ jsx(View, { style: [styles.heroIcon, {
|
|
178
|
-
backgroundColor: colors.primarySoft
|
|
179
|
-
}], children: /* @__PURE__ */ jsx(Ionicons, { name: "bluetooth", size: 30, color: colors.primary }) }),
|
|
180
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.heroTitle, {
|
|
181
|
-
color: colors.text
|
|
182
|
-
}], children: "Connect a device" }),
|
|
183
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.heroBody, {
|
|
184
|
-
color: colors.textMuted
|
|
185
|
-
}], children: [
|
|
186
|
-
"Pair a scale, blood-pressure monitor, heart-rate strap, pulse oximeter, thermometer or glucose meter. Each reading goes to your coach, and to ",
|
|
187
|
-
STORE_NAME,
|
|
188
|
-
" when you connected it."
|
|
189
|
-
] })
|
|
190
|
-
] }),
|
|
191
|
-
devices.lastError && devices.pendingDates.length ? /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "cloud-offline-outline", text: `Readings are kept on this phone and sent when Yantra can reach your coach. ${devices.lastError}` }) : null,
|
|
192
|
-
/* @__PURE__ */ jsx(View, { style: styles.actions, children: /* @__PURE__ */ jsx(PrimaryButton, { label: "Add a device", onPress: onAdd }) }),
|
|
193
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.footnote, {
|
|
194
|
-
color: colors.textMuted
|
|
195
|
-
}], children: [
|
|
196
|
-
"Devices that use the Bluetooth health standards pair here. For a brand scale with its own app, such as RENPHO or Withings, turn on its ",
|
|
197
|
-
STORE_NAME,
|
|
198
|
-
" sync; Yantra reads it there."
|
|
199
|
-
] }),
|
|
200
|
-
/* @__PURE__ */ jsxs(Pressable, { onPress: onHealth, accessibilityRole: "link", style: ({
|
|
201
|
-
pressed
|
|
202
|
-
}) => [styles.linkRow, pressed && styles.pressed], children: [
|
|
203
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.link, {
|
|
204
|
-
color: colors.primary
|
|
205
|
-
}], children: [
|
|
206
|
-
STORE_NAME,
|
|
207
|
-
" settings"
|
|
208
|
-
] }),
|
|
209
|
-
/* @__PURE__ */ jsx(Ionicons, { name: "chevron-forward", size: 14, color: colors.primary })
|
|
210
|
-
] })
|
|
211
|
-
] });
|
|
212
|
-
}
|
|
213
|
-
function PickKind({
|
|
214
|
-
colors,
|
|
215
|
-
isDark,
|
|
216
|
-
onPick
|
|
217
|
-
}) {
|
|
218
|
-
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
219
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.question, {
|
|
220
|
-
color: colors.text
|
|
221
|
-
}], children: "Which device do you want to connect?" }),
|
|
222
|
-
/* @__PURE__ */ jsx(View, { style: styles.kindList, children: DEVICE_KINDS.map((k) => /* @__PURE__ */ jsxs(Pressable, { onPress: () => onPick(k.id), accessibilityRole: "button", accessibilityLabel: k.title, style: ({
|
|
223
|
-
pressed
|
|
224
|
-
}) => [styles.kindCard, {
|
|
225
|
-
backgroundColor: colors.surface
|
|
226
|
-
}, pressed && {
|
|
227
|
-
backgroundColor: colors.surfaceMuted
|
|
228
|
-
}], children: [
|
|
229
|
-
/* @__PURE__ */ jsx(KindIcon, { kind: k.id, colors, large: true }),
|
|
230
|
-
/* @__PURE__ */ jsxs(View, { style: styles.deviceText, children: [
|
|
231
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.kindTitle, {
|
|
232
|
-
color: colors.text
|
|
233
|
-
}], children: k.title }),
|
|
234
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.deviceMeta, {
|
|
235
|
-
color: colors.textMuted
|
|
236
|
-
}], children: k.subtitle })
|
|
237
|
-
] }),
|
|
238
|
-
/* @__PURE__ */ jsx(Ionicons, { name: "chevron-forward", size: 16, color: isDark ? "#64748b" : "#c4c4c4" })
|
|
239
|
-
] }, k.id)) })
|
|
240
|
-
] });
|
|
241
|
-
}
|
|
242
|
-
function Measure({
|
|
243
|
-
kind,
|
|
244
|
-
deviceId,
|
|
245
|
-
colors,
|
|
246
|
-
units,
|
|
247
|
-
onDone,
|
|
248
|
-
onHealth
|
|
249
|
-
}) {
|
|
250
|
-
const {
|
|
251
|
-
snapshot,
|
|
252
|
-
session
|
|
253
|
-
} = useDeviceSession(kind, deviceId);
|
|
254
|
-
const {
|
|
255
|
-
state,
|
|
256
|
-
readings,
|
|
257
|
-
live,
|
|
258
|
-
recording,
|
|
259
|
-
notices
|
|
260
|
-
} = snapshot;
|
|
261
|
-
const info = deviceKind(kind);
|
|
262
|
-
const now = Date.now();
|
|
263
|
-
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
264
|
-
state.step === "starting" ? /* @__PURE__ */ jsx(ActivityIndicator, { style: styles.loading, color: colors.primary }) : null,
|
|
265
|
-
state.step === "unavailable" ? /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "information-circle", text: state.reason }) : null,
|
|
266
|
-
state.step === "radio" ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
267
|
-
/* @__PURE__ */ jsx(BluetoothPulse, { colors, active: false }),
|
|
268
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
269
|
-
color: colors.text
|
|
270
|
-
}], children: state.radio === "off" ? "Turn on Bluetooth" : state.radio === "unauthorized" ? "Allow Bluetooth for Yantra" : "This phone has no Bluetooth Yantra can use" }),
|
|
271
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.statusBody, {
|
|
272
|
-
color: colors.textMuted
|
|
273
|
-
}], children: state.radio === "off" ? "Yantra finds your device over Bluetooth." : state.radio === "unauthorized" ? "Yantra needs Bluetooth to find and read your device. Turn it on for Yantra in Settings." : "" }),
|
|
274
|
-
state.radio === "unauthorized" ? /* @__PURE__ */ jsx(PrimaryButton, { label: "Open Settings", onPress: () => void Linking.openSettings() }) : null,
|
|
275
|
-
state.radio === "off" ? /* @__PURE__ */ jsx(PrimaryButton, { label: "Try again", onPress: () => void (session == null ? void 0 : session.start()) }) : null
|
|
276
|
-
] }) : null,
|
|
277
|
-
state.step === "scanning" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
278
|
-
/* @__PURE__ */ jsx(BluetoothPulse, { colors, active: true }),
|
|
279
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
280
|
-
color: colors.text
|
|
281
|
-
}], children: deviceId ? "Looking for your device" : "Looking for devices nearby" }),
|
|
282
|
-
/* @__PURE__ */ jsx(View, { style: [styles.card, styles.guidance, {
|
|
283
|
-
backgroundColor: colors.surface
|
|
284
|
-
}], children: info.steps.map((line, i) => /* @__PURE__ */ jsxs(View, { style: styles.guidanceRow, children: [
|
|
285
|
-
/* @__PURE__ */ jsx(View, { style: [styles.stepDot, {
|
|
286
|
-
backgroundColor: colors.primarySoft
|
|
287
|
-
}], children: /* @__PURE__ */ jsx(Text, { style: [styles.stepNumber, {
|
|
288
|
-
color: colors.primary
|
|
289
|
-
}], children: i + 1 }) }),
|
|
290
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.guidanceText, {
|
|
291
|
-
color: colors.text
|
|
292
|
-
}], children: line })
|
|
293
|
-
] }, line)) }),
|
|
294
|
-
state.hint ? /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "information-circle", text: `Nothing yet. ${state.hint} Keep it close to the phone.` }) : null,
|
|
295
|
-
state.found.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
296
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.sectionTitle, {
|
|
297
|
-
color: colors.textMuted
|
|
298
|
-
}], children: "NEARBY" }),
|
|
299
|
-
/* @__PURE__ */ jsx(View, { style: [styles.card, {
|
|
300
|
-
backgroundColor: colors.surface
|
|
301
|
-
}], children: state.found.map((f, i) => /* @__PURE__ */ jsx(FoundRow, { found: f, first: i === 0, colors, onPress: () => void (session == null ? void 0 : session.pick(f)) }, f.id)) })
|
|
302
|
-
] }) : null
|
|
303
|
-
] }) : null,
|
|
304
|
-
state.step === "connecting" ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
305
|
-
/* @__PURE__ */ jsx(ActivityIndicator, { color: colors.primary, size: "large" }),
|
|
306
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.statusTitle, {
|
|
307
|
-
color: colors.text
|
|
308
|
-
}], children: [
|
|
309
|
-
"Connecting to ",
|
|
310
|
-
state.device.name
|
|
311
|
-
] }),
|
|
312
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.statusBody, {
|
|
313
|
-
color: colors.textMuted
|
|
314
|
-
}], children: "If your phone asks to pair, tap Pair." })
|
|
315
|
-
] }) : null,
|
|
316
|
-
state.step === "connected" && !readings.length && !live ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
317
|
-
/* @__PURE__ */ jsx(BluetoothPulse, { colors, active: true, connected: true }),
|
|
318
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
319
|
-
color: colors.text
|
|
320
|
-
}], children: info.waitingFor }),
|
|
321
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.statusBody, {
|
|
322
|
-
color: colors.textMuted
|
|
323
|
-
}], children: [
|
|
324
|
-
"Connected to ",
|
|
325
|
-
state.device.name,
|
|
326
|
-
"."
|
|
327
|
-
] })
|
|
328
|
-
] }) : null,
|
|
329
|
-
(state.step === "connected" || state.step === "ended") && live ? /* @__PURE__ */ jsx(LivePanel, { kind, colors, live, recording, connected: state.step === "connected", onStart: (type) => session == null ? void 0 : session.startRecording(type), onStop: () => void (session == null ? void 0 : session.stopRecording()), onSave: () => void (session == null ? void 0 : session.saveLive()) }) : null,
|
|
330
|
-
notices.map((n) => /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "information-circle", text: n }, n)),
|
|
331
|
-
readings.length ? /* @__PURE__ */ jsx(ReadingsCard, { title: "JUST MEASURED", readings, colors, units, now }) : null,
|
|
332
|
-
readings.length ? /* @__PURE__ */ jsx(SavedLine, { colors, onHealth }) : null,
|
|
333
|
-
state.step === "ended" ? /* @__PURE__ */ jsxs(View, { style: styles.actions, children: [
|
|
334
|
-
!readings.length ? /* @__PURE__ */ jsx(Text, { style: [styles.actionHint, {
|
|
335
|
-
color: colors.textMuted
|
|
336
|
-
}], children: "The device went to sleep before it sent a measurement." }) : null,
|
|
337
|
-
/* @__PURE__ */ jsx(PrimaryButton, { label: "Done", onPress: onDone }),
|
|
338
|
-
/* @__PURE__ */ jsx(SecondaryButton, { label: "Measure again", colors, onPress: () => session == null ? void 0 : session.scan() })
|
|
339
|
-
] }) : null,
|
|
340
|
-
state.step === "connected" && readings.length ? /* @__PURE__ */ jsx(View, { style: styles.actions, children: /* @__PURE__ */ jsx(PrimaryButton, { label: "Done", onPress: onDone }) }) : null,
|
|
341
|
-
state.step === "error" ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
342
|
-
/* @__PURE__ */ jsx(Ionicons, { name: "alert-circle", size: 40, color: colors.dangerText }),
|
|
343
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
344
|
-
color: colors.text
|
|
345
|
-
}], children: state.message }),
|
|
346
|
-
/* @__PURE__ */ jsx(PrimaryButton, { label: "Try again", onPress: () => void (session == null ? void 0 : session.start()) })
|
|
347
|
-
] }) : null
|
|
348
|
-
] });
|
|
349
|
-
}
|
|
350
|
-
function LivePanel({
|
|
351
|
-
kind,
|
|
352
|
-
colors,
|
|
353
|
-
live,
|
|
354
|
-
recording,
|
|
355
|
-
connected,
|
|
356
|
-
onStart,
|
|
357
|
-
onStop,
|
|
358
|
-
onSave
|
|
359
|
-
}) {
|
|
360
|
-
var _a, _b, _c, _d, _e;
|
|
361
|
-
const [type, setType] = useState("run");
|
|
362
|
-
const [, tick] = useState(0);
|
|
363
|
-
useEffect(() => {
|
|
364
|
-
if (!recording) return void 0;
|
|
365
|
-
const t = setInterval(() => tick((n) => n + 1), 1e3);
|
|
366
|
-
return () => clearInterval(t);
|
|
367
|
-
}, [recording]);
|
|
368
|
-
if (kind === "heart-rate") {
|
|
369
|
-
const elapsed = recording ? Math.max(0, Math.floor((Date.now() - recording.startedAt) / 1e3)) : 0;
|
|
370
|
-
return /* @__PURE__ */ jsxs(View, { style: [styles.card, styles.livePanel, {
|
|
371
|
-
backgroundColor: colors.surface
|
|
372
|
-
}], children: [
|
|
373
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.liveValue, {
|
|
374
|
-
color: colors.text
|
|
375
|
-
}], accessibilityLabel: `Heart rate ${(_a = live.bpm) != null ? _a : 0} beats per minute`, children: [
|
|
376
|
-
(_b = live.bpm) != null ? _b : "--",
|
|
377
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.liveUnit, {
|
|
378
|
-
color: colors.textMuted
|
|
379
|
-
}], children: " bpm" })
|
|
380
|
-
] }),
|
|
381
|
-
recording ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
382
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.liveMeta, {
|
|
383
|
-
color: colors.textMuted
|
|
384
|
-
}], children: [
|
|
385
|
-
clockOf(elapsed),
|
|
386
|
-
" \xB7 average ",
|
|
387
|
-
(_c = recording.avgHr) != null ? _c : "--",
|
|
388
|
-
" \xB7 max ",
|
|
389
|
-
(_d = recording.maxHr) != null ? _d : "--"
|
|
390
|
-
] }),
|
|
391
|
-
/* @__PURE__ */ jsx(PrimaryButton, { label: "Stop and save", onPress: onStop })
|
|
392
|
-
] }) : connected ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
393
|
-
/* @__PURE__ */ jsx(View, { style: styles.chips, children: WORKOUT_TYPES.map((w) => /* @__PURE__ */ jsx(Pressable, { onPress: () => setType(w.id), accessibilityRole: "radio", accessibilityState: {
|
|
394
|
-
selected: type === w.id
|
|
395
|
-
}, style: [styles.chip, {
|
|
396
|
-
borderColor: type === w.id ? colors.primary : colors.border
|
|
397
|
-
}, type === w.id && {
|
|
398
|
-
backgroundColor: colors.primarySoft
|
|
399
|
-
}], children: /* @__PURE__ */ jsx(Text, { style: [styles.chipLabel, {
|
|
400
|
-
color: type === w.id ? colors.primary : colors.text
|
|
401
|
-
}], children: w.label }) }, w.id)) }),
|
|
402
|
-
/* @__PURE__ */ jsx(PrimaryButton, { label: "Start session", onPress: () => onStart(type) })
|
|
403
|
-
] }) : null
|
|
404
|
-
] });
|
|
405
|
-
}
|
|
406
|
-
return /* @__PURE__ */ jsxs(View, { style: [styles.card, styles.livePanel, {
|
|
407
|
-
backgroundColor: colors.surface
|
|
408
|
-
}], children: [
|
|
409
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.liveValue, {
|
|
410
|
-
color: colors.text
|
|
411
|
-
}], children: [
|
|
412
|
-
(_e = live.spo2) != null ? _e : "--",
|
|
413
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.liveUnit, {
|
|
414
|
-
color: colors.textMuted
|
|
415
|
-
}], children: "%" })
|
|
416
|
-
] }),
|
|
417
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.liveMeta, {
|
|
418
|
-
color: colors.textMuted
|
|
419
|
-
}], children: [
|
|
420
|
-
"Blood oxygen",
|
|
421
|
-
live.pulse ? ` \xB7 pulse ${live.pulse}` : ""
|
|
422
|
-
] }),
|
|
423
|
-
connected ? /* @__PURE__ */ jsx(PrimaryButton, { label: "Save this reading", onPress: onSave }) : null
|
|
424
|
-
] });
|
|
425
|
-
}
|
|
426
|
-
function DeviceDetail({
|
|
427
|
-
id,
|
|
428
|
-
colors,
|
|
429
|
-
units,
|
|
430
|
-
onMeasure,
|
|
431
|
-
onForgot
|
|
432
|
-
}) {
|
|
433
|
-
const devices = useDevices();
|
|
434
|
-
const device = devices.devices.find((d) => d.id === id);
|
|
435
|
-
const readings = useMemo(() => devices.readings.filter((r) => r.deviceId === id).sort((a, b) => b.at - a.at).slice(0, 20), [devices.readings, id]);
|
|
436
|
-
if (!device) return null;
|
|
437
|
-
const forget = () => Alert.alert(`Forget ${device.name}?`, "Its readings stay in Yantra. To use it again, pair it again.", [{
|
|
438
|
-
text: "Cancel",
|
|
439
|
-
style: "cancel"
|
|
440
|
-
}, {
|
|
441
|
-
text: "Forget",
|
|
442
|
-
style: "destructive",
|
|
443
|
-
onPress: () => void deviceStore.forget(id).then(onForgot)
|
|
444
|
-
}]);
|
|
445
|
-
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
446
|
-
/* @__PURE__ */ jsxs(View, { style: styles.hero, children: [
|
|
447
|
-
/* @__PURE__ */ jsx(KindIcon, { kind: device.kind, colors, large: true }),
|
|
448
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.heroTitle, {
|
|
449
|
-
color: colors.text
|
|
450
|
-
}], children: device.name }),
|
|
451
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.heroBody, {
|
|
452
|
-
color: colors.textMuted
|
|
453
|
-
}], children: [
|
|
454
|
-
deviceKind(device.kind).title,
|
|
455
|
-
device.scaleUser ? ` \xB7 user ${device.scaleUser.userIndex} on this scale` : ""
|
|
456
|
-
] })
|
|
457
|
-
] }),
|
|
458
|
-
/* @__PURE__ */ jsx(View, { style: styles.actions, children: /* @__PURE__ */ jsx(PrimaryButton, { label: device.kind === "heart-rate" ? "Start a session" : "Take a reading", onPress: () => onMeasure(device.kind) }) }),
|
|
459
|
-
readings.length ? /* @__PURE__ */ jsx(ReadingsCard, { title: "READINGS", readings, colors, units, now: Date.now() }) : /* @__PURE__ */ jsx(Text, { style: [styles.footnote, {
|
|
460
|
-
color: colors.textMuted
|
|
461
|
-
}], children: "No readings from this device yet." }),
|
|
462
|
-
/* @__PURE__ */ jsx(View, { style: [styles.card, styles.secondaryCard, {
|
|
463
|
-
backgroundColor: colors.surface
|
|
464
|
-
}], children: /* @__PURE__ */ jsx(Pressable, { onPress: forget, accessibilityRole: "button", style: ({
|
|
465
|
-
pressed
|
|
466
|
-
}) => [styles.row, pressed && {
|
|
467
|
-
backgroundColor: colors.surfaceMuted
|
|
468
|
-
}], children: /* @__PURE__ */ jsx(Text, { style: [styles.rowLabelWide, {
|
|
469
|
-
color: colors.dangerText
|
|
470
|
-
}], children: "Forget this device" }) }) })
|
|
471
|
-
] });
|
|
472
|
-
}
|
|
473
|
-
function ReadingsCard({
|
|
474
|
-
title,
|
|
475
|
-
readings,
|
|
476
|
-
colors,
|
|
477
|
-
units,
|
|
478
|
-
now
|
|
479
|
-
}) {
|
|
480
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
481
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.sectionTitle, {
|
|
482
|
-
color: colors.textMuted
|
|
483
|
-
}], children: title }),
|
|
484
|
-
/* @__PURE__ */ jsx(View, { style: [styles.card, {
|
|
485
|
-
backgroundColor: colors.surface
|
|
486
|
-
}], children: readings.map((r, i) => {
|
|
487
|
-
var _a;
|
|
488
|
-
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
489
|
-
i > 0 ? /* @__PURE__ */ jsx(View, { style: [styles.rowLine, {
|
|
490
|
-
backgroundColor: colors.border
|
|
491
|
-
}] }) : null,
|
|
492
|
-
/* @__PURE__ */ jsxs(View, { style: styles.readingRow, children: [
|
|
493
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.readingValue, {
|
|
494
|
-
color: colors.text
|
|
495
|
-
}], children: describeReading(r, units) }),
|
|
496
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.readingWhen, {
|
|
497
|
-
color: colors.textMuted
|
|
498
|
-
}], children: whenLabel(r.at, now) }),
|
|
499
|
-
r.kind === "blood-pressure" && ((_a = r.problems) == null ? void 0 : _a.length) ? /* @__PURE__ */ jsx(Text, { style: [styles.readingNote, {
|
|
500
|
-
color: colors.warningText
|
|
501
|
-
}], children: r.problems.join(" ") }) : null
|
|
502
|
-
] })
|
|
503
|
-
] }, r.id);
|
|
504
|
-
}) })
|
|
505
|
-
] });
|
|
506
|
-
}
|
|
507
|
-
function SavedLine({
|
|
508
|
-
colors,
|
|
509
|
-
onHealth
|
|
510
|
-
}) {
|
|
511
|
-
const health = useHealthSync();
|
|
512
|
-
const [asked, setAsked] = useState(null);
|
|
513
|
-
useEffect(() => {
|
|
514
|
-
let live = true;
|
|
515
|
-
void platformWriter().then(async (w) => {
|
|
516
|
-
const a = w ? await w.asked().catch(() => true) : true;
|
|
517
|
-
if (live) setAsked(a);
|
|
518
|
-
});
|
|
519
|
-
return () => {
|
|
520
|
-
live = false;
|
|
521
|
-
};
|
|
522
|
-
}, [health.sync.connected]);
|
|
523
|
-
const allowSaving = async () => {
|
|
524
|
-
const w = await platformWriter();
|
|
525
|
-
if (!w) return;
|
|
526
|
-
await w.requestAccess().catch(() => void 0);
|
|
527
|
-
setAsked(true);
|
|
528
|
-
void deviceStore.flush();
|
|
529
|
-
};
|
|
530
|
-
if (!health.sync.connected) {
|
|
531
|
-
return /* @__PURE__ */ jsxs(Pressable, { onPress: onHealth, accessibilityRole: "link", style: ({
|
|
532
|
-
pressed
|
|
533
|
-
}) => [styles.savedLine, pressed && styles.pressed], children: [
|
|
534
|
-
/* @__PURE__ */ jsx(Ionicons, { name: "checkmark-circle", size: 18, color: colors.successText }),
|
|
535
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.savedText, {
|
|
536
|
-
color: colors.textMuted
|
|
537
|
-
}], children: [
|
|
538
|
-
"Saved for your coach. ",
|
|
539
|
-
/* @__PURE__ */ jsxs(Text, { style: {
|
|
540
|
-
color: colors.primary
|
|
541
|
-
}, children: [
|
|
542
|
-
"Connect ",
|
|
543
|
-
STORE_NAME
|
|
544
|
-
] }),
|
|
545
|
-
" to keep it there too."
|
|
546
|
-
] })
|
|
547
|
-
] });
|
|
548
|
-
}
|
|
549
|
-
if (asked === false) {
|
|
550
|
-
return /* @__PURE__ */ jsxs(View, { style: styles.savedBlock, children: [
|
|
551
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.savedText, {
|
|
552
|
-
color: colors.textMuted
|
|
553
|
-
}], children: "Saved for your coach." }),
|
|
554
|
-
/* @__PURE__ */ jsx(SecondaryButton, { label: `Also save to ${STORE_NAME}`, colors, onPress: () => void allowSaving() })
|
|
555
|
-
] });
|
|
556
|
-
}
|
|
557
|
-
return /* @__PURE__ */ jsxs(View, { style: styles.savedLine, children: [
|
|
558
|
-
/* @__PURE__ */ jsx(Ionicons, { name: "checkmark-circle", size: 18, color: colors.successText }),
|
|
559
|
-
/* @__PURE__ */ jsxs(Text, { style: [styles.savedText, {
|
|
560
|
-
color: colors.textMuted
|
|
561
|
-
}], children: [
|
|
562
|
-
"Saved for your coach and to ",
|
|
563
|
-
STORE_NAME,
|
|
564
|
-
"."
|
|
565
|
-
] })
|
|
566
|
-
] });
|
|
567
|
-
}
|
|
568
|
-
function FoundRow({
|
|
569
|
-
found,
|
|
570
|
-
first,
|
|
571
|
-
colors,
|
|
572
|
-
onPress
|
|
573
|
-
}) {
|
|
574
|
-
const bars = found.rssi === void 0 ? 1 : found.rssi > -60 ? 3 : found.rssi > -80 ? 2 : 1;
|
|
575
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
576
|
-
!first ? /* @__PURE__ */ jsx(View, { style: [styles.rowLine, {
|
|
577
|
-
backgroundColor: colors.border
|
|
578
|
-
}] }) : null,
|
|
579
|
-
/* @__PURE__ */ jsxs(Pressable, { onPress, accessibilityRole: "button", accessibilityLabel: `Connect ${found.name}`, style: ({
|
|
580
|
-
pressed
|
|
581
|
-
}) => [styles.deviceRow, pressed && {
|
|
582
|
-
backgroundColor: colors.surfaceMuted
|
|
583
|
-
}], children: [
|
|
584
|
-
found.kind ? /* @__PURE__ */ jsx(KindIcon, { kind: found.kind, colors }) : /* @__PURE__ */ jsx(Ionicons, { name: "bluetooth", size: 22, color: colors.primary }),
|
|
585
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.deviceName, styles.deviceText, {
|
|
586
|
-
color: colors.text
|
|
587
|
-
}], numberOfLines: 1, children: found.name }),
|
|
588
|
-
/* @__PURE__ */ jsx(View, { style: styles.signal, accessibilityLabel: `Signal ${bars} of 3`, children: [1, 2, 3].map((b) => /* @__PURE__ */ jsx(View, { style: [styles.signalBar, {
|
|
589
|
-
height: 4 + b * 4,
|
|
590
|
-
backgroundColor: b <= bars ? colors.primary : colors.border
|
|
591
|
-
}] }, b)) })
|
|
592
|
-
] })
|
|
593
|
-
] });
|
|
594
|
-
}
|
|
595
|
-
function KindIcon({
|
|
596
|
-
kind,
|
|
597
|
-
colors,
|
|
598
|
-
large
|
|
599
|
-
}) {
|
|
600
|
-
const size = large ? 48 : 36;
|
|
601
|
-
return /* @__PURE__ */ jsx(View, { style: [styles.kindIcon, {
|
|
602
|
-
width: size,
|
|
603
|
-
height: size,
|
|
604
|
-
borderRadius: size / 2,
|
|
605
|
-
backgroundColor: colors.primarySoft
|
|
606
|
-
}], children: /* @__PURE__ */ jsx(Ionicons, { name: deviceKind(kind).icon, size: large ? 24 : 18, color: colors.primary }) });
|
|
607
|
-
}
|
|
608
|
-
function BluetoothPulse({
|
|
609
|
-
colors,
|
|
610
|
-
active,
|
|
611
|
-
connected
|
|
612
|
-
}) {
|
|
613
|
-
const pulse = useRef(new Animated.Value(0)).current;
|
|
614
|
-
useEffect(() => {
|
|
615
|
-
if (!active) return void 0;
|
|
616
|
-
const loop = Animated.loop(Animated.timing(pulse, {
|
|
617
|
-
toValue: 1,
|
|
618
|
-
duration: 1600,
|
|
619
|
-
easing: Easing.out(Easing.ease),
|
|
620
|
-
useNativeDriver: true
|
|
621
|
-
}));
|
|
622
|
-
loop.start();
|
|
623
|
-
return () => loop.stop();
|
|
624
|
-
}, [active, pulse]);
|
|
625
|
-
const scale = pulse.interpolate({
|
|
626
|
-
inputRange: [0, 1],
|
|
627
|
-
outputRange: [1, 1.9]
|
|
628
|
-
});
|
|
629
|
-
const opacity = pulse.interpolate({
|
|
630
|
-
inputRange: [0, 1],
|
|
631
|
-
outputRange: [0.45, 0]
|
|
632
|
-
});
|
|
633
|
-
return /* @__PURE__ */ jsxs(View, { style: styles.pulseBox, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: [
|
|
634
|
-
active ? /* @__PURE__ */ jsx(Animated.View, { style: [styles.pulseRing, {
|
|
635
|
-
backgroundColor: colors.primary,
|
|
636
|
-
opacity,
|
|
637
|
-
transform: [{
|
|
638
|
-
scale
|
|
639
|
-
}]
|
|
640
|
-
}] }) : null,
|
|
641
|
-
/* @__PURE__ */ jsx(View, { style: [styles.pulseCore, {
|
|
642
|
-
backgroundColor: connected ? colors.successText : colors.primary
|
|
643
|
-
}], children: /* @__PURE__ */ jsx(Ionicons, { name: connected ? "checkmark" : "bluetooth", size: 28, color: "#fff" }) })
|
|
644
|
-
] });
|
|
645
|
-
}
|
|
646
|
-
function Notice({
|
|
647
|
-
colors,
|
|
648
|
-
tone,
|
|
649
|
-
icon,
|
|
650
|
-
text
|
|
651
|
-
}) {
|
|
652
|
-
const bg = tone === "danger" ? colors.dangerSoft : colors.warningSoft;
|
|
653
|
-
const fg = tone === "danger" ? colors.dangerText : colors.warningText;
|
|
654
|
-
return /* @__PURE__ */ jsxs(View, { style: [styles.notice, {
|
|
655
|
-
backgroundColor: bg
|
|
656
|
-
}], accessibilityRole: "alert", children: [
|
|
657
|
-
/* @__PURE__ */ jsx(Ionicons, { name: icon, size: 18, color: fg, style: styles.noticeIcon }),
|
|
658
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.noticeText, {
|
|
659
|
-
color: fg
|
|
660
|
-
}], children: text })
|
|
661
|
-
] });
|
|
662
|
-
}
|
|
663
|
-
function PrimaryButton({
|
|
664
|
-
label,
|
|
665
|
-
onPress
|
|
666
|
-
}) {
|
|
667
|
-
return /* @__PURE__ */ jsx(Pressable, { onPress, accessibilityRole: "button", accessibilityLabel: label, style: ({
|
|
668
|
-
pressed
|
|
669
|
-
}) => [styles.primary, pressed && styles.pressed], children: /* @__PURE__ */ jsx(Text, { style: styles.primaryLabel, children: label }) });
|
|
670
|
-
}
|
|
671
|
-
function SecondaryButton({
|
|
672
|
-
label,
|
|
673
|
-
onPress,
|
|
674
|
-
colors
|
|
675
|
-
}) {
|
|
676
|
-
return /* @__PURE__ */ jsx(Pressable, { onPress, accessibilityRole: "button", accessibilityLabel: label, style: ({
|
|
677
|
-
pressed
|
|
678
|
-
}) => [styles.secondary, {
|
|
679
|
-
borderColor: colors.border,
|
|
680
|
-
backgroundColor: colors.surface
|
|
681
|
-
}, pressed && styles.pressed], children: /* @__PURE__ */ jsx(Text, { style: [styles.secondaryLabel, {
|
|
682
|
-
color: colors.text
|
|
683
|
-
}], children: label }) });
|
|
684
|
-
}
|
|
685
|
-
function whenLabel(at, now) {
|
|
686
|
-
const d = new Date(at);
|
|
687
|
-
const time = d.toLocaleTimeString(void 0, {
|
|
688
|
-
hour: "numeric",
|
|
689
|
-
minute: "2-digit"
|
|
690
|
-
});
|
|
691
|
-
const startOf = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
692
|
-
const days = Math.round((startOf(new Date(now)) - startOf(d)) / 864e5);
|
|
693
|
-
if (days === 0) return `Today, ${time}`;
|
|
694
|
-
if (days === 1) return `Yesterday, ${time}`;
|
|
695
|
-
return d.toLocaleDateString(void 0, {
|
|
696
|
-
month: "short",
|
|
697
|
-
day: "numeric"
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
function clockOf(seconds) {
|
|
701
|
-
const m = Math.floor(seconds / 60);
|
|
702
|
-
const s = seconds % 60;
|
|
703
|
-
return `${m}:${String(s).padStart(2, "0")}`;
|
|
704
|
-
}
|
|
705
39
|
const styles = StyleSheet.create({
|
|
706
40
|
safe: {
|
|
707
41
|
flex: 1
|
|
@@ -767,7 +101,9 @@ const styles = StyleSheet.create({
|
|
|
767
101
|
},
|
|
768
102
|
card: {
|
|
769
103
|
borderRadius: 16,
|
|
770
|
-
overflow: "hidden"
|
|
104
|
+
overflow: "hidden",
|
|
105
|
+
borderWidth: 1,
|
|
106
|
+
borderColor: CARD_EDGE
|
|
771
107
|
},
|
|
772
108
|
secondaryCard: {
|
|
773
109
|
marginTop: 20
|
|
@@ -834,7 +170,9 @@ const styles = StyleSheet.create({
|
|
|
834
170
|
alignItems: "center",
|
|
835
171
|
borderRadius: 16,
|
|
836
172
|
padding: 14,
|
|
837
|
-
gap: 14
|
|
173
|
+
gap: 14,
|
|
174
|
+
borderWidth: 1,
|
|
175
|
+
borderColor: CARD_EDGE
|
|
838
176
|
},
|
|
839
177
|
kindTitle: {
|
|
840
178
|
fontSize: 16,
|
|
@@ -1052,4 +390,725 @@ const styles = StyleSheet.create({
|
|
|
1052
390
|
fontSize: 14,
|
|
1053
391
|
fontWeight: "600"
|
|
1054
392
|
}
|
|
1055
|
-
});
|
|
393
|
+
});
|
|
394
|
+
function stepTitle(step, paired) {
|
|
395
|
+
var _a, _b;
|
|
396
|
+
switch (step.name) {
|
|
397
|
+
case "pick":
|
|
398
|
+
return "Add a device";
|
|
399
|
+
case "measure":
|
|
400
|
+
return deviceKind(step.kind).title;
|
|
401
|
+
case "device":
|
|
402
|
+
return (_b = (_a = paired.find((d) => d.id === step.id)) == null ? void 0 : _a.name) != null ? _b : "Device";
|
|
403
|
+
default:
|
|
404
|
+
return "Devices";
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function radioCopy(radio) {
|
|
408
|
+
if (radio === "off") return {
|
|
409
|
+
title: "Turn on Bluetooth",
|
|
410
|
+
body: "Yantra finds your device over Bluetooth."
|
|
411
|
+
};
|
|
412
|
+
if (radio === "unauthorized") {
|
|
413
|
+
return {
|
|
414
|
+
title: "Allow Bluetooth for Yantra",
|
|
415
|
+
body: "Yantra needs Bluetooth to find and read your device. Turn it on for Yantra in Settings."
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
title: "This phone has no Bluetooth Yantra can use",
|
|
420
|
+
body: ""
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
function signalBars(rssi) {
|
|
424
|
+
if (rssi === void 0) return 1;
|
|
425
|
+
if (rssi > -60) return 3;
|
|
426
|
+
if (rssi > -80) return 2;
|
|
427
|
+
return 1;
|
|
428
|
+
}
|
|
429
|
+
function whenLabel(at, now) {
|
|
430
|
+
const d = new Date(at);
|
|
431
|
+
const time = d.toLocaleTimeString(void 0, {
|
|
432
|
+
hour: "numeric",
|
|
433
|
+
minute: "2-digit"
|
|
434
|
+
});
|
|
435
|
+
const startOf = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
436
|
+
const days = Math.round((startOf(new Date(now)) - startOf(d)) / 864e5);
|
|
437
|
+
if (days === 0) return `Today, ${time}`;
|
|
438
|
+
if (days === 1) return `Yesterday, ${time}`;
|
|
439
|
+
return d.toLocaleDateString(void 0, {
|
|
440
|
+
month: "short",
|
|
441
|
+
day: "numeric"
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
function keepTogether(text) {
|
|
445
|
+
return text.replace(/\s/g, "\xA0");
|
|
446
|
+
}
|
|
447
|
+
function clockOf(seconds) {
|
|
448
|
+
const m = Math.floor(seconds / 60);
|
|
449
|
+
const s = seconds % 60;
|
|
450
|
+
return `${m}:${String(s).padStart(2, "0")}`;
|
|
451
|
+
}
|
|
452
|
+
function KindIcon({
|
|
453
|
+
kind,
|
|
454
|
+
colors,
|
|
455
|
+
large
|
|
456
|
+
}) {
|
|
457
|
+
const size = large ? 48 : 36;
|
|
458
|
+
return /* @__PURE__ */ jsx(View, { style: [styles.kindIcon, {
|
|
459
|
+
width: size,
|
|
460
|
+
height: size,
|
|
461
|
+
borderRadius: size / 2,
|
|
462
|
+
backgroundColor: colors.primarySoft
|
|
463
|
+
}], children: /* @__PURE__ */ jsx(Ionicons, { name: deviceKind(kind).icon, size: large ? 24 : 18, color: colors.primary }) });
|
|
464
|
+
}
|
|
465
|
+
function BluetoothPulse({
|
|
466
|
+
colors,
|
|
467
|
+
active,
|
|
468
|
+
connected
|
|
469
|
+
}) {
|
|
470
|
+
const pulse = useRef(new Animated.Value(0)).current;
|
|
471
|
+
useEffect(() => {
|
|
472
|
+
if (!active) return void 0;
|
|
473
|
+
const loop = Animated.loop(Animated.timing(pulse, {
|
|
474
|
+
toValue: 1,
|
|
475
|
+
duration: 1600,
|
|
476
|
+
easing: Easing.out(Easing.ease),
|
|
477
|
+
useNativeDriver: true
|
|
478
|
+
}));
|
|
479
|
+
loop.start();
|
|
480
|
+
return () => loop.stop();
|
|
481
|
+
}, [active, pulse]);
|
|
482
|
+
const scale = pulse.interpolate({
|
|
483
|
+
inputRange: [0, 1],
|
|
484
|
+
outputRange: [1, 1.9]
|
|
485
|
+
});
|
|
486
|
+
const opacity = pulse.interpolate({
|
|
487
|
+
inputRange: [0, 1],
|
|
488
|
+
outputRange: [0.45, 0]
|
|
489
|
+
});
|
|
490
|
+
return /* @__PURE__ */ jsxs(View, { style: styles.pulseBox, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: [
|
|
491
|
+
active ? /* @__PURE__ */ jsx(Animated.View, { style: [styles.pulseRing, {
|
|
492
|
+
backgroundColor: colors.primary,
|
|
493
|
+
opacity,
|
|
494
|
+
transform: [{
|
|
495
|
+
scale
|
|
496
|
+
}]
|
|
497
|
+
}] }) : null,
|
|
498
|
+
/* @__PURE__ */ jsx(View, { style: [styles.pulseCore, {
|
|
499
|
+
backgroundColor: connected ? colors.successText : colors.primary
|
|
500
|
+
}], children: /* @__PURE__ */ jsx(Ionicons, { name: connected ? "checkmark" : "bluetooth", size: 28, color: "#fff" }) })
|
|
501
|
+
] });
|
|
502
|
+
}
|
|
503
|
+
function Notice({
|
|
504
|
+
colors,
|
|
505
|
+
tone,
|
|
506
|
+
icon,
|
|
507
|
+
text
|
|
508
|
+
}) {
|
|
509
|
+
const bg = tone === "danger" ? colors.dangerSoft : colors.warningSoft;
|
|
510
|
+
const fg = tone === "danger" ? colors.dangerText : colors.warningText;
|
|
511
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles.notice, {
|
|
512
|
+
backgroundColor: bg
|
|
513
|
+
}], accessibilityRole: "alert", children: [
|
|
514
|
+
/* @__PURE__ */ jsx(Ionicons, { name: icon, size: 18, color: fg, style: styles.noticeIcon }),
|
|
515
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.noticeText, {
|
|
516
|
+
color: fg
|
|
517
|
+
}], children: text })
|
|
518
|
+
] });
|
|
519
|
+
}
|
|
520
|
+
function PrimaryButton({
|
|
521
|
+
label,
|
|
522
|
+
onPress
|
|
523
|
+
}) {
|
|
524
|
+
return /* @__PURE__ */ jsx(Pressable, { onPress, accessibilityRole: "button", accessibilityLabel: label, style: ({
|
|
525
|
+
pressed
|
|
526
|
+
}) => [styles.primary, pressed && styles.pressed], children: /* @__PURE__ */ jsx(Text, { style: styles.primaryLabel, children: label }) });
|
|
527
|
+
}
|
|
528
|
+
function SecondaryButton({
|
|
529
|
+
label,
|
|
530
|
+
onPress,
|
|
531
|
+
colors
|
|
532
|
+
}) {
|
|
533
|
+
return /* @__PURE__ */ jsx(Pressable, { onPress, accessibilityRole: "button", accessibilityLabel: label, style: ({
|
|
534
|
+
pressed
|
|
535
|
+
}) => [styles.secondary, {
|
|
536
|
+
borderColor: colors.border,
|
|
537
|
+
backgroundColor: colors.surface
|
|
538
|
+
}, pressed && styles.pressed], children: /* @__PURE__ */ jsx(Text, { style: [styles.secondaryLabel, {
|
|
539
|
+
color: colors.text
|
|
540
|
+
}], children: label }) });
|
|
541
|
+
}
|
|
542
|
+
function ReadingsCard({
|
|
543
|
+
title,
|
|
544
|
+
readings,
|
|
545
|
+
colors,
|
|
546
|
+
units,
|
|
547
|
+
now
|
|
548
|
+
}) {
|
|
549
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
550
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.sectionTitle, {
|
|
551
|
+
color: colors.textMuted
|
|
552
|
+
}], children: title }),
|
|
553
|
+
/* @__PURE__ */ jsx(View, { style: [styles.card, {
|
|
554
|
+
backgroundColor: colors.surface
|
|
555
|
+
}], children: readings.map((r, i) => {
|
|
556
|
+
var _a;
|
|
557
|
+
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
558
|
+
i > 0 ? /* @__PURE__ */ jsx(View, { style: [styles.rowLine, {
|
|
559
|
+
backgroundColor: colors.border
|
|
560
|
+
}] }) : null,
|
|
561
|
+
/* @__PURE__ */ jsxs(View, { style: styles.readingRow, children: [
|
|
562
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.readingValue, {
|
|
563
|
+
color: colors.text
|
|
564
|
+
}], children: describeReading(r, units) }),
|
|
565
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.readingWhen, {
|
|
566
|
+
color: colors.textMuted
|
|
567
|
+
}], children: whenLabel(r.at, now) }),
|
|
568
|
+
r.kind === "blood-pressure" && ((_a = r.problems) == null ? void 0 : _a.length) ? /* @__PURE__ */ jsx(Text, { style: [styles.readingNote, {
|
|
569
|
+
color: colors.warningText
|
|
570
|
+
}], children: r.problems.join(" ") }) : null
|
|
571
|
+
] })
|
|
572
|
+
] }, r.id);
|
|
573
|
+
}) })
|
|
574
|
+
] });
|
|
575
|
+
}
|
|
576
|
+
function SavedLine({
|
|
577
|
+
colors,
|
|
578
|
+
onHealth
|
|
579
|
+
}) {
|
|
580
|
+
const health = useHealthSync();
|
|
581
|
+
const [asked, setAsked] = useState(null);
|
|
582
|
+
useEffect(() => {
|
|
583
|
+
let live = true;
|
|
584
|
+
void platformWriter().then(async (w) => {
|
|
585
|
+
const a = w ? await w.asked().catch(() => true) : true;
|
|
586
|
+
if (live) setAsked(a);
|
|
587
|
+
});
|
|
588
|
+
return () => {
|
|
589
|
+
live = false;
|
|
590
|
+
};
|
|
591
|
+
}, [health.sync.connected]);
|
|
592
|
+
const allowSaving = async () => {
|
|
593
|
+
const w = await platformWriter();
|
|
594
|
+
if (!w) return;
|
|
595
|
+
await w.requestAccess().catch(() => void 0);
|
|
596
|
+
setAsked(true);
|
|
597
|
+
void deviceStore.flush();
|
|
598
|
+
};
|
|
599
|
+
if (!health.sync.connected) {
|
|
600
|
+
return /* @__PURE__ */ jsxs(Pressable, { onPress: onHealth, accessibilityRole: "link", style: ({
|
|
601
|
+
pressed
|
|
602
|
+
}) => [styles.savedLine, pressed && styles.pressed], children: [
|
|
603
|
+
/* @__PURE__ */ jsx(Ionicons, { name: "checkmark-circle", size: 18, color: colors.successText }),
|
|
604
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.savedText, {
|
|
605
|
+
color: colors.textMuted
|
|
606
|
+
}], children: [
|
|
607
|
+
"Saved for your coach. ",
|
|
608
|
+
/* @__PURE__ */ jsxs(Text, { style: {
|
|
609
|
+
color: colors.primary
|
|
610
|
+
}, children: [
|
|
611
|
+
"Connect ",
|
|
612
|
+
STORE_NAME
|
|
613
|
+
] }),
|
|
614
|
+
" to keep it there too."
|
|
615
|
+
] })
|
|
616
|
+
] });
|
|
617
|
+
}
|
|
618
|
+
if (asked === false) {
|
|
619
|
+
return /* @__PURE__ */ jsxs(View, { style: styles.savedBlock, children: [
|
|
620
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.savedText, {
|
|
621
|
+
color: colors.textMuted
|
|
622
|
+
}], children: "Saved for your coach." }),
|
|
623
|
+
/* @__PURE__ */ jsx(SecondaryButton, { label: `Also save to ${STORE_NAME}`, colors, onPress: () => {
|
|
624
|
+
void allowSaving();
|
|
625
|
+
} })
|
|
626
|
+
] });
|
|
627
|
+
}
|
|
628
|
+
return /* @__PURE__ */ jsxs(View, { style: styles.savedLine, children: [
|
|
629
|
+
/* @__PURE__ */ jsx(Ionicons, { name: "checkmark-circle", size: 18, color: colors.successText }),
|
|
630
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.savedText, {
|
|
631
|
+
color: colors.textMuted
|
|
632
|
+
}], children: [
|
|
633
|
+
"Saved for your coach and to ",
|
|
634
|
+
STORE_NAME,
|
|
635
|
+
"."
|
|
636
|
+
] })
|
|
637
|
+
] });
|
|
638
|
+
}
|
|
639
|
+
function FoundRow({
|
|
640
|
+
found,
|
|
641
|
+
first,
|
|
642
|
+
colors,
|
|
643
|
+
onPress
|
|
644
|
+
}) {
|
|
645
|
+
const bars = signalBars(found.rssi);
|
|
646
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
647
|
+
!first ? /* @__PURE__ */ jsx(View, { style: [styles.rowLine, {
|
|
648
|
+
backgroundColor: colors.border
|
|
649
|
+
}] }) : null,
|
|
650
|
+
/* @__PURE__ */ jsxs(Pressable, { onPress, accessibilityRole: "button", accessibilityLabel: `Connect ${found.name}`, style: ({
|
|
651
|
+
pressed
|
|
652
|
+
}) => [styles.deviceRow, pressed && {
|
|
653
|
+
backgroundColor: colors.surfaceMuted
|
|
654
|
+
}], children: [
|
|
655
|
+
found.kind ? /* @__PURE__ */ jsx(KindIcon, { kind: found.kind, colors }) : /* @__PURE__ */ jsx(Ionicons, { name: "bluetooth", size: 22, color: colors.primary }),
|
|
656
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.deviceName, styles.deviceText, {
|
|
657
|
+
color: colors.text
|
|
658
|
+
}], numberOfLines: 1, children: found.name }),
|
|
659
|
+
/* @__PURE__ */ jsx(View, { style: styles.signal, accessibilityLabel: `Signal ${bars} of 3`, children: [1, 2, 3].map((b) => /* @__PURE__ */ jsx(View, { style: [styles.signalBar, {
|
|
660
|
+
height: 4 + b * 4,
|
|
661
|
+
backgroundColor: b <= bars ? colors.primary : colors.border
|
|
662
|
+
}] }, b)) })
|
|
663
|
+
] })
|
|
664
|
+
] });
|
|
665
|
+
}
|
|
666
|
+
function Home({
|
|
667
|
+
colors,
|
|
668
|
+
isDark,
|
|
669
|
+
units,
|
|
670
|
+
onAdd,
|
|
671
|
+
onOpen,
|
|
672
|
+
onHealth
|
|
673
|
+
}) {
|
|
674
|
+
const devices = useDevices();
|
|
675
|
+
const now = Date.now();
|
|
676
|
+
if (!devices.loaded) return /* @__PURE__ */ jsx(ActivityIndicator, { style: styles.loading, color: colors.primary });
|
|
677
|
+
const latestOf = (d) => devices.readings.filter((r) => r.deviceId === d.id).reduce((a, b) => !a || b.at > a.at ? b : a, void 0);
|
|
678
|
+
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
679
|
+
devices.devices.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
680
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.sectionTitle, {
|
|
681
|
+
color: colors.textMuted
|
|
682
|
+
}], children: "MY DEVICES" }),
|
|
683
|
+
/* @__PURE__ */ jsx(View, { style: [styles.card, {
|
|
684
|
+
backgroundColor: colors.surface
|
|
685
|
+
}], children: devices.devices.map((d, i) => {
|
|
686
|
+
const latest = latestOf(d);
|
|
687
|
+
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
688
|
+
i > 0 ? /* @__PURE__ */ jsx(View, { style: [styles.rowLine, {
|
|
689
|
+
backgroundColor: colors.border
|
|
690
|
+
}] }) : null,
|
|
691
|
+
/* @__PURE__ */ jsxs(Pressable, { onPress: () => onOpen(d.id), accessibilityRole: "button", accessibilityLabel: d.name, style: ({
|
|
692
|
+
pressed
|
|
693
|
+
}) => [styles.deviceRow, pressed && {
|
|
694
|
+
backgroundColor: colors.surfaceMuted
|
|
695
|
+
}], children: [
|
|
696
|
+
/* @__PURE__ */ jsx(KindIcon, { kind: d.kind, colors }),
|
|
697
|
+
/* @__PURE__ */ jsxs(View, { style: styles.deviceText, children: [
|
|
698
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.deviceName, {
|
|
699
|
+
color: colors.text
|
|
700
|
+
}], numberOfLines: 1, children: d.name }),
|
|
701
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.deviceMeta, {
|
|
702
|
+
color: colors.textMuted
|
|
703
|
+
}], numberOfLines: 2, children: latest ? `${describeReading(latest, units)} \xB7 ${keepTogether(whenLabel(latest.at, now))}` : "No readings yet" })
|
|
704
|
+
] }),
|
|
705
|
+
/* @__PURE__ */ jsx(Ionicons, { name: "chevron-forward", size: 16, color: isDark ? "#64748b" : "#c4c4c4" })
|
|
706
|
+
] })
|
|
707
|
+
] }, d.id);
|
|
708
|
+
}) })
|
|
709
|
+
] }) : /* @__PURE__ */ jsxs(View, { style: styles.hero, children: [
|
|
710
|
+
/* @__PURE__ */ jsx(View, { style: [styles.heroIcon, {
|
|
711
|
+
backgroundColor: colors.primarySoft
|
|
712
|
+
}], children: /* @__PURE__ */ jsx(Ionicons, { name: "bluetooth", size: 30, color: colors.primary }) }),
|
|
713
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.heroTitle, {
|
|
714
|
+
color: colors.text
|
|
715
|
+
}], children: "Connect a device" }),
|
|
716
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.heroBody, {
|
|
717
|
+
color: colors.textMuted
|
|
718
|
+
}], children: [
|
|
719
|
+
"Pair a scale, blood-pressure monitor, heart-rate strap, pulse oximeter, thermometer or glucose meter. Each reading goes to your coach, and to ",
|
|
720
|
+
STORE_NAME,
|
|
721
|
+
" when you connected it."
|
|
722
|
+
] })
|
|
723
|
+
] }),
|
|
724
|
+
devices.lastError && devices.pendingDates.length ? /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "cloud-offline-outline", text: `Readings are kept on this phone and sent when Yantra can reach your coach. ${devices.lastError}` }) : null,
|
|
725
|
+
/* @__PURE__ */ jsx(View, { style: styles.actions, children: /* @__PURE__ */ jsx(PrimaryButton, { label: "Add a device", onPress: onAdd }) }),
|
|
726
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.footnote, {
|
|
727
|
+
color: colors.textMuted
|
|
728
|
+
}], children: [
|
|
729
|
+
"Devices that use the Bluetooth health standards pair here. For a brand scale with its own app, such as RENPHO or Withings, turn on its ",
|
|
730
|
+
STORE_NAME,
|
|
731
|
+
" sync; Yantra reads it there."
|
|
732
|
+
] }),
|
|
733
|
+
/* @__PURE__ */ jsxs(Pressable, { onPress: onHealth, accessibilityRole: "link", style: ({
|
|
734
|
+
pressed
|
|
735
|
+
}) => [styles.linkRow, pressed && styles.pressed], children: [
|
|
736
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.link, {
|
|
737
|
+
color: colors.primary
|
|
738
|
+
}], children: [
|
|
739
|
+
STORE_NAME,
|
|
740
|
+
" settings"
|
|
741
|
+
] }),
|
|
742
|
+
/* @__PURE__ */ jsx(Ionicons, { name: "chevron-forward", size: 14, color: colors.primary })
|
|
743
|
+
] })
|
|
744
|
+
] });
|
|
745
|
+
}
|
|
746
|
+
function PickKind({
|
|
747
|
+
colors,
|
|
748
|
+
isDark,
|
|
749
|
+
onPick
|
|
750
|
+
}) {
|
|
751
|
+
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
752
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.question, {
|
|
753
|
+
color: colors.text
|
|
754
|
+
}], children: "Which device do you want to connect?" }),
|
|
755
|
+
/* @__PURE__ */ jsx(View, { style: styles.kindList, children: DEVICE_KINDS.map((k) => /* @__PURE__ */ jsxs(Pressable, { onPress: () => onPick(k.id), accessibilityRole: "button", accessibilityLabel: k.title, style: ({
|
|
756
|
+
pressed
|
|
757
|
+
}) => [styles.kindCard, {
|
|
758
|
+
backgroundColor: colors.surface
|
|
759
|
+
}, pressed && {
|
|
760
|
+
backgroundColor: colors.surfaceMuted
|
|
761
|
+
}], children: [
|
|
762
|
+
/* @__PURE__ */ jsx(KindIcon, { kind: k.id, colors, large: true }),
|
|
763
|
+
/* @__PURE__ */ jsxs(View, { style: styles.deviceText, children: [
|
|
764
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.kindTitle, {
|
|
765
|
+
color: colors.text
|
|
766
|
+
}], children: k.title }),
|
|
767
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.deviceMeta, {
|
|
768
|
+
color: colors.textMuted
|
|
769
|
+
}], children: k.subtitle })
|
|
770
|
+
] }),
|
|
771
|
+
/* @__PURE__ */ jsx(Ionicons, { name: "chevron-forward", size: 16, color: isDark ? "#64748b" : "#c4c4c4" })
|
|
772
|
+
] }, k.id)) })
|
|
773
|
+
] });
|
|
774
|
+
}
|
|
775
|
+
function LivePanel({
|
|
776
|
+
kind,
|
|
777
|
+
colors,
|
|
778
|
+
live,
|
|
779
|
+
recording,
|
|
780
|
+
connected,
|
|
781
|
+
onStart,
|
|
782
|
+
onStop,
|
|
783
|
+
onSave
|
|
784
|
+
}) {
|
|
785
|
+
var _a, _b, _c, _d, _e;
|
|
786
|
+
const [type, setType] = useState("run");
|
|
787
|
+
const [, tick] = useState(0);
|
|
788
|
+
useEffect(() => {
|
|
789
|
+
if (!recording) return void 0;
|
|
790
|
+
const t = setInterval(() => tick((n) => n + 1), 1e3);
|
|
791
|
+
return () => clearInterval(t);
|
|
792
|
+
}, [recording]);
|
|
793
|
+
if (kind === "heart-rate") {
|
|
794
|
+
const elapsed = recording ? Math.max(0, Math.floor((Date.now() - recording.startedAt) / 1e3)) : 0;
|
|
795
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles.card, styles.livePanel, {
|
|
796
|
+
backgroundColor: colors.surface
|
|
797
|
+
}], children: [
|
|
798
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.liveValue, {
|
|
799
|
+
color: colors.text
|
|
800
|
+
}], accessibilityLabel: `Heart rate ${(_a = live.bpm) != null ? _a : 0} beats per minute`, children: [
|
|
801
|
+
(_b = live.bpm) != null ? _b : "--",
|
|
802
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.liveUnit, {
|
|
803
|
+
color: colors.textMuted
|
|
804
|
+
}], children: " bpm" })
|
|
805
|
+
] }),
|
|
806
|
+
recording ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
807
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.liveMeta, {
|
|
808
|
+
color: colors.textMuted
|
|
809
|
+
}], children: [
|
|
810
|
+
clockOf(elapsed),
|
|
811
|
+
" \xB7 average ",
|
|
812
|
+
(_c = recording.avgHr) != null ? _c : "--",
|
|
813
|
+
" \xB7 max ",
|
|
814
|
+
(_d = recording.maxHr) != null ? _d : "--"
|
|
815
|
+
] }),
|
|
816
|
+
/* @__PURE__ */ jsx(PrimaryButton, { label: "Stop and save", onPress: onStop })
|
|
817
|
+
] }) : null,
|
|
818
|
+
!recording && connected ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
819
|
+
/* @__PURE__ */ jsx(View, { style: styles.chips, children: WORKOUT_TYPES.map((w) => /* @__PURE__ */ jsx(Pressable, { onPress: () => setType(w.id), accessibilityRole: "radio", accessibilityState: {
|
|
820
|
+
selected: type === w.id
|
|
821
|
+
}, style: [styles.chip, {
|
|
822
|
+
borderColor: type === w.id ? colors.primary : colors.border
|
|
823
|
+
}, type === w.id && {
|
|
824
|
+
backgroundColor: colors.primarySoft
|
|
825
|
+
}], children: /* @__PURE__ */ jsx(Text, { style: [styles.chipLabel, {
|
|
826
|
+
color: type === w.id ? colors.primary : colors.text
|
|
827
|
+
}], children: w.label }) }, w.id)) }),
|
|
828
|
+
/* @__PURE__ */ jsx(PrimaryButton, { label: "Start session", onPress: () => onStart(type) })
|
|
829
|
+
] }) : null
|
|
830
|
+
] });
|
|
831
|
+
}
|
|
832
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles.card, styles.livePanel, {
|
|
833
|
+
backgroundColor: colors.surface
|
|
834
|
+
}], children: [
|
|
835
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.liveValue, {
|
|
836
|
+
color: colors.text
|
|
837
|
+
}], children: [
|
|
838
|
+
(_e = live.spo2) != null ? _e : "--",
|
|
839
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.liveUnit, {
|
|
840
|
+
color: colors.textMuted
|
|
841
|
+
}], children: "%" })
|
|
842
|
+
] }),
|
|
843
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.liveMeta, {
|
|
844
|
+
color: colors.textMuted
|
|
845
|
+
}], children: [
|
|
846
|
+
"Blood oxygen",
|
|
847
|
+
live.pulse ? ` \xB7 pulse ${live.pulse}` : ""
|
|
848
|
+
] }),
|
|
849
|
+
connected ? /* @__PURE__ */ jsx(PrimaryButton, { label: "Save this reading", onPress: onSave }) : null
|
|
850
|
+
] });
|
|
851
|
+
}
|
|
852
|
+
function Measure({
|
|
853
|
+
kind,
|
|
854
|
+
deviceId,
|
|
855
|
+
colors,
|
|
856
|
+
units,
|
|
857
|
+
onDone,
|
|
858
|
+
onHealth
|
|
859
|
+
}) {
|
|
860
|
+
const {
|
|
861
|
+
snapshot,
|
|
862
|
+
session
|
|
863
|
+
} = useDeviceSession(kind, deviceId);
|
|
864
|
+
const {
|
|
865
|
+
state,
|
|
866
|
+
readings,
|
|
867
|
+
live,
|
|
868
|
+
recording,
|
|
869
|
+
notices
|
|
870
|
+
} = snapshot;
|
|
871
|
+
const info = deviceKind(kind);
|
|
872
|
+
const now = Date.now();
|
|
873
|
+
const retry = () => {
|
|
874
|
+
void (session == null ? void 0 : session.start());
|
|
875
|
+
};
|
|
876
|
+
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
877
|
+
state.step === "starting" ? /* @__PURE__ */ jsx(ActivityIndicator, { style: styles.loading, color: colors.primary }) : null,
|
|
878
|
+
state.step === "unavailable" ? /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "information-circle", text: state.reason }) : null,
|
|
879
|
+
state.step === "radio" ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
880
|
+
/* @__PURE__ */ jsx(BluetoothPulse, { colors, active: false }),
|
|
881
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
882
|
+
color: colors.text
|
|
883
|
+
}], children: radioCopy(state.radio).title }),
|
|
884
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.statusBody, {
|
|
885
|
+
color: colors.textMuted
|
|
886
|
+
}], children: radioCopy(state.radio).body }),
|
|
887
|
+
state.radio === "unauthorized" ? /* @__PURE__ */ jsx(PrimaryButton, { label: "Open Settings", onPress: () => {
|
|
888
|
+
void Linking.openSettings();
|
|
889
|
+
} }) : null,
|
|
890
|
+
state.radio === "off" ? /* @__PURE__ */ jsx(PrimaryButton, { label: "Try again", onPress: retry }) : null
|
|
891
|
+
] }) : null,
|
|
892
|
+
state.step === "scanning" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
893
|
+
/* @__PURE__ */ jsx(BluetoothPulse, { colors, active: true }),
|
|
894
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
895
|
+
color: colors.text
|
|
896
|
+
}], children: deviceId ? "Looking for your device" : "Looking for devices nearby" }),
|
|
897
|
+
/* @__PURE__ */ jsx(View, { style: [styles.card, styles.guidance, {
|
|
898
|
+
backgroundColor: colors.surface
|
|
899
|
+
}], children: info.steps.map((line, i) => /* @__PURE__ */ jsxs(View, { style: styles.guidanceRow, children: [
|
|
900
|
+
/* @__PURE__ */ jsx(View, { style: [styles.stepDot, {
|
|
901
|
+
backgroundColor: colors.primarySoft
|
|
902
|
+
}], children: /* @__PURE__ */ jsx(Text, { style: [styles.stepNumber, {
|
|
903
|
+
color: colors.primary
|
|
904
|
+
}], children: i + 1 }) }),
|
|
905
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.guidanceText, {
|
|
906
|
+
color: colors.text
|
|
907
|
+
}], children: line })
|
|
908
|
+
] }, line)) }),
|
|
909
|
+
state.hint ? /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "information-circle", text: `Nothing yet. ${state.hint} Keep it close to the phone.` }) : null,
|
|
910
|
+
state.found.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
911
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.sectionTitle, {
|
|
912
|
+
color: colors.textMuted
|
|
913
|
+
}], children: "NEARBY" }),
|
|
914
|
+
/* @__PURE__ */ jsx(View, { style: [styles.card, {
|
|
915
|
+
backgroundColor: colors.surface
|
|
916
|
+
}], children: state.found.map((f, i) => /* @__PURE__ */ jsx(FoundRow, { found: f, first: i === 0, colors, onPress: () => {
|
|
917
|
+
void (session == null ? void 0 : session.pick(f));
|
|
918
|
+
} }, f.id)) })
|
|
919
|
+
] }) : null
|
|
920
|
+
] }) : null,
|
|
921
|
+
state.step === "connecting" ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
922
|
+
/* @__PURE__ */ jsx(ActivityIndicator, { color: colors.primary, size: "large" }),
|
|
923
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.statusTitle, {
|
|
924
|
+
color: colors.text
|
|
925
|
+
}], children: [
|
|
926
|
+
"Connecting to ",
|
|
927
|
+
state.device.name
|
|
928
|
+
] }),
|
|
929
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.statusBody, {
|
|
930
|
+
color: colors.textMuted
|
|
931
|
+
}], children: "If your phone asks to pair, tap Pair." })
|
|
932
|
+
] }) : null,
|
|
933
|
+
state.step === "connected" && !readings.length && !live ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
934
|
+
/* @__PURE__ */ jsx(BluetoothPulse, { colors, active: true, connected: true }),
|
|
935
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
936
|
+
color: colors.text
|
|
937
|
+
}], children: info.waitingFor }),
|
|
938
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.statusBody, {
|
|
939
|
+
color: colors.textMuted
|
|
940
|
+
}], children: [
|
|
941
|
+
"Connected to ",
|
|
942
|
+
state.device.name,
|
|
943
|
+
"."
|
|
944
|
+
] })
|
|
945
|
+
] }) : null,
|
|
946
|
+
(state.step === "connected" || state.step === "ended") && live ? /* @__PURE__ */ jsx(LivePanel, { kind, colors, live, recording, connected: state.step === "connected", onStart: (type) => session == null ? void 0 : session.startRecording(type), onStop: () => {
|
|
947
|
+
void (session == null ? void 0 : session.stopRecording());
|
|
948
|
+
}, onSave: () => {
|
|
949
|
+
void (session == null ? void 0 : session.saveLive());
|
|
950
|
+
} }) : null,
|
|
951
|
+
notices.map((n) => /* @__PURE__ */ jsx(Notice, { colors, tone: "warning", icon: "information-circle", text: n }, n)),
|
|
952
|
+
readings.length ? /* @__PURE__ */ jsx(ReadingsCard, { title: "JUST MEASURED", readings, colors, units, now }) : null,
|
|
953
|
+
readings.length ? /* @__PURE__ */ jsx(SavedLine, { colors, onHealth }) : null,
|
|
954
|
+
state.step === "ended" ? /* @__PURE__ */ jsxs(View, { style: styles.actions, children: [
|
|
955
|
+
!readings.length ? /* @__PURE__ */ jsx(Text, { style: [styles.actionHint, {
|
|
956
|
+
color: colors.textMuted
|
|
957
|
+
}], children: "The device went to sleep before it sent a measurement." }) : null,
|
|
958
|
+
/* @__PURE__ */ jsx(PrimaryButton, { label: "Done", onPress: onDone }),
|
|
959
|
+
/* @__PURE__ */ jsx(SecondaryButton, { label: "Measure again", colors, onPress: () => session == null ? void 0 : session.scan() })
|
|
960
|
+
] }) : null,
|
|
961
|
+
state.step === "connected" && readings.length ? /* @__PURE__ */ jsx(View, { style: styles.actions, children: /* @__PURE__ */ jsx(PrimaryButton, { label: "Done", onPress: onDone }) }) : null,
|
|
962
|
+
state.step === "error" ? /* @__PURE__ */ jsxs(View, { style: styles.center, children: [
|
|
963
|
+
/* @__PURE__ */ jsx(Ionicons, { name: "alert-circle", size: 40, color: colors.dangerText }),
|
|
964
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.statusTitle, {
|
|
965
|
+
color: colors.text
|
|
966
|
+
}], children: state.message }),
|
|
967
|
+
/* @__PURE__ */ jsx(PrimaryButton, { label: "Try again", onPress: retry })
|
|
968
|
+
] }) : null
|
|
969
|
+
] });
|
|
970
|
+
}
|
|
971
|
+
function DeviceDetail({
|
|
972
|
+
id,
|
|
973
|
+
colors,
|
|
974
|
+
units,
|
|
975
|
+
onMeasure,
|
|
976
|
+
onForgot
|
|
977
|
+
}) {
|
|
978
|
+
const devices = useDevices();
|
|
979
|
+
const device = devices.devices.find((d) => d.id === id);
|
|
980
|
+
const readings = useMemo(() => devices.readings.filter((r) => r.deviceId === id).sort((a, b) => b.at - a.at).slice(0, 20), [devices.readings, id]);
|
|
981
|
+
if (!device) return null;
|
|
982
|
+
const forget = () => Alert.alert(`Forget ${device.name}?`, "Its readings stay in Yantra. To use it again, pair it again.", [{
|
|
983
|
+
text: "Cancel",
|
|
984
|
+
style: "cancel"
|
|
985
|
+
}, {
|
|
986
|
+
text: "Forget",
|
|
987
|
+
style: "destructive",
|
|
988
|
+
onPress: () => {
|
|
989
|
+
void deviceStore.forget(id).then(onForgot);
|
|
990
|
+
}
|
|
991
|
+
}]);
|
|
992
|
+
return /* @__PURE__ */ jsxs(ScrollView, { contentContainerStyle: styles.scroll, children: [
|
|
993
|
+
/* @__PURE__ */ jsxs(View, { style: styles.hero, children: [
|
|
994
|
+
/* @__PURE__ */ jsx(KindIcon, { kind: device.kind, colors, large: true }),
|
|
995
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.heroTitle, {
|
|
996
|
+
color: colors.text
|
|
997
|
+
}], children: device.name }),
|
|
998
|
+
/* @__PURE__ */ jsxs(Text, { style: [styles.heroBody, {
|
|
999
|
+
color: colors.textMuted
|
|
1000
|
+
}], children: [
|
|
1001
|
+
deviceKind(device.kind).title,
|
|
1002
|
+
device.scaleUser ? ` \xB7 user ${device.scaleUser.userIndex} on this scale` : ""
|
|
1003
|
+
] })
|
|
1004
|
+
] }),
|
|
1005
|
+
/* @__PURE__ */ jsx(View, { style: styles.actions, children: /* @__PURE__ */ jsx(PrimaryButton, { label: device.kind === "heart-rate" ? "Start a session" : "Take a reading", onPress: () => onMeasure(device.kind) }) }),
|
|
1006
|
+
readings.length ? /* @__PURE__ */ jsx(ReadingsCard, { title: "READINGS", readings, colors, units, now: Date.now() }) : /* @__PURE__ */ jsx(Text, { style: [styles.footnote, {
|
|
1007
|
+
color: colors.textMuted
|
|
1008
|
+
}], children: "No readings from this device yet." }),
|
|
1009
|
+
/* @__PURE__ */ jsx(View, { style: [styles.card, styles.secondaryCard, {
|
|
1010
|
+
backgroundColor: colors.surface
|
|
1011
|
+
}], children: /* @__PURE__ */ jsx(Pressable, { onPress: forget, accessibilityRole: "button", style: ({
|
|
1012
|
+
pressed
|
|
1013
|
+
}) => [styles.row, pressed && {
|
|
1014
|
+
backgroundColor: colors.surfaceMuted
|
|
1015
|
+
}], children: /* @__PURE__ */ jsx(Text, { style: [styles.rowLabelWide, {
|
|
1016
|
+
color: colors.dangerText
|
|
1017
|
+
}], children: "Forget this device" }) }) })
|
|
1018
|
+
] });
|
|
1019
|
+
}
|
|
1020
|
+
function DevicesScreen() {
|
|
1021
|
+
var _a, _b, _c, _d;
|
|
1022
|
+
const navigation = useNavigation();
|
|
1023
|
+
const route = useRoute();
|
|
1024
|
+
const {
|
|
1025
|
+
isDark
|
|
1026
|
+
} = useAppTheme();
|
|
1027
|
+
const colors = mobileColors(isDark);
|
|
1028
|
+
const insets = useSafeAreaInsets();
|
|
1029
|
+
const devices = useDevices();
|
|
1030
|
+
const [stack, setStack] = useState(() => {
|
|
1031
|
+
var _a2;
|
|
1032
|
+
return ((_a2 = route == null ? void 0 : route.params) == null ? void 0 : _a2.add) ? [{
|
|
1033
|
+
name: "home"
|
|
1034
|
+
}, {
|
|
1035
|
+
name: "pick"
|
|
1036
|
+
}] : [{
|
|
1037
|
+
name: "home"
|
|
1038
|
+
}];
|
|
1039
|
+
});
|
|
1040
|
+
const step = stack[stack.length - 1];
|
|
1041
|
+
const units = (_b = (_a = devices.person) == null ? void 0 : _a.units) != null ? _b : "metric";
|
|
1042
|
+
const orgName = useMemo(() => {
|
|
1043
|
+
var _a2, _b2;
|
|
1044
|
+
const raw = (_b2 = (_a2 = route == null ? void 0 : route.params) == null ? void 0 : _a2.orgName) != null ? _b2 : "";
|
|
1045
|
+
return typeof raw === "string" && raw.trim() ? raw.trim() : null;
|
|
1046
|
+
}, [(_c = route == null ? void 0 : route.params) == null ? void 0 : _c.orgName]);
|
|
1047
|
+
const push = useCallback((next) => setStack((s) => [...s, next]), []);
|
|
1048
|
+
const pop = useCallback(() => {
|
|
1049
|
+
var _a2, _b2;
|
|
1050
|
+
if (stack.length > 1) {
|
|
1051
|
+
setStack((s) => s.slice(0, -1));
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|
|
1054
|
+
if ((_a2 = navigation == null ? void 0 : navigation.canGoBack) == null ? void 0 : _a2.call(navigation)) {
|
|
1055
|
+
navigation.goBack();
|
|
1056
|
+
return true;
|
|
1057
|
+
}
|
|
1058
|
+
(_b2 = navigation == null ? void 0 : navigation.dispatch) == null ? void 0 : _b2.call(navigation, CommonActions.navigate({
|
|
1059
|
+
name: "MainStack.Account",
|
|
1060
|
+
params: orgName ? {
|
|
1061
|
+
orgName
|
|
1062
|
+
} : void 0
|
|
1063
|
+
}));
|
|
1064
|
+
return true;
|
|
1065
|
+
}, [stack.length, navigation, orgName]);
|
|
1066
|
+
useEffect(() => {
|
|
1067
|
+
const sub = BackHandler.addEventListener("hardwareBackPress", pop);
|
|
1068
|
+
return () => sub.remove();
|
|
1069
|
+
}, [pop]);
|
|
1070
|
+
const openHealth = useCallback(() => {
|
|
1071
|
+
var _a2;
|
|
1072
|
+
(_a2 = navigation == null ? void 0 : navigation.navigate) == null ? void 0 : _a2.call(navigation, "MainStack.Health", orgName ? {
|
|
1073
|
+
orgName
|
|
1074
|
+
} : void 0);
|
|
1075
|
+
}, [navigation, orgName]);
|
|
1076
|
+
const title = stepTitle(step, devices.devices);
|
|
1077
|
+
return /* @__PURE__ */ jsxs(SafeAreaView, { edges: ["top", "left", "right"], style: [styles.safe, {
|
|
1078
|
+
backgroundColor: colors.bg
|
|
1079
|
+
}], children: [
|
|
1080
|
+
/* @__PURE__ */ jsxs(View, { style: [styles.header, {
|
|
1081
|
+
paddingTop: insets.top > 0 ? 4 : 10
|
|
1082
|
+
}], children: [
|
|
1083
|
+
/* @__PURE__ */ jsx(Pressable, { onPress: pop, accessibilityRole: "button", accessibilityLabel: "Go back", style: ({
|
|
1084
|
+
pressed
|
|
1085
|
+
}) => [styles.backCircle, {
|
|
1086
|
+
backgroundColor: colors.surface
|
|
1087
|
+
}, pressed && styles.pressed], children: /* @__PURE__ */ jsx(Ionicons, { name: "chevron-back", size: 22, color: colors.text }) }),
|
|
1088
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.headerTitle, {
|
|
1089
|
+
color: colors.text
|
|
1090
|
+
}], numberOfLines: 1, children: title }),
|
|
1091
|
+
/* @__PURE__ */ jsx(View, { style: styles.headerSpacer })
|
|
1092
|
+
] }),
|
|
1093
|
+
step.name === "home" ? /* @__PURE__ */ jsx(Home, { colors, isDark, units, onAdd: () => push({
|
|
1094
|
+
name: "pick"
|
|
1095
|
+
}), onOpen: (id) => push({
|
|
1096
|
+
name: "device",
|
|
1097
|
+
id
|
|
1098
|
+
}), onHealth: openHealth }) : null,
|
|
1099
|
+
step.name === "pick" ? /* @__PURE__ */ jsx(PickKind, { colors, isDark, onPick: (kind) => push({
|
|
1100
|
+
name: "measure",
|
|
1101
|
+
kind
|
|
1102
|
+
}) }) : null,
|
|
1103
|
+
step.name === "measure" ? /* @__PURE__ */ jsx(Measure, { kind: step.kind, deviceId: step.deviceId, colors, units, onDone: () => setStack([{
|
|
1104
|
+
name: "home"
|
|
1105
|
+
}]), onHealth: openHealth }, `${step.kind}:${(_d = step.deviceId) != null ? _d : ""}`) : null,
|
|
1106
|
+
step.name === "device" ? /* @__PURE__ */ jsx(DeviceDetail, { id: step.id, colors, units, onMeasure: (kind) => push({
|
|
1107
|
+
name: "measure",
|
|
1108
|
+
kind,
|
|
1109
|
+
deviceId: step.id
|
|
1110
|
+
}), onForgot: () => setStack([{
|
|
1111
|
+
name: "home"
|
|
1112
|
+
}]) }) : null
|
|
1113
|
+
] });
|
|
1114
|
+
}export{DevicesScreen as default};//# sourceMappingURL=index.js.map
|