fix(dae): on alert modal
This commit is contained in:
parent
93ba79bfa7
commit
cf00b5cea4
4 changed files with 54 additions and 28 deletions
|
|
@ -15,16 +15,18 @@ export default function DaeSuggestModal() {
|
|||
|
||||
const styles = useMemo(
|
||||
() => ({
|
||||
container: { backgroundColor: colors.surface, padding: 20 },
|
||||
container: {
|
||||
backgroundColor: colors.surface,
|
||||
padding: 20,
|
||||
marginHorizontal: 16,
|
||||
borderRadius: 12,
|
||||
},
|
||||
title: { fontSize: 20, fontWeight: "bold" },
|
||||
paragraph: { marginTop: 10, fontSize: 16 },
|
||||
actionsRow: {
|
||||
actionsColumn: {
|
||||
marginTop: 18,
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
gap: 10,
|
||||
},
|
||||
action: { flex: 1 },
|
||||
actionLeft: { marginRight: 12 },
|
||||
}),
|
||||
[colors.surface],
|
||||
);
|
||||
|
|
@ -52,18 +54,14 @@ export default function DaeSuggestModal() {
|
|||
>
|
||||
<Text style={styles.title}>Défibrillateur à proximité</Text>
|
||||
<Text style={styles.paragraph}>
|
||||
Votre alerte semble concerner un malaise grave / arrêt cardiaque.
|
||||
Recherchez rapidement un défibrillateur (DAE) près de vous.
|
||||
En cas d'arrêt cardiaque, un défibrillateur (DAE) à proximité peut
|
||||
sauver une vie.
|
||||
</Text>
|
||||
<View style={styles.actionsRow}>
|
||||
<Button
|
||||
style={[styles.action, styles.actionLeft]}
|
||||
mode="contained"
|
||||
onPress={goToDaeList}
|
||||
>
|
||||
<View style={styles.actionsColumn}>
|
||||
<Button mode="contained" onPress={goToDaeList}>
|
||||
Chercher un défibrillateur
|
||||
</Button>
|
||||
<Button style={styles.action} mode="outlined" onPress={dismiss}>
|
||||
<Button mode="outlined" onPress={dismiss}>
|
||||
Non merci
|
||||
</Button>
|
||||
</View>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { getCurrentLocation } from "~/location";
|
|||
|
||||
import useSendAlertSMSToEmergency from "~/hooks/useSendAlertSMSToEmergency";
|
||||
|
||||
import alertsList from "~/misc/alertsList";
|
||||
import subjectSuggestsDefib from "~/utils/dae/subjectSuggestsDefib";
|
||||
|
||||
import { SEND_ALERT_MUTATION } from "./gql";
|
||||
|
|
@ -84,6 +85,13 @@ async function onSubmit(args, context) {
|
|||
speed,
|
||||
};
|
||||
|
||||
// DAE suggest modal — must run before network call so it works offline.
|
||||
// Show on red alerts unconditionally, or when cardiac keywords are detected.
|
||||
const matchingAlert = alertsList.find((a) => a.title === subject);
|
||||
if (level === "red" || subjectSuggestsDefib(subject, matchingAlert?.desc)) {
|
||||
defibsActions.setShowDaeSuggestModal(true);
|
||||
}
|
||||
|
||||
const { userId, deviceId } = getSessionState();
|
||||
const createdAt = new Date().toISOString();
|
||||
|
||||
|
|
@ -133,12 +141,6 @@ async function onSubmit(args, context) {
|
|||
|
||||
alertActions.setNavAlertCur({ alert });
|
||||
|
||||
// Task 9 (DAE v1): keyword detection based on subject only.
|
||||
// Must be independent of network; we trigger purely from the subject and persist state in store.
|
||||
if (subjectSuggestsDefib(subject)) {
|
||||
defibsActions.setShowDaeSuggestModal(true);
|
||||
}
|
||||
|
||||
navigation.navigate("Main", {
|
||||
screen: "AlertCur",
|
||||
params: {
|
||||
|
|
|
|||
|
|
@ -59,13 +59,14 @@ const DEFIB_SUGGESTION_REGEXES = [
|
|||
/\brespire\s+plus\b/,
|
||||
];
|
||||
|
||||
export function subjectSuggestsDefib(subject) {
|
||||
const text = normalizeSubjectText(subject);
|
||||
if (!text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DEFIB_SUGGESTION_REGEXES.some((re) => re.test(text));
|
||||
export function subjectSuggestsDefib(...texts) {
|
||||
return texts.some((input) => {
|
||||
const text = normalizeSubjectText(input);
|
||||
if (!text) {
|
||||
return false;
|
||||
}
|
||||
return DEFIB_SUGGESTION_REGEXES.some((re) => re.test(text));
|
||||
});
|
||||
}
|
||||
|
||||
export const __private__ = {
|
||||
|
|
|
|||
|
|
@ -37,4 +37,29 @@ describe("dae/subjectSuggestsDefib", () => {
|
|||
expect(subjectSuggestsDefib("mal au dos")).toBe(false);
|
||||
expect(subjectSuggestsDefib("panne de voiture")).toBe(false);
|
||||
});
|
||||
|
||||
test("matches when keyword is in second argument (description)", () => {
|
||||
expect(
|
||||
subjectSuggestsDefib(
|
||||
"urgence médicale mortelle",
|
||||
"crise cardiaque, attaque cérébrale, hémorragie importante, blessure grave",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("matches when keyword is only in subject, not description", () => {
|
||||
expect(subjectSuggestsDefib("arrêt cardiaque", "some other desc")).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("does not match when neither subject nor description has keywords", () => {
|
||||
expect(subjectSuggestsDefib("agression", "violence physique")).toBe(false);
|
||||
});
|
||||
|
||||
test("handles null/undefined in multi-arg", () => {
|
||||
expect(subjectSuggestsDefib(null, "cardiaque")).toBe(true);
|
||||
expect(subjectSuggestsDefib("cardiaque", undefined)).toBe(true);
|
||||
expect(subjectSuggestsDefib(null, undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue