@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,527 +1,546 @@
1
- import { useEffect, useMemo, useRef, useState, type ComponentType, type ReactNode } from "react";
2
- import {
3
- ActivityIndicator,
4
- Pressable,
5
- ScrollView,
6
- StyleSheet,
7
- Text,
8
- View,
9
- } from "react-native";
10
- import { ChevronRight, MapPin, X } from "lucide-react-native";
11
- import Animated, {
12
- Easing,
13
- interpolate,
14
- useAnimatedStyle,
15
- useSharedValue,
16
- withTiming,
17
- } from "react-native-reanimated";
18
- import { useTheme } from "../../contexts/ThemeContext";
19
- import type { ResolvedTheme } from "../../types/Theme";
20
- import {
21
- LOCATION_CATEGORY_META,
22
- useLocations,
23
- type LocationCategory,
24
- type MapLocation,
25
- } from "../../hooks/useLocations";
26
- import { LocationSheet } from "./LocationSheet";
27
- import type { LocationsMapViewProps } from "./LocationsMapView";
28
- import { cardStyle, resolveTheme } from "../../helpers/themeStyles";
29
- import { getContrastColor } from "../../helpers/getContrastColor";
30
- import { Header } from "../header/Header";
31
- import { SPACE } from "../../helpers/layout";
32
-
33
- export type LocationsMapProps = {
34
- fullScreen?: boolean;
35
- showFilters?: boolean;
36
- /** Header flottant au-dessus de la carte (titre + cloche + profil). */
37
- overlayHeader?: boolean;
38
- overlayTitle?: string;
39
- };
40
-
41
- const CATEGORIES = Object.keys(LOCATION_CATEGORY_META) as LocationCategory[];
42
- const NOOP_NAV = { canGoBack: () => false, goBack: () => undefined };
43
- const PANEL_OPEN = { duration: 300, easing: Easing.out(Easing.cubic) };
44
- const PANEL_CLOSE = { duration: 260, easing: Easing.in(Easing.cubic) };
45
-
46
- export type LocationsMapShellProps = LocationsMapProps & {
47
- MapCanvas: ComponentType<LocationsMapViewProps>;
48
- };
49
-
50
- function RoundCtrl({
51
- onPress,
52
- children,
53
- label,
54
- radius,
55
- backgroundColor,
56
- borderColor,
57
- }: {
58
- onPress: () => void;
59
- children: ReactNode;
60
- label: string;
61
- radius: number;
62
- backgroundColor: string;
63
- borderColor: string;
64
- }) {
65
- return (
66
- <Pressable
67
- onPress={onPress}
68
- accessibilityLabel={label}
69
- style={[
70
- styles.roundCtrl,
71
- {
72
- borderRadius: radius,
73
- backgroundColor,
74
- borderColor,
75
- },
76
- ]}
77
- >
78
- {children}
79
- </Pressable>
80
- );
81
- }
82
-
83
- function FilterPanel({
84
- title,
85
- onClose,
86
- children,
87
- }: {
88
- title: string;
89
- onClose: () => void;
90
- children: ReactNode;
91
- }) {
92
- const { theme } = useTheme();
93
- const t = resolveTheme(theme);
94
- const progress = useSharedValue(0);
95
- const widthSv = useSharedValue(0);
96
- const closing = useRef(false);
97
- const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
98
-
99
- useEffect(() => {
100
- return () => {
101
- if (closeTimer.current) clearTimeout(closeTimer.current);
102
- };
103
- }, []);
104
-
105
- const close = () => {
106
- if (closing.current) return;
107
- closing.current = true;
108
- progress.value = withTiming(0, PANEL_CLOSE);
109
- closeTimer.current = setTimeout(onClose, PANEL_CLOSE.duration);
110
- };
111
-
112
- const panelStyle = useAnimatedStyle(() => {
113
- const width = widthSv.value;
114
- if (width <= 0) return { opacity: 0 };
115
- return {
116
- opacity: 1,
117
- transform: [
118
- { translateX: interpolate(progress.value, [0, 1], [-width, 0]) },
119
- ],
120
- };
121
- }, []);
122
-
123
- return (
124
- <Animated.View
125
- onLayout={(event) => {
126
- const nextWidth = event.nativeEvent.layout.width;
127
- if (nextWidth <= 0) return;
128
- const firstLayout = widthSv.value <= 0;
129
- widthSv.value = nextWidth;
130
- if (firstLayout) progress.value = withTiming(1, PANEL_OPEN);
131
- }}
132
- style={[styles.filterPanelOuter, panelStyle]}
133
- >
134
- <View
135
- style={[
136
- styles.filterPanel,
137
- cardStyle(theme),
138
- { borderRadius: t.radii.lg },
139
- ]}
140
- >
141
- <View style={styles.filterPanelHead}>
142
- <Text style={[styles.filterPanelTitle, { color: theme.colors.onSurface }]}>
143
- {title}
144
- </Text>
145
- <Pressable
146
- onPress={close}
147
- hitSlop={8}
148
- accessibilityRole="button"
149
- accessibilityLabel="Fermer les filtres"
150
- style={[
151
- styles.closeBtn,
152
- {
153
- backgroundColor: theme.colors.background,
154
- borderRadius: t.radii.pill,
155
- },
156
- ]}
157
- >
158
- <X size={16} color={theme.colors.onSurface} />
159
- </Pressable>
160
- </View>
161
- {children}
162
- </View>
163
- </Animated.View>
164
- );
165
- }
166
-
167
- export function LocationsMapShell({
168
- fullScreen = false,
169
- showFilters = true,
170
- overlayHeader = false,
171
- overlayTitle = "Carte",
172
- MapCanvas,
173
- }: LocationsMapShellProps): ReactNode {
174
- const { theme } = useTheme();
175
- const t = resolveTheme(theme);
176
- const themedStyles = createThemedStyles(theme);
177
- const { locations, isLoading, error, center } = useLocations();
178
- const [filters, setFilters] = useState<Set<LocationCategory>>(new Set());
179
- const [selected, setSelected] = useState<MapLocation | null>(null);
180
- const [filtersOpen, setFiltersOpen] = useState(false);
181
-
182
- const toggle = (category: LocationCategory) => {
183
- setFilters((prev) => {
184
- const next = new Set(prev);
185
- if (next.has(category)) next.delete(category);
186
- else next.add(category);
187
- return next;
188
- });
189
- };
190
-
191
- const visible = useMemo(() => {
192
- if (filters.size === 0) return locations;
193
- return locations.filter((loc) => filters.has(loc.category));
194
- }, [filters, locations]);
195
-
196
- const selectedCategories = CATEGORIES.filter((c) => filters.has(c));
197
- const showChipBar = selectedCategories.length > 0;
198
-
199
- const filterLabel =
200
- filters.size === 0
201
- ? "Tous les points"
202
- : filters.size === 1
203
- ? LOCATION_CATEGORY_META[[...filters][0]!].label
204
- : `${filters.size} filtres`;
205
-
206
- const selectLocation = (location: MapLocation) => {
207
- setSelected(location);
208
- setFiltersOpen(false);
209
- };
210
-
211
- const roundRadius = t.radii.pill;
212
-
213
- return (
214
- <View style={[styles.wrap, fullScreen && styles.fullScreen]}>
215
- <View
216
- style={[
217
- styles.mapShell,
218
- themedStyles.mapShell,
219
- fullScreen ? styles.mapShellFull : styles.mapShellFixed,
220
- ]}
221
- >
222
- {isLoading ? (
223
- <View style={styles.center}>
224
- <ActivityIndicator color={theme.colors.primary} />
225
- <Text style={themedStyles.muted}>Chargement de la carte…</Text>
226
- </View>
227
- ) : (
228
- <>
229
- <MapCanvas
230
- locations={visible}
231
- center={center}
232
- selectedId={selected?.id}
233
- onSelect={selectLocation}
234
- />
235
- {error ? (
236
- <View style={[styles.center, styles.mapOverlayMessage]} pointerEvents="none">
237
- <Text style={{ color: theme.colors.error, textAlign: "center" }}>
238
- {error}
239
- </Text>
240
- </View>
241
- ) : null}
242
- {!error && visible.length === 0 ? (
243
- <View style={[styles.center, styles.mapOverlayMessage]} pointerEvents="none">
244
- <Text style={themedStyles.muted}>Aucun point à afficher.</Text>
245
- </View>
246
- ) : null}
247
- </>
248
- )}
249
- </View>
250
-
251
- <View style={styles.topOverlay} pointerEvents="box-none">
252
- {overlayHeader ? (
253
- <Header
254
- overlay
255
- options={{ title: overlayTitle, headerBackVisible: false }}
256
- route={{ name: overlayTitle }}
257
- navigation={NOOP_NAV}
258
- />
259
- ) : null}
260
-
261
- {showFilters ? (
262
- <View style={styles.filtersOverlay} pointerEvents="box-none">
263
- {showChipBar ? (
264
- <ScrollView
265
- horizontal
266
- showsHorizontalScrollIndicator={false}
267
- style={styles.chipScrollView}
268
- contentContainerStyle={styles.chipScroll}
269
- >
270
- <RoundCtrl
271
- label="Ouvrir les filtres"
272
- onPress={() => setFiltersOpen(true)}
273
- radius={roundRadius}
274
- backgroundColor={theme.colors.surface}
275
- borderColor={theme.colors.border}
276
- >
277
- <ChevronRight size={16} color={theme.colors.onSurface} />
278
- </RoundCtrl>
279
- {selectedCategories.map((category) => {
280
- const meta = LOCATION_CATEGORY_META[category];
281
- const fg = getContrastColor(meta.color);
282
- return (
283
- <Pressable
284
- key={category}
285
- onPress={() => toggle(category)}
286
- style={[
287
- styles.chip,
288
- {
289
- backgroundColor: meta.color,
290
- borderRadius: t.radii.pill,
291
- },
292
- ]}
293
- >
294
- <Text style={[styles.chipText, { color: fg }]}>
295
- {meta.label}
296
- </Text>
297
- </Pressable>
298
- );
299
- })}
300
- <RoundCtrl
301
- label="Effacer les filtres"
302
- onPress={() => setFilters(new Set())}
303
- radius={roundRadius}
304
- backgroundColor={theme.colors.surface}
305
- borderColor={theme.colors.border}
306
- >
307
- <X size={16} color={theme.colors.onSurface} />
308
- </RoundCtrl>
309
- </ScrollView>
310
- ) : (
311
- <Pressable
312
- onPress={() => setFiltersOpen(true)}
313
- style={[
314
- styles.filterTrigger,
315
- cardStyle(theme),
316
- { borderRadius: t.radii.pill },
317
- ]}
318
- >
319
- <Text style={[styles.filterTriggerText, { color: theme.colors.onSurface }]}>
320
- {filterLabel}
321
- </Text>
322
- <ChevronRight size={16} color={theme.colors.onSurface} />
323
- </Pressable>
324
- )}
325
- {filtersOpen ? (
326
- <FilterPanel title={filterLabel} onClose={() => setFiltersOpen(false)}>
327
- <View style={styles.filterList}>
328
- {CATEGORIES.map((category) => {
329
- const meta = LOCATION_CATEGORY_META[category];
330
- const active = filters.has(category);
331
- const bg = active ? meta.color : theme.colors.background;
332
- const fg = active ? getContrastColor(meta.color) : t.colors.muted;
333
- return (
334
- <Pressable
335
- key={category}
336
- onPress={() => toggle(category)}
337
- style={[
338
- styles.filterRow,
339
- {
340
- backgroundColor: bg,
341
- borderRadius: t.radii.md,
342
- },
343
- ]}
344
- >
345
- <MapPin size={16} color={fg} />
346
- <Text style={[styles.filterRowText, { color: fg }]}>
347
- {meta.label}
348
- </Text>
349
- </Pressable>
350
- );
351
- })}
352
- </View>
353
- </FilterPanel>
354
- ) : null}
355
- </View>
356
- ) : null}
357
- </View>
358
-
359
- {selected ? (
360
- <View style={styles.sheetOverlay} pointerEvents="box-none">
361
- <LocationSheet location={selected} onClose={() => setSelected(null)} />
362
- </View>
363
- ) : null}
364
- </View>
365
- );
366
- }
367
-
368
- const createThemedStyles = (theme: ResolvedTheme) =>
369
- StyleSheet.create({
370
- mapShell: {
371
- backgroundColor: theme.colors.surface,
372
- borderRadius: theme.radii.lg,
373
- borderWidth: 1,
374
- borderColor: theme.colors.border,
375
- ...theme.shadow.soft,
376
- },
377
- muted: {
378
- color: theme.colors.muted ?? theme.colors.onBackground,
379
- },
380
- });
381
-
382
- const styles = StyleSheet.create({
383
- wrap: {
384
- position: "relative",
385
- },
386
- fullScreen: {
387
- flex: 1,
388
- },
389
- topOverlay: {
390
- position: "absolute",
391
- top: 0,
392
- left: 0,
393
- right: 0,
394
- zIndex: 2,
395
- },
396
- filtersOverlay: {
397
- overflow: "visible",
398
- paddingBottom: 8,
399
- },
400
- filterTrigger: {
401
- alignSelf: "flex-start",
402
- flexDirection: "row",
403
- alignItems: "center",
404
- gap: 8,
405
- marginHorizontal: SPACE.pageX,
406
- paddingHorizontal: 14,
407
- paddingVertical: 10,
408
- },
409
- filterTriggerText: {
410
- fontSize: 14,
411
- fontWeight: "700",
412
- },
413
- chipScrollView: {
414
- alignSelf: "stretch",
415
- flexGrow: 0,
416
- overflow: "visible",
417
- },
418
- chipScroll: {
419
- flexDirection: "row",
420
- alignItems: "center",
421
- gap: 8,
422
- paddingHorizontal: SPACE.pageX,
423
- paddingVertical: 8,
424
- flexGrow: 0,
425
- },
426
- chip: {
427
- paddingHorizontal: 14,
428
- paddingVertical: 10,
429
- },
430
- chipText: {
431
- fontSize: 13,
432
- fontWeight: "700",
433
- },
434
- roundCtrl: {
435
- width: SPACE.iconHit,
436
- height: SPACE.iconHit,
437
- alignItems: "center",
438
- justifyContent: "center",
439
- borderWidth: 1,
440
- ...({
441
- shadowColor: "#0F172A",
442
- shadowOffset: { width: 0, height: 1 },
443
- shadowOpacity: 0.08,
444
- shadowRadius: 3,
445
- elevation: 2,
446
- } as const),
447
- },
448
- closeBtn: {
449
- width: 28,
450
- height: 28,
451
- alignItems: "center",
452
- justifyContent: "center",
453
- overflow: "hidden",
454
- flexShrink: 0,
455
- },
456
- filterPanelOuter: {
457
- position: "absolute",
458
- top: 0,
459
- left: SPACE.pageX,
460
- right: SPACE.pageX,
461
- zIndex: 4,
462
- },
463
- filterPanel: {
464
- overflow: "hidden",
465
- paddingHorizontal: 16,
466
- paddingTop: 18,
467
- paddingBottom: 20,
468
- gap: 16,
469
- },
470
- filterPanelHead: {
471
- flexDirection: "row",
472
- justifyContent: "space-between",
473
- alignItems: "center",
474
- },
475
- filterPanelTitle: {
476
- fontSize: 15,
477
- fontWeight: "800",
478
- },
479
- filterList: {
480
- gap: 10,
481
- },
482
- filterRow: {
483
- flexDirection: "row",
484
- alignItems: "center",
485
- gap: 10,
486
- paddingHorizontal: 14,
487
- paddingVertical: 12,
488
- },
489
- filterRowText: {
490
- fontSize: 14,
491
- fontWeight: "600",
492
- },
493
- mapShell: {
494
- overflow: "hidden",
495
- position: "relative",
496
- },
497
- mapShellFixed: {
498
- height: 320,
499
- },
500
- mapShellFull: {
501
- flex: 1,
502
- minHeight: 280,
503
- borderRadius: 0,
504
- borderWidth: 0,
505
- },
506
- sheetOverlay: {
507
- position: "absolute",
508
- left: 0,
509
- right: 0,
510
- top: 0,
511
- bottom: 0,
512
- zIndex: 3,
513
- justifyContent: "flex-end",
514
- },
515
- center: {
516
- flex: 1,
517
- alignItems: "center",
518
- justifyContent: "center",
519
- padding: 16,
520
- gap: 8,
521
- },
522
- mapOverlayMessage: {
523
- ...StyleSheet.absoluteFillObject,
524
- backgroundColor: "rgba(255,255,255,0.72)",
525
- zIndex: 1,
526
- },
527
- });
1
+ import { useEffect, useMemo, useRef, useState, type ComponentType, type ReactNode } from "react";
2
+ import {
3
+ ActivityIndicator,
4
+ Pressable,
5
+ ScrollView,
6
+ StyleSheet,
7
+ Text,
8
+ View,
9
+ } from "react-native";
10
+ import { ChevronRight, MapPin, X } from "lucide-react-native";
11
+ import Animated, {
12
+ Easing,
13
+ interpolate,
14
+ useAnimatedStyle,
15
+ useSharedValue,
16
+ withTiming,
17
+ } from "react-native-reanimated";
18
+ import { useTheme } from "../../contexts/ThemeContext";
19
+ import type { ResolvedTheme } from "../../types/Theme";
20
+ import {
21
+ LOCATION_CATEGORY_META,
22
+ useLocations,
23
+ type LocationCategory,
24
+ type MapLocation,
25
+ } from "../../hooks/useLocations";
26
+ import { LocationSheet } from "./LocationSheet";
27
+ import type { LocationsMapViewProps } from "./LocationsMapView";
28
+ import { cardStyle, resolveTheme } from "../../helpers/themeStyles";
29
+ import { getContrastColor } from "../../helpers/getContrastColor";
30
+ import { Header, DEFAULT_HEADER_ACTIONS, type AppHeaderConfig } from "../header/Header";
31
+ import { useHeaderConfig } from "../../contexts/HeaderConfigContext";
32
+ import { SPACE } from "../../helpers/layout";
33
+
34
+ export type LocationsMapProps = {
35
+ fullScreen?: boolean;
36
+ showFilters?: boolean;
37
+ /** Header flottant au-dessus de la carte (même navbar que le layout, sans titre). */
38
+ overlayHeader?: boolean;
39
+ /**
40
+ * @deprecated Ignoré — la navbar n’affiche plus de titre d’écran.
41
+ * Conservé pour compatibilité des configs CMS existantes.
42
+ */
43
+ overlayTitle?: string;
44
+ /** Override optionnel ; sinon config du layout via `HeaderConfigProvider`. */
45
+ headerConfig?: AppHeaderConfig | null;
46
+ };
47
+
48
+ const CATEGORIES = Object.keys(LOCATION_CATEGORY_META) as LocationCategory[];
49
+ const NOOP_NAV = { canGoBack: () => false, goBack: () => undefined };
50
+ const PANEL_OPEN = { duration: 300, easing: Easing.out(Easing.cubic) };
51
+ const PANEL_CLOSE = { duration: 260, easing: Easing.in(Easing.cubic) };
52
+
53
+ export type LocationsMapShellProps = LocationsMapProps & {
54
+ MapCanvas: ComponentType<LocationsMapViewProps>;
55
+ };
56
+
57
+ function RoundCtrl({
58
+ onPress,
59
+ children,
60
+ label,
61
+ radius,
62
+ backgroundColor,
63
+ borderColor,
64
+ }: {
65
+ onPress: () => void;
66
+ children: ReactNode;
67
+ label: string;
68
+ radius: number;
69
+ backgroundColor: string;
70
+ borderColor: string;
71
+ }) {
72
+ return (
73
+ <Pressable
74
+ onPress={onPress}
75
+ accessibilityLabel={label}
76
+ style={[
77
+ styles.roundCtrl,
78
+ {
79
+ borderRadius: radius,
80
+ backgroundColor,
81
+ borderColor,
82
+ },
83
+ ]}
84
+ >
85
+ {children}
86
+ </Pressable>
87
+ );
88
+ }
89
+
90
+ function FilterPanel({
91
+ title,
92
+ onClose,
93
+ children,
94
+ }: {
95
+ title: string;
96
+ onClose: () => void;
97
+ children: ReactNode;
98
+ }) {
99
+ const { theme } = useTheme();
100
+ const t = resolveTheme(theme);
101
+ const progress = useSharedValue(0);
102
+ const widthSv = useSharedValue(0);
103
+ const closing = useRef(false);
104
+ const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
105
+
106
+ useEffect(() => {
107
+ return () => {
108
+ if (closeTimer.current) clearTimeout(closeTimer.current);
109
+ };
110
+ }, []);
111
+
112
+ const close = () => {
113
+ if (closing.current) return;
114
+ closing.current = true;
115
+ progress.value = withTiming(0, PANEL_CLOSE);
116
+ closeTimer.current = setTimeout(onClose, PANEL_CLOSE.duration);
117
+ };
118
+
119
+ const panelStyle = useAnimatedStyle(() => {
120
+ const width = widthSv.value;
121
+ if (width <= 0) return { opacity: 0 };
122
+ return {
123
+ opacity: 1,
124
+ transform: [
125
+ { translateX: interpolate(progress.value, [0, 1], [-width, 0]) },
126
+ ],
127
+ };
128
+ }, []);
129
+
130
+ return (
131
+ <Animated.View
132
+ onLayout={(event) => {
133
+ const nextWidth = event.nativeEvent.layout.width;
134
+ if (nextWidth <= 0) return;
135
+ const firstLayout = widthSv.value <= 0;
136
+ widthSv.value = nextWidth;
137
+ if (firstLayout) progress.value = withTiming(1, PANEL_OPEN);
138
+ }}
139
+ style={[styles.filterPanelOuter, panelStyle]}
140
+ >
141
+ <View
142
+ style={[
143
+ styles.filterPanel,
144
+ cardStyle(theme),
145
+ { borderRadius: t.radii.lg },
146
+ ]}
147
+ >
148
+ <View style={styles.filterPanelHead}>
149
+ <Text style={[styles.filterPanelTitle, { color: theme.colors.onSurface }]}>
150
+ {title}
151
+ </Text>
152
+ <Pressable
153
+ onPress={close}
154
+ hitSlop={8}
155
+ accessibilityRole="button"
156
+ accessibilityLabel="Fermer les filtres"
157
+ style={[
158
+ styles.closeBtn,
159
+ {
160
+ backgroundColor: theme.colors.background,
161
+ borderRadius: t.radii.pill,
162
+ },
163
+ ]}
164
+ >
165
+ <X size={16} color={theme.colors.onSurface} />
166
+ </Pressable>
167
+ </View>
168
+ {children}
169
+ </View>
170
+ </Animated.View>
171
+ );
172
+ }
173
+
174
+ export function LocationsMapShell({
175
+ fullScreen = false,
176
+ showFilters = true,
177
+ overlayHeader = false,
178
+ headerConfig: headerConfigProp,
179
+ MapCanvas,
180
+ }: LocationsMapShellProps): ReactNode {
181
+ const { theme } = useTheme();
182
+ const t = resolveTheme(theme);
183
+ const themedStyles = createThemedStyles(theme);
184
+ const layoutHeaderConfig = useHeaderConfig();
185
+ const { locations, isLoading, error, center } = useLocations();
186
+ const [filters, setFilters] = useState<Set<LocationCategory>>(new Set());
187
+ const [selected, setSelected] = useState<MapLocation | null>(null);
188
+ const [filtersOpen, setFiltersOpen] = useState(false);
189
+
190
+ const overlayHeaderConfig: AppHeaderConfig = useMemo(() => {
191
+ const raw = headerConfigProp ?? layoutHeaderConfig;
192
+ if (raw?.elements?.length) {
193
+ return {
194
+ elements: raw.elements.filter((el) => el.type !== "title"),
195
+ };
196
+ }
197
+ return { elements: DEFAULT_HEADER_ACTIONS.map((a) => ({ ...a })) };
198
+ }, [headerConfigProp, layoutHeaderConfig]);
199
+
200
+ const toggle = (category: LocationCategory) => {
201
+ setFilters((prev) => {
202
+ const next = new Set(prev);
203
+ if (next.has(category)) next.delete(category);
204
+ else next.add(category);
205
+ return next;
206
+ });
207
+ };
208
+
209
+ const visible = useMemo(() => {
210
+ if (filters.size === 0) return locations;
211
+ return locations.filter((loc) => filters.has(loc.category));
212
+ }, [filters, locations]);
213
+
214
+ const selectedCategories = CATEGORIES.filter((c) => filters.has(c));
215
+ const showChipBar = selectedCategories.length > 0;
216
+
217
+ const filterLabel =
218
+ filters.size === 0
219
+ ? "Tous les points"
220
+ : filters.size === 1
221
+ ? LOCATION_CATEGORY_META[[...filters][0]!].label
222
+ : `${filters.size} filtres`;
223
+
224
+ const selectLocation = (location: MapLocation) => {
225
+ setSelected(location);
226
+ setFiltersOpen(false);
227
+ };
228
+
229
+ const roundRadius = t.radii.pill;
230
+
231
+ return (
232
+ <View style={[styles.wrap, fullScreen && styles.fullScreen]}>
233
+ <View
234
+ style={[
235
+ styles.mapShell,
236
+ themedStyles.mapShell,
237
+ fullScreen ? styles.mapShellFull : styles.mapShellFixed,
238
+ ]}
239
+ >
240
+ {isLoading ? (
241
+ <View style={styles.center}>
242
+ <ActivityIndicator color={theme.colors.primary} />
243
+ <Text style={themedStyles.muted}>Chargement de la carte…</Text>
244
+ </View>
245
+ ) : (
246
+ <>
247
+ <MapCanvas
248
+ locations={visible}
249
+ center={center}
250
+ selectedId={selected?.id}
251
+ onSelect={selectLocation}
252
+ />
253
+ {error ? (
254
+ <View style={[styles.center, styles.mapOverlayMessage]} pointerEvents="none">
255
+ <Text style={{ color: theme.colors.error, textAlign: "center" }}>
256
+ {error}
257
+ </Text>
258
+ </View>
259
+ ) : null}
260
+ {!error && visible.length === 0 ? (
261
+ <View style={[styles.center, styles.mapOverlayMessage]} pointerEvents="none">
262
+ <Text style={themedStyles.muted}>Aucun point à afficher.</Text>
263
+ </View>
264
+ ) : null}
265
+ </>
266
+ )}
267
+ </View>
268
+
269
+ <View style={styles.topOverlay} pointerEvents="box-none">
270
+ {overlayHeader ? (
271
+ <Header
272
+ overlay
273
+ options={{ headerBackVisible: false }}
274
+ route={{ name: "map" }}
275
+ navigation={NOOP_NAV}
276
+ headerConfig={overlayHeaderConfig}
277
+ />
278
+ ) : null}
279
+
280
+ {showFilters ? (
281
+ <View style={styles.filtersOverlay} pointerEvents="box-none">
282
+ {showChipBar ? (
283
+ <ScrollView
284
+ horizontal
285
+ showsHorizontalScrollIndicator={false}
286
+ style={styles.chipScrollView}
287
+ contentContainerStyle={styles.chipScroll}
288
+ >
289
+ <RoundCtrl
290
+ label="Ouvrir les filtres"
291
+ onPress={() => setFiltersOpen(true)}
292
+ radius={roundRadius}
293
+ backgroundColor={theme.colors.surface}
294
+ borderColor={theme.colors.border}
295
+ >
296
+ <ChevronRight size={16} color={theme.colors.onSurface} />
297
+ </RoundCtrl>
298
+ {selectedCategories.map((category) => {
299
+ const meta = LOCATION_CATEGORY_META[category];
300
+ const fg = getContrastColor(meta.color);
301
+ return (
302
+ <Pressable
303
+ key={category}
304
+ onPress={() => toggle(category)}
305
+ style={[
306
+ styles.chip,
307
+ {
308
+ backgroundColor: meta.color,
309
+ borderRadius: t.radii.pill,
310
+ },
311
+ ]}
312
+ >
313
+ <Text style={[styles.chipText, { color: fg }]}>
314
+ {meta.label}
315
+ </Text>
316
+ </Pressable>
317
+ );
318
+ })}
319
+ <RoundCtrl
320
+ label="Effacer les filtres"
321
+ onPress={() => setFilters(new Set())}
322
+ radius={roundRadius}
323
+ backgroundColor={theme.colors.surface}
324
+ borderColor={theme.colors.border}
325
+ >
326
+ <X size={16} color={theme.colors.onSurface} />
327
+ </RoundCtrl>
328
+ </ScrollView>
329
+ ) : (
330
+ <Pressable
331
+ onPress={() => setFiltersOpen(true)}
332
+ style={[
333
+ styles.filterTrigger,
334
+ cardStyle(theme),
335
+ { borderRadius: t.radii.pill },
336
+ ]}
337
+ >
338
+ <Text style={[styles.filterTriggerText, { color: theme.colors.onSurface }]}>
339
+ {filterLabel}
340
+ </Text>
341
+ <ChevronRight size={16} color={theme.colors.onSurface} />
342
+ </Pressable>
343
+ )}
344
+ {filtersOpen ? (
345
+ <FilterPanel title={filterLabel} onClose={() => setFiltersOpen(false)}>
346
+ <View style={styles.filterList}>
347
+ {CATEGORIES.map((category) => {
348
+ const meta = LOCATION_CATEGORY_META[category];
349
+ const active = filters.has(category);
350
+ const bg = active ? meta.color : theme.colors.background;
351
+ const fg = active ? getContrastColor(meta.color) : t.colors.muted;
352
+ return (
353
+ <Pressable
354
+ key={category}
355
+ onPress={() => toggle(category)}
356
+ style={[
357
+ styles.filterRow,
358
+ {
359
+ backgroundColor: bg,
360
+ borderRadius: t.radii.md,
361
+ },
362
+ ]}
363
+ >
364
+ <MapPin size={16} color={fg} />
365
+ <Text style={[styles.filterRowText, { color: fg }]}>
366
+ {meta.label}
367
+ </Text>
368
+ </Pressable>
369
+ );
370
+ })}
371
+ </View>
372
+ </FilterPanel>
373
+ ) : null}
374
+ </View>
375
+ ) : null}
376
+ </View>
377
+
378
+ {selected ? (
379
+ <View style={styles.sheetOverlay} pointerEvents="box-none">
380
+ <LocationSheet location={selected} onClose={() => setSelected(null)} />
381
+ </View>
382
+ ) : null}
383
+ </View>
384
+ );
385
+ }
386
+
387
+ const createThemedStyles = (theme: ResolvedTheme) =>
388
+ StyleSheet.create({
389
+ mapShell: {
390
+ backgroundColor: theme.colors.surface,
391
+ borderRadius: theme.radii.lg,
392
+ borderWidth: 1,
393
+ borderColor: theme.colors.border,
394
+ ...theme.shadow.soft,
395
+ },
396
+ muted: {
397
+ color: theme.colors.muted ?? theme.colors.onBackground,
398
+ },
399
+ });
400
+
401
+ const styles = StyleSheet.create({
402
+ wrap: {
403
+ position: "relative",
404
+ },
405
+ fullScreen: {
406
+ flex: 1,
407
+ },
408
+ topOverlay: {
409
+ position: "absolute",
410
+ top: 0,
411
+ left: 0,
412
+ right: 0,
413
+ zIndex: 2,
414
+ },
415
+ filtersOverlay: {
416
+ overflow: "visible",
417
+ paddingBottom: 8,
418
+ },
419
+ filterTrigger: {
420
+ alignSelf: "flex-start",
421
+ flexDirection: "row",
422
+ alignItems: "center",
423
+ gap: 8,
424
+ marginHorizontal: SPACE.pageX,
425
+ paddingHorizontal: 14,
426
+ paddingVertical: 10,
427
+ },
428
+ filterTriggerText: {
429
+ fontSize: 14,
430
+ fontWeight: "700",
431
+ },
432
+ chipScrollView: {
433
+ alignSelf: "stretch",
434
+ flexGrow: 0,
435
+ overflow: "visible",
436
+ },
437
+ chipScroll: {
438
+ flexDirection: "row",
439
+ alignItems: "center",
440
+ gap: 8,
441
+ paddingHorizontal: SPACE.pageX,
442
+ paddingVertical: 8,
443
+ flexGrow: 0,
444
+ },
445
+ chip: {
446
+ paddingHorizontal: 14,
447
+ paddingVertical: 10,
448
+ },
449
+ chipText: {
450
+ fontSize: 13,
451
+ fontWeight: "700",
452
+ },
453
+ roundCtrl: {
454
+ width: SPACE.iconHit,
455
+ height: SPACE.iconHit,
456
+ alignItems: "center",
457
+ justifyContent: "center",
458
+ borderWidth: 1,
459
+ ...({
460
+ shadowColor: "#0F172A",
461
+ shadowOffset: { width: 0, height: 1 },
462
+ shadowOpacity: 0.08,
463
+ shadowRadius: 3,
464
+ elevation: 2,
465
+ } as const),
466
+ },
467
+ closeBtn: {
468
+ width: 28,
469
+ height: 28,
470
+ alignItems: "center",
471
+ justifyContent: "center",
472
+ overflow: "hidden",
473
+ flexShrink: 0,
474
+ },
475
+ filterPanelOuter: {
476
+ position: "absolute",
477
+ top: 0,
478
+ left: SPACE.pageX,
479
+ right: SPACE.pageX,
480
+ zIndex: 4,
481
+ },
482
+ filterPanel: {
483
+ overflow: "hidden",
484
+ paddingHorizontal: 16,
485
+ paddingTop: 18,
486
+ paddingBottom: 20,
487
+ gap: 16,
488
+ },
489
+ filterPanelHead: {
490
+ flexDirection: "row",
491
+ justifyContent: "space-between",
492
+ alignItems: "center",
493
+ },
494
+ filterPanelTitle: {
495
+ fontSize: 15,
496
+ fontWeight: "800",
497
+ },
498
+ filterList: {
499
+ gap: 10,
500
+ },
501
+ filterRow: {
502
+ flexDirection: "row",
503
+ alignItems: "center",
504
+ gap: 10,
505
+ paddingHorizontal: 14,
506
+ paddingVertical: 12,
507
+ },
508
+ filterRowText: {
509
+ fontSize: 14,
510
+ fontWeight: "600",
511
+ },
512
+ mapShell: {
513
+ overflow: "hidden",
514
+ position: "relative",
515
+ },
516
+ mapShellFixed: {
517
+ height: 320,
518
+ },
519
+ mapShellFull: {
520
+ flex: 1,
521
+ minHeight: 280,
522
+ borderRadius: 0,
523
+ borderWidth: 0,
524
+ },
525
+ sheetOverlay: {
526
+ position: "absolute",
527
+ left: 0,
528
+ right: 0,
529
+ top: 0,
530
+ bottom: 0,
531
+ zIndex: 3,
532
+ justifyContent: "flex-end",
533
+ },
534
+ center: {
535
+ flex: 1,
536
+ alignItems: "center",
537
+ justifyContent: "center",
538
+ padding: 16,
539
+ gap: 8,
540
+ },
541
+ mapOverlayMessage: {
542
+ ...StyleSheet.absoluteFillObject,
543
+ backgroundColor: "rgba(255,255,255,0.72)",
544
+ zIndex: 1,
545
+ },
546
+ });