@wasto/cms-components 1.5.10 → 1.5.12

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.
Files changed (101) hide show
  1. package/README.md +47 -47
  2. package/dist/index.d.mts +181 -51
  3. package/dist/index.d.ts +181 -51
  4. package/dist/index.js +3614 -3015
  5. package/dist/index.mjs +3021 -2418
  6. package/package.json +12 -2
  7. package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
  8. package/src/components/article/Article.tsx +21 -21
  9. package/src/components/article/ArticleCard.tsx +81 -81
  10. package/src/components/article/ArticleExcerpts.tsx +80 -80
  11. package/src/components/article/ArticleList.tsx +114 -114
  12. package/src/components/article/ArticleMarkdown.tsx +170 -170
  13. package/src/components/article/ArticleReaderModal.tsx +93 -93
  14. package/src/components/article/ArticleSingle.tsx +57 -57
  15. package/src/components/bottom-tab/BottomTab.tsx +392 -392
  16. package/src/components/button/Button.tsx +154 -154
  17. package/src/components/challenge/Badges.tsx +84 -84
  18. package/src/components/challenge/BadgesModal.tsx +166 -166
  19. package/src/components/challenge/Challenge.tsx +380 -380
  20. package/src/components/challenge/ChallengeModal.tsx +231 -231
  21. package/src/components/challenge/ChallengeVignette.tsx +249 -249
  22. package/src/components/challenge/ChallengesModal.tsx +243 -243
  23. package/src/components/challenge/QuizModal.tsx +381 -381
  24. package/src/components/challenge/ResultModal.tsx +144 -144
  25. package/src/components/chat/Chat.tsx +928 -928
  26. package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
  27. package/src/components/columns/Columns.tsx +33 -33
  28. package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
  29. package/src/components/content-inset/ContentInset.tsx +33 -33
  30. package/src/components/header/Header.tsx +415 -391
  31. package/src/components/image/Image.tsx +15 -15
  32. package/src/components/image/ImageFrame.tsx +102 -102
  33. package/src/components/image/ImageMedia.tsx +31 -31
  34. package/src/components/image/ImageUrl.tsx +30 -30
  35. package/src/components/locations-map/LocationSheet.tsx +417 -417
  36. package/src/components/locations-map/LocationsMap.native.tsx +260 -260
  37. package/src/components/locations-map/LocationsMap.tsx +13 -13
  38. package/src/components/locations-map/LocationsMap.web.tsx +10 -10
  39. package/src/components/locations-map/LocationsMapShell.tsx +546 -527
  40. package/src/components/locations-map/LocationsMapView.tsx +108 -108
  41. package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
  42. package/src/components/nav-button/NavButton.tsx +59 -59
  43. package/src/components/next-collection/NextCollection.tsx +636 -621
  44. package/src/components/notifications/NotificationsScreen.tsx +247 -247
  45. package/src/components/page/Page.tsx +102 -64
  46. package/src/components/parapraph/Paragraph.tsx +67 -67
  47. package/src/components/profile/ProfileScreen.tsx +236 -236
  48. package/src/components/push/PushTokenRegistrar.tsx +47 -0
  49. package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
  50. package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
  51. package/src/components/search/Search.tsx +320 -320
  52. package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
  53. package/src/components/title/Title.tsx +100 -100
  54. package/src/components/vision/Vision.tsx +447 -447
  55. package/src/components/vision/VisionActionCard.tsx +117 -117
  56. package/src/components/vision/VisionCapture.tsx +30 -30
  57. package/src/components/vision/VisionTapOverlay.tsx +122 -122
  58. package/src/contexts/AnnouncementsContext.tsx +171 -171
  59. package/src/contexts/AppDataContext.tsx +458 -0
  60. package/src/contexts/ChallengesContext.tsx +182 -182
  61. package/src/contexts/HeaderConfigContext.tsx +29 -0
  62. package/src/contexts/LocalContext.tsx +227 -227
  63. package/src/contexts/ThemeContext.tsx +37 -37
  64. package/src/contexts/WastoContext.tsx +132 -127
  65. package/src/helpers/blogPost.ts +72 -72
  66. package/src/helpers/generateQuizQuestions.ts +247 -247
  67. package/src/helpers/getContrastColor.ts +18 -18
  68. package/src/helpers/haptics.ts +20 -20
  69. package/src/helpers/hoursSchedule.ts +230 -230
  70. package/src/helpers/htmlContentToMarkdown.ts +114 -114
  71. package/src/helpers/layout.ts +54 -54
  72. package/src/helpers/loadLinearGradient.ts +22 -22
  73. package/src/helpers/mapLocations.ts +170 -0
  74. package/src/helpers/maquetteTheme.ts +76 -76
  75. package/src/helpers/markdownUnderlinePlugin.ts +32 -32
  76. package/src/helpers/nextCollection.ts +122 -0
  77. package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
  78. package/src/helpers/publicMediaUrl.ts +8 -8
  79. package/src/helpers/resolveApiAssetUrl.ts +21 -21
  80. package/src/helpers/systemRoutes.ts +7 -7
  81. package/src/helpers/themeStyles.ts +114 -114
  82. package/src/helpers/ttlCache.ts +41 -0
  83. package/src/helpers/useSafeAreaPadding.ts +14 -14
  84. package/src/hooks/useBadges.ts +100 -100
  85. package/src/hooks/useBlogPosts.ts +109 -105
  86. package/src/hooks/useChallenges.ts +110 -110
  87. package/src/hooks/useCities.ts +56 -56
  88. package/src/hooks/useCityAnnouncements.ts +118 -118
  89. package/src/hooks/useCollectionCalendar.ts +421 -421
  90. package/src/hooks/useColumns.ts +19 -19
  91. package/src/hooks/useConsignes.ts +62 -62
  92. package/src/hooks/useLocations.ts +120 -248
  93. package/src/hooks/useNextCollection.ts +163 -238
  94. package/src/hooks/useRecyclingInfo.ts +90 -90
  95. package/src/hooks/useWastoClient.ts +16 -16
  96. package/src/index.ts +161 -142
  97. package/src/navigation/NavigationContext.tsx +56 -56
  98. package/src/push/registerExpoPushToken.ts +133 -0
  99. package/src/sentry/initSentry.ts +120 -120
  100. package/src/types/Theme.ts +72 -72
  101. package/src/types/css-modules.d.ts +1 -1
@@ -1,475 +1,475 @@
1
- import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
2
- import {
3
- ActivityIndicator,
4
- FlatList,
5
- KeyboardAvoidingView,
6
- Modal,
7
- Platform,
8
- Pressable,
9
- StyleSheet,
10
- Text,
11
- TextInput,
12
- View,
13
- } from "react-native";
14
- import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
15
- import { Check, MapPin, Search, X } from "lucide-react-native";
16
- import type { CalendarPdfSector, StreetSectorMatch } from "@wasto/sdk";
17
- import { useLocal } from "../../contexts/LocalContext";
18
- import { useTheme } from "../../contexts/ThemeContext";
19
- import { useWasto } from "../../contexts/WastoContext";
20
- import { useWastoClient } from "../../hooks/useWastoClient";
21
- import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
22
- import { resolveTheme } from "../../helpers/themeStyles";
23
- import { hapticLight, hapticSelection } from "../../helpers/haptics";
24
- import { Button } from "../button/Button";
25
-
26
- type Step = "search" | "pickSector" | "confirm";
27
-
28
- type PendingSelection = {
29
- street: StreetSectorMatch;
30
- sector: CalendarPdfSector;
31
- };
32
-
33
- export default function SelectStreetModal(): ReactNode {
34
- const { hasPlaceSelected, registerDevice, isLoading } = useLocal();
35
- const { cityGroupId } = useWasto();
36
- const { theme } = useTheme();
37
- const t = resolveTheme(theme);
38
- const client = useWastoClient();
39
- const insets = useSafeAreaPadding(["top", "bottom"]);
40
- const inputRef = useRef<TextInput>(null);
41
-
42
- const [query, setQuery] = useState("");
43
- const [results, setResults] = useState<StreetSectorMatch[]>([]);
44
- const [searching, setSearching] = useState(false);
45
- const [selectedStreet, setSelectedStreet] = useState<StreetSectorMatch | null>(null);
46
- const [pending, setPending] = useState<PendingSelection | null>(null);
47
- const [step, setStep] = useState<Step>("search");
48
- const [error, setError] = useState<string | null>(null);
49
-
50
- useEffect(() => {
51
- if (hasPlaceSelected) return;
52
- const timer = setTimeout(() => inputRef.current?.focus(), 350);
53
- return () => clearTimeout(timer);
54
- }, [hasPlaceSelected, step]);
55
-
56
- useEffect(() => {
57
- if (hasPlaceSelected) return;
58
- const trimmed = query.trim();
59
- if (trimmed.length < 2 || !cityGroupId) {
60
- setResults([]);
61
- setSearching(false);
62
- return;
63
- }
64
-
65
- setSearching(true);
66
- const handle = setTimeout(async () => {
67
- try {
68
- setError(null);
69
- const res = await client.public.cityGroups.searchStreetSectors(cityGroupId, {
70
- q: trimmed,
71
- });
72
- setResults(res.data ?? []);
73
- } catch (err) {
74
- setError(
75
- err instanceof Error ? err.message : "Impossible de rechercher cette rue",
76
- );
77
- setResults([]);
78
- } finally {
79
- setSearching(false);
80
- }
81
- }, 300);
82
-
83
- return () => clearTimeout(handle);
84
- }, [cityGroupId, client.public.cityGroups, hasPlaceSelected, query]);
85
-
86
- const resetToSearch = useCallback(() => {
87
- setStep("search");
88
- setSelectedStreet(null);
89
- setPending(null);
90
- setTimeout(() => inputRef.current?.focus(), 100);
91
- }, []);
92
-
93
- const onSelectStreet = async (street: StreetSectorMatch) => {
94
- await hapticSelection();
95
- setSelectedStreet(street);
96
- setError(null);
97
- if ((street.sectors ?? []).length === 0) {
98
- setError("Aucun secteur de collecte trouvé pour cette rue.");
99
- }
100
- };
101
-
102
- const onContinueFromList = async () => {
103
- if (!selectedStreet) return;
104
- const withSectors = (selectedStreet.sectors ?? []).filter(Boolean);
105
- if (withSectors.length === 0) {
106
- setError("Aucun secteur de collecte trouvé pour cette rue.");
107
- return;
108
- }
109
- await hapticLight();
110
- if (withSectors.length === 1) {
111
- setPending({ street: selectedStreet, sector: withSectors[0]! });
112
- setStep("confirm");
113
- return;
114
- }
115
- setStep("pickSector");
116
- };
117
-
118
- const onSelectSector = async (sector: CalendarPdfSector) => {
119
- if (!selectedStreet) return;
120
- await hapticSelection();
121
- setPending({ street: selectedStreet, sector });
122
- setStep("confirm");
123
- };
124
-
125
- const onConfirm = async () => {
126
- if (!pending) return;
127
- await hapticLight();
128
- await registerDevice(
129
- pending.sector.cityId || pending.street.cityId,
130
- pending.sector.id,
131
- {
132
- cityName: pending.sector.cityName || pending.street.cityName,
133
- streetName: pending.street.streetName,
134
- sectorName: pending.sector.name,
135
- },
136
- );
137
- };
138
-
139
- const showEmptyHint = query.trim().length < 2 && step === "search";
140
- const showResults = step === "search" && query.trim().length >= 2;
141
-
142
- return (
143
- <Modal visible={!hasPlaceSelected} animationType="fade">
144
- <KeyboardAvoidingView
145
- style={[styles.root, { backgroundColor: theme.colors.background }, insets]}
146
- behavior={Platform.OS === "ios" ? "padding" : undefined}
147
- >
148
- {step === "confirm" && pending ? (
149
- <Animated.View entering={FadeIn.duration(220)} exiting={FadeOut.duration(160)} style={styles.confirmWrap}>
150
- <View style={styles.confirmCenter}>
151
- <Text style={[styles.confirmLabel, { color: theme.colors.onBackground }]}>
152
- Votre zone est :
153
- </Text>
154
- <Text style={[styles.confirmZone, { color: theme.colors.onBackground }]}>
155
- “{pending.sector.name}” à {pending.sector.cityName || pending.street.cityName}
156
- </Text>
157
- </View>
158
- <View style={styles.confirmActions}>
159
- <Button
160
- onPress={onConfirm}
161
- loading={isLoading}
162
- style={[styles.confirmPrimaryBtn, { borderRadius: t.radii.lg }]}
163
- >
164
- Continuer
165
- </Button>
166
- <Pressable onPress={resetToSearch} hitSlop={8}>
167
- <Text style={[styles.link, { color: theme.colors.primary }]}>
168
- Choisir une autre rue
169
- </Text>
170
- </Pressable>
171
- </View>
172
- </Animated.View>
173
- ) : (
174
- <Animated.View entering={FadeIn.duration(220)} style={styles.searchWrap}>
175
- <View
176
- style={[
177
- styles.searchBar,
178
- {
179
- backgroundColor: theme.colors.surface,
180
- borderColor: theme.colors.border,
181
- borderRadius: t.radii.lg,
182
- },
183
- ]}
184
- >
185
- <Search size={18} color={t.colors.muted} />
186
- <TextInput
187
- ref={inputRef}
188
- value={query}
189
- onChangeText={setQuery}
190
- placeholder="Rue de Paris, Saint Denis"
191
- placeholderTextColor={t.colors.muted}
192
- style={[styles.input, { color: theme.colors.onSurface }]}
193
- autoFocus
194
- returnKeyType="search"
195
- autoCorrect={false}
196
- autoCapitalize="words"
197
- />
198
- {query.length > 0 ? (
199
- <Pressable
200
- onPress={() => {
201
- setQuery("");
202
- setSelectedStreet(null);
203
- inputRef.current?.focus();
204
- }}
205
- hitSlop={8}
206
- >
207
- <X size={16} color={t.colors.muted} />
208
- </Pressable>
209
- ) : null}
210
- </View>
211
-
212
- {!cityGroupId ? (
213
- <Text style={[styles.error, { color: theme.colors.error }]}>
214
- Configuration manquante : cityGroupId requis pour la recherche de rues.
215
- </Text>
216
- ) : null}
217
-
218
- {showEmptyHint ? (
219
- <View style={styles.hint}>
220
- <Text style={[styles.hintTitle, { color: theme.colors.onBackground }]}>
221
- Où habitez-vous ?
222
- </Text>
223
- <Text style={[styles.hintSub, { color: t.colors.muted }]}>
224
- Recherchez le nom de votre rue afin de définir votre secteur de collecte
225
- </Text>
226
- </View>
227
- ) : null}
228
-
229
- {step === "pickSector" && selectedStreet ? (
230
- <FlatList
231
- data={selectedStreet.sectors}
232
- keyExtractor={(item) => item.id}
233
- contentContainerStyle={styles.listContent}
234
- keyboardShouldPersistTaps="handled"
235
- ListHeaderComponent={
236
- <Text style={[styles.sectionTitle, { color: t.colors.muted }]}>
237
- Choisissez votre secteur
238
- </Text>
239
- }
240
- renderItem={({ item }) => (
241
- <Pressable
242
- onPress={() => onSelectSector(item)}
243
- style={[
244
- styles.row,
245
- { borderBottomColor: theme.colors.border },
246
- ]}
247
- >
248
- <View style={[styles.pin, { backgroundColor: theme.colors.border }]}>
249
- <MapPin size={16} color={t.colors.muted} />
250
- </View>
251
- <View style={styles.rowText}>
252
- <Text style={[styles.rowTitle, { color: theme.colors.onSurface }]}>
253
- {item.name}
254
- </Text>
255
- <Text style={[styles.rowSub, { color: t.colors.muted }]}>
256
- {item.cityName}
257
- </Text>
258
- </View>
259
- </Pressable>
260
- )}
261
- />
262
- ) : null}
263
-
264
- {showResults ? (
265
- <>
266
- {searching ? (
267
- <ActivityIndicator
268
- color={theme.colors.primary}
269
- style={{ marginTop: 16 }}
270
- />
271
- ) : null}
272
- {error ? (
273
- <Text style={[styles.error, { color: theme.colors.error }]}>{error}</Text>
274
- ) : null}
275
- <FlatList
276
- data={results}
277
- keyExtractor={(item) => item.streetId}
278
- keyboardShouldPersistTaps="handled"
279
- contentContainerStyle={styles.listContent}
280
- ListEmptyComponent={
281
- !searching ? (
282
- <Text style={[styles.empty, { color: t.colors.muted }]}>
283
- Aucune rue trouvée
284
- </Text>
285
- ) : null
286
- }
287
- renderItem={({ item }) => {
288
- const selected = selectedStreet?.streetId === item.streetId;
289
- return (
290
- <Pressable
291
- onPress={() => onSelectStreet(item)}
292
- style={[
293
- styles.row,
294
- {
295
- borderBottomColor: theme.colors.border,
296
- backgroundColor: selected
297
- ? theme.colors.border
298
- : "transparent",
299
- },
300
- ]}
301
- >
302
- <View
303
- style={[
304
- styles.pin,
305
- { backgroundColor: theme.colors.border },
306
- ]}
307
- >
308
- <MapPin size={16} color={t.colors.muted} />
309
- </View>
310
- <View style={styles.rowText}>
311
- <Text
312
- style={[
313
- styles.rowTitle,
314
- { color: theme.colors.onSurface },
315
- ]}
316
- >
317
- {item.streetName}
318
- </Text>
319
- <Text style={[styles.rowSub, { color: t.colors.muted }]}>
320
- {item.cityName}
321
- </Text>
322
- </View>
323
- {selected ? (
324
- <Check size={18} color={theme.colors.onSurface} />
325
- ) : null}
326
- </Pressable>
327
- );
328
- }}
329
- />
330
- {selectedStreet ? (
331
- <Button
332
- onPress={onContinueFromList}
333
- style={[styles.primaryBtn, { borderRadius: t.radii.lg }]}
334
- >
335
- Continuer
336
- </Button>
337
- ) : null}
338
- </>
339
- ) : null}
340
- </Animated.View>
341
- )}
342
- </KeyboardAvoidingView>
343
- </Modal>
344
- );
345
- }
346
-
347
- const styles = StyleSheet.create({
348
- root: {
349
- flex: 1,
350
- paddingHorizontal: 16,
351
- paddingTop: 8,
352
- },
353
- searchWrap: {
354
- flex: 1,
355
- gap: 12,
356
- },
357
- searchBar: {
358
- flexDirection: "row",
359
- alignItems: "center",
360
- gap: 10,
361
- paddingHorizontal: 14,
362
- height: 48,
363
- borderWidth: 1,
364
- },
365
- input: {
366
- flex: 1,
367
- fontSize: 16,
368
- paddingVertical: 0,
369
- },
370
- hint: {
371
- flex: 1,
372
- justifyContent: "center",
373
- alignItems: "center",
374
- paddingHorizontal: 24,
375
- gap: 10,
376
- marginBottom: 80,
377
- },
378
- hintTitle: {
379
- fontSize: 22,
380
- fontWeight: "800",
381
- textAlign: "center",
382
- },
383
- hintSub: {
384
- fontSize: 15,
385
- textAlign: "center",
386
- lineHeight: 22,
387
- },
388
- listContent: {
389
- paddingBottom: 16,
390
- },
391
- sectionTitle: {
392
- fontSize: 13,
393
- fontWeight: "600",
394
- textTransform: "uppercase",
395
- marginBottom: 8,
396
- marginTop: 4,
397
- },
398
- row: {
399
- flexDirection: "row",
400
- alignItems: "center",
401
- gap: 12,
402
- paddingVertical: 12,
403
- paddingHorizontal: 8,
404
- borderBottomWidth: StyleSheet.hairlineWidth,
405
- },
406
- pin: {
407
- width: 36,
408
- height: 36,
409
- borderRadius: 18,
410
- alignItems: "center",
411
- justifyContent: "center",
412
- },
413
- rowText: {
414
- flex: 1,
415
- gap: 2,
416
- },
417
- rowTitle: {
418
- fontSize: 16,
419
- fontWeight: "700",
420
- },
421
- rowSub: {
422
- fontSize: 13,
423
- },
424
- empty: {
425
- textAlign: "center",
426
- marginTop: 24,
427
- },
428
- error: {
429
- marginTop: 8,
430
- fontSize: 13,
431
- },
432
- primaryBtn: {
433
- height: 52,
434
- marginBottom: 8,
435
- },
436
- confirmWrap: {
437
- flex: 1,
438
- justifyContent: "space-between",
439
- paddingBottom: 24,
440
- },
441
- confirmCenter: {
442
- flex: 1,
443
- justifyContent: "center",
444
- alignItems: "center",
445
- gap: 8,
446
- paddingHorizontal: 24,
447
- },
448
- confirmLabel: {
449
- fontSize: 20,
450
- fontWeight: "800",
451
- textAlign: "center",
452
- },
453
- confirmZone: {
454
- fontSize: 22,
455
- fontWeight: "800",
456
- textAlign: "center",
457
- },
458
- confirmActions: {
459
- gap: 16,
460
- alignItems: "stretch",
461
- width: "100%",
462
- },
463
- confirmPrimaryBtn: {
464
- height: 52,
465
- width: "100%",
466
- alignSelf: "stretch",
467
- },
468
- link: {
469
- fontSize: 15,
470
- fontWeight: "700",
471
- paddingVertical: 4,
472
- textAlign: "center",
473
- alignSelf: "center",
474
- },
475
- });
1
+ import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
2
+ import {
3
+ ActivityIndicator,
4
+ FlatList,
5
+ KeyboardAvoidingView,
6
+ Modal,
7
+ Platform,
8
+ Pressable,
9
+ StyleSheet,
10
+ Text,
11
+ TextInput,
12
+ View,
13
+ } from "react-native";
14
+ import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
15
+ import { Check, MapPin, Search, X } from "lucide-react-native";
16
+ import type { CalendarPdfSector, StreetSectorMatch } from "@wasto/sdk";
17
+ import { useLocal } from "../../contexts/LocalContext";
18
+ import { useTheme } from "../../contexts/ThemeContext";
19
+ import { useWasto } from "../../contexts/WastoContext";
20
+ import { useWastoClient } from "../../hooks/useWastoClient";
21
+ import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
22
+ import { resolveTheme } from "../../helpers/themeStyles";
23
+ import { hapticLight, hapticSelection } from "../../helpers/haptics";
24
+ import { Button } from "../button/Button";
25
+
26
+ type Step = "search" | "pickSector" | "confirm";
27
+
28
+ type PendingSelection = {
29
+ street: StreetSectorMatch;
30
+ sector: CalendarPdfSector;
31
+ };
32
+
33
+ export default function SelectStreetModal(): ReactNode {
34
+ const { hasPlaceSelected, registerDevice, isLoading } = useLocal();
35
+ const { cityGroupId } = useWasto();
36
+ const { theme } = useTheme();
37
+ const t = resolveTheme(theme);
38
+ const client = useWastoClient();
39
+ const insets = useSafeAreaPadding(["top", "bottom"]);
40
+ const inputRef = useRef<TextInput>(null);
41
+
42
+ const [query, setQuery] = useState("");
43
+ const [results, setResults] = useState<StreetSectorMatch[]>([]);
44
+ const [searching, setSearching] = useState(false);
45
+ const [selectedStreet, setSelectedStreet] = useState<StreetSectorMatch | null>(null);
46
+ const [pending, setPending] = useState<PendingSelection | null>(null);
47
+ const [step, setStep] = useState<Step>("search");
48
+ const [error, setError] = useState<string | null>(null);
49
+
50
+ useEffect(() => {
51
+ if (hasPlaceSelected) return;
52
+ const timer = setTimeout(() => inputRef.current?.focus(), 350);
53
+ return () => clearTimeout(timer);
54
+ }, [hasPlaceSelected, step]);
55
+
56
+ useEffect(() => {
57
+ if (hasPlaceSelected) return;
58
+ const trimmed = query.trim();
59
+ if (trimmed.length < 2 || !cityGroupId) {
60
+ setResults([]);
61
+ setSearching(false);
62
+ return;
63
+ }
64
+
65
+ setSearching(true);
66
+ const handle = setTimeout(async () => {
67
+ try {
68
+ setError(null);
69
+ const res = await client.public.cityGroups.searchStreetSectors(cityGroupId, {
70
+ q: trimmed,
71
+ });
72
+ setResults(res.data ?? []);
73
+ } catch (err) {
74
+ setError(
75
+ err instanceof Error ? err.message : "Impossible de rechercher cette rue",
76
+ );
77
+ setResults([]);
78
+ } finally {
79
+ setSearching(false);
80
+ }
81
+ }, 300);
82
+
83
+ return () => clearTimeout(handle);
84
+ }, [cityGroupId, client.public.cityGroups, hasPlaceSelected, query]);
85
+
86
+ const resetToSearch = useCallback(() => {
87
+ setStep("search");
88
+ setSelectedStreet(null);
89
+ setPending(null);
90
+ setTimeout(() => inputRef.current?.focus(), 100);
91
+ }, []);
92
+
93
+ const onSelectStreet = async (street: StreetSectorMatch) => {
94
+ await hapticSelection();
95
+ setSelectedStreet(street);
96
+ setError(null);
97
+ if ((street.sectors ?? []).length === 0) {
98
+ setError("Aucun secteur de collecte trouvé pour cette rue.");
99
+ }
100
+ };
101
+
102
+ const onContinueFromList = async () => {
103
+ if (!selectedStreet) return;
104
+ const withSectors = (selectedStreet.sectors ?? []).filter(Boolean);
105
+ if (withSectors.length === 0) {
106
+ setError("Aucun secteur de collecte trouvé pour cette rue.");
107
+ return;
108
+ }
109
+ await hapticLight();
110
+ if (withSectors.length === 1) {
111
+ setPending({ street: selectedStreet, sector: withSectors[0]! });
112
+ setStep("confirm");
113
+ return;
114
+ }
115
+ setStep("pickSector");
116
+ };
117
+
118
+ const onSelectSector = async (sector: CalendarPdfSector) => {
119
+ if (!selectedStreet) return;
120
+ await hapticSelection();
121
+ setPending({ street: selectedStreet, sector });
122
+ setStep("confirm");
123
+ };
124
+
125
+ const onConfirm = async () => {
126
+ if (!pending) return;
127
+ await hapticLight();
128
+ await registerDevice(
129
+ pending.sector.cityId || pending.street.cityId,
130
+ pending.sector.id,
131
+ {
132
+ cityName: pending.sector.cityName || pending.street.cityName,
133
+ streetName: pending.street.streetName,
134
+ sectorName: pending.sector.name,
135
+ },
136
+ );
137
+ };
138
+
139
+ const showEmptyHint = query.trim().length < 2 && step === "search";
140
+ const showResults = step === "search" && query.trim().length >= 2;
141
+
142
+ return (
143
+ <Modal visible={!hasPlaceSelected} animationType="fade">
144
+ <KeyboardAvoidingView
145
+ style={[styles.root, { backgroundColor: theme.colors.background }, insets]}
146
+ behavior={Platform.OS === "ios" ? "padding" : undefined}
147
+ >
148
+ {step === "confirm" && pending ? (
149
+ <Animated.View entering={FadeIn.duration(220)} exiting={FadeOut.duration(160)} style={styles.confirmWrap}>
150
+ <View style={styles.confirmCenter}>
151
+ <Text style={[styles.confirmLabel, { color: theme.colors.onBackground }]}>
152
+ Votre zone est :
153
+ </Text>
154
+ <Text style={[styles.confirmZone, { color: theme.colors.onBackground }]}>
155
+ “{pending.sector.name}” à {pending.sector.cityName || pending.street.cityName}
156
+ </Text>
157
+ </View>
158
+ <View style={styles.confirmActions}>
159
+ <Button
160
+ onPress={onConfirm}
161
+ loading={isLoading}
162
+ style={[styles.confirmPrimaryBtn, { borderRadius: t.radii.lg }]}
163
+ >
164
+ Continuer
165
+ </Button>
166
+ <Pressable onPress={resetToSearch} hitSlop={8}>
167
+ <Text style={[styles.link, { color: theme.colors.primary }]}>
168
+ Choisir une autre rue
169
+ </Text>
170
+ </Pressable>
171
+ </View>
172
+ </Animated.View>
173
+ ) : (
174
+ <Animated.View entering={FadeIn.duration(220)} style={styles.searchWrap}>
175
+ <View
176
+ style={[
177
+ styles.searchBar,
178
+ {
179
+ backgroundColor: theme.colors.surface,
180
+ borderColor: theme.colors.border,
181
+ borderRadius: t.radii.lg,
182
+ },
183
+ ]}
184
+ >
185
+ <Search size={18} color={t.colors.muted} />
186
+ <TextInput
187
+ ref={inputRef}
188
+ value={query}
189
+ onChangeText={setQuery}
190
+ placeholder="Rue de Paris, Saint Denis"
191
+ placeholderTextColor={t.colors.muted}
192
+ style={[styles.input, { color: theme.colors.onSurface }]}
193
+ autoFocus
194
+ returnKeyType="search"
195
+ autoCorrect={false}
196
+ autoCapitalize="words"
197
+ />
198
+ {query.length > 0 ? (
199
+ <Pressable
200
+ onPress={() => {
201
+ setQuery("");
202
+ setSelectedStreet(null);
203
+ inputRef.current?.focus();
204
+ }}
205
+ hitSlop={8}
206
+ >
207
+ <X size={16} color={t.colors.muted} />
208
+ </Pressable>
209
+ ) : null}
210
+ </View>
211
+
212
+ {!cityGroupId ? (
213
+ <Text style={[styles.error, { color: theme.colors.error }]}>
214
+ Configuration manquante : cityGroupId requis pour la recherche de rues.
215
+ </Text>
216
+ ) : null}
217
+
218
+ {showEmptyHint ? (
219
+ <View style={styles.hint}>
220
+ <Text style={[styles.hintTitle, { color: theme.colors.onBackground }]}>
221
+ Où habitez-vous ?
222
+ </Text>
223
+ <Text style={[styles.hintSub, { color: t.colors.muted }]}>
224
+ Recherchez le nom de votre rue afin de définir votre secteur de collecte
225
+ </Text>
226
+ </View>
227
+ ) : null}
228
+
229
+ {step === "pickSector" && selectedStreet ? (
230
+ <FlatList
231
+ data={selectedStreet.sectors}
232
+ keyExtractor={(item) => item.id}
233
+ contentContainerStyle={styles.listContent}
234
+ keyboardShouldPersistTaps="handled"
235
+ ListHeaderComponent={
236
+ <Text style={[styles.sectionTitle, { color: t.colors.muted }]}>
237
+ Choisissez votre secteur
238
+ </Text>
239
+ }
240
+ renderItem={({ item }) => (
241
+ <Pressable
242
+ onPress={() => onSelectSector(item)}
243
+ style={[
244
+ styles.row,
245
+ { borderBottomColor: theme.colors.border },
246
+ ]}
247
+ >
248
+ <View style={[styles.pin, { backgroundColor: theme.colors.border }]}>
249
+ <MapPin size={16} color={t.colors.muted} />
250
+ </View>
251
+ <View style={styles.rowText}>
252
+ <Text style={[styles.rowTitle, { color: theme.colors.onSurface }]}>
253
+ {item.name}
254
+ </Text>
255
+ <Text style={[styles.rowSub, { color: t.colors.muted }]}>
256
+ {item.cityName}
257
+ </Text>
258
+ </View>
259
+ </Pressable>
260
+ )}
261
+ />
262
+ ) : null}
263
+
264
+ {showResults ? (
265
+ <>
266
+ {searching ? (
267
+ <ActivityIndicator
268
+ color={theme.colors.primary}
269
+ style={{ marginTop: 16 }}
270
+ />
271
+ ) : null}
272
+ {error ? (
273
+ <Text style={[styles.error, { color: theme.colors.error }]}>{error}</Text>
274
+ ) : null}
275
+ <FlatList
276
+ data={results}
277
+ keyExtractor={(item) => item.streetId}
278
+ keyboardShouldPersistTaps="handled"
279
+ contentContainerStyle={styles.listContent}
280
+ ListEmptyComponent={
281
+ !searching ? (
282
+ <Text style={[styles.empty, { color: t.colors.muted }]}>
283
+ Aucune rue trouvée
284
+ </Text>
285
+ ) : null
286
+ }
287
+ renderItem={({ item }) => {
288
+ const selected = selectedStreet?.streetId === item.streetId;
289
+ return (
290
+ <Pressable
291
+ onPress={() => onSelectStreet(item)}
292
+ style={[
293
+ styles.row,
294
+ {
295
+ borderBottomColor: theme.colors.border,
296
+ backgroundColor: selected
297
+ ? theme.colors.border
298
+ : "transparent",
299
+ },
300
+ ]}
301
+ >
302
+ <View
303
+ style={[
304
+ styles.pin,
305
+ { backgroundColor: theme.colors.border },
306
+ ]}
307
+ >
308
+ <MapPin size={16} color={t.colors.muted} />
309
+ </View>
310
+ <View style={styles.rowText}>
311
+ <Text
312
+ style={[
313
+ styles.rowTitle,
314
+ { color: theme.colors.onSurface },
315
+ ]}
316
+ >
317
+ {item.streetName}
318
+ </Text>
319
+ <Text style={[styles.rowSub, { color: t.colors.muted }]}>
320
+ {item.cityName}
321
+ </Text>
322
+ </View>
323
+ {selected ? (
324
+ <Check size={18} color={theme.colors.onSurface} />
325
+ ) : null}
326
+ </Pressable>
327
+ );
328
+ }}
329
+ />
330
+ {selectedStreet ? (
331
+ <Button
332
+ onPress={onContinueFromList}
333
+ style={[styles.primaryBtn, { borderRadius: t.radii.lg }]}
334
+ >
335
+ Continuer
336
+ </Button>
337
+ ) : null}
338
+ </>
339
+ ) : null}
340
+ </Animated.View>
341
+ )}
342
+ </KeyboardAvoidingView>
343
+ </Modal>
344
+ );
345
+ }
346
+
347
+ const styles = StyleSheet.create({
348
+ root: {
349
+ flex: 1,
350
+ paddingHorizontal: 16,
351
+ paddingTop: 8,
352
+ },
353
+ searchWrap: {
354
+ flex: 1,
355
+ gap: 12,
356
+ },
357
+ searchBar: {
358
+ flexDirection: "row",
359
+ alignItems: "center",
360
+ gap: 10,
361
+ paddingHorizontal: 14,
362
+ height: 48,
363
+ borderWidth: 1,
364
+ },
365
+ input: {
366
+ flex: 1,
367
+ fontSize: 16,
368
+ paddingVertical: 0,
369
+ },
370
+ hint: {
371
+ flex: 1,
372
+ justifyContent: "center",
373
+ alignItems: "center",
374
+ paddingHorizontal: 24,
375
+ gap: 10,
376
+ marginBottom: 80,
377
+ },
378
+ hintTitle: {
379
+ fontSize: 22,
380
+ fontWeight: "800",
381
+ textAlign: "center",
382
+ },
383
+ hintSub: {
384
+ fontSize: 15,
385
+ textAlign: "center",
386
+ lineHeight: 22,
387
+ },
388
+ listContent: {
389
+ paddingBottom: 16,
390
+ },
391
+ sectionTitle: {
392
+ fontSize: 13,
393
+ fontWeight: "600",
394
+ textTransform: "uppercase",
395
+ marginBottom: 8,
396
+ marginTop: 4,
397
+ },
398
+ row: {
399
+ flexDirection: "row",
400
+ alignItems: "center",
401
+ gap: 12,
402
+ paddingVertical: 12,
403
+ paddingHorizontal: 8,
404
+ borderBottomWidth: StyleSheet.hairlineWidth,
405
+ },
406
+ pin: {
407
+ width: 36,
408
+ height: 36,
409
+ borderRadius: 18,
410
+ alignItems: "center",
411
+ justifyContent: "center",
412
+ },
413
+ rowText: {
414
+ flex: 1,
415
+ gap: 2,
416
+ },
417
+ rowTitle: {
418
+ fontSize: 16,
419
+ fontWeight: "700",
420
+ },
421
+ rowSub: {
422
+ fontSize: 13,
423
+ },
424
+ empty: {
425
+ textAlign: "center",
426
+ marginTop: 24,
427
+ },
428
+ error: {
429
+ marginTop: 8,
430
+ fontSize: 13,
431
+ },
432
+ primaryBtn: {
433
+ height: 52,
434
+ marginBottom: 8,
435
+ },
436
+ confirmWrap: {
437
+ flex: 1,
438
+ justifyContent: "space-between",
439
+ paddingBottom: 24,
440
+ },
441
+ confirmCenter: {
442
+ flex: 1,
443
+ justifyContent: "center",
444
+ alignItems: "center",
445
+ gap: 8,
446
+ paddingHorizontal: 24,
447
+ },
448
+ confirmLabel: {
449
+ fontSize: 20,
450
+ fontWeight: "800",
451
+ textAlign: "center",
452
+ },
453
+ confirmZone: {
454
+ fontSize: 22,
455
+ fontWeight: "800",
456
+ textAlign: "center",
457
+ },
458
+ confirmActions: {
459
+ gap: 16,
460
+ alignItems: "stretch",
461
+ width: "100%",
462
+ },
463
+ confirmPrimaryBtn: {
464
+ height: 52,
465
+ width: "100%",
466
+ alignSelf: "stretch",
467
+ },
468
+ link: {
469
+ fontSize: 15,
470
+ fontWeight: "700",
471
+ paddingVertical: 4,
472
+ textAlign: "center",
473
+ alignSelf: "center",
474
+ },
475
+ });