@wasto/cms-components 1.5.10

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 (94) hide show
  1. package/README.md +47 -0
  2. package/dist/index.d.mts +465 -0
  3. package/dist/index.d.ts +465 -0
  4. package/dist/index.js +10445 -0
  5. package/dist/index.mjs +10553 -0
  6. package/package.json +90 -0
  7. package/src/components/announcement-modal/AnnouncementModal.tsx +183 -0
  8. package/src/components/article/Article.tsx +22 -0
  9. package/src/components/article/ArticleCard.tsx +81 -0
  10. package/src/components/article/ArticleExcerpts.tsx +80 -0
  11. package/src/components/article/ArticleList.tsx +114 -0
  12. package/src/components/article/ArticleMarkdown.tsx +170 -0
  13. package/src/components/article/ArticleReaderModal.tsx +93 -0
  14. package/src/components/article/ArticleSingle.tsx +57 -0
  15. package/src/components/bottom-tab/BottomTab.tsx +392 -0
  16. package/src/components/button/Button.tsx +154 -0
  17. package/src/components/challenge/Badges.tsx +84 -0
  18. package/src/components/challenge/BadgesModal.tsx +166 -0
  19. package/src/components/challenge/Challenge.tsx +380 -0
  20. package/src/components/challenge/ChallengeModal.tsx +231 -0
  21. package/src/components/challenge/ChallengeVignette.tsx +249 -0
  22. package/src/components/challenge/ChallengesModal.tsx +243 -0
  23. package/src/components/challenge/QuizModal.tsx +381 -0
  24. package/src/components/challenge/ResultModal.tsx +144 -0
  25. package/src/components/chat/Chat.tsx +928 -0
  26. package/src/components/collection-calendar/CollectionCalendar.tsx +274 -0
  27. package/src/components/columns/Columns.tsx +34 -0
  28. package/src/components/consignes-modal/ConsignesModal.tsx +267 -0
  29. package/src/components/content-inset/ContentInset.tsx +33 -0
  30. package/src/components/header/Header.tsx +391 -0
  31. package/src/components/image/Image.tsx +16 -0
  32. package/src/components/image/ImageFrame.tsx +102 -0
  33. package/src/components/image/ImageMedia.tsx +31 -0
  34. package/src/components/image/ImageUrl.tsx +30 -0
  35. package/src/components/locations-map/LocationSheet.tsx +417 -0
  36. package/src/components/locations-map/LocationsMap.native.tsx +260 -0
  37. package/src/components/locations-map/LocationsMap.tsx +13 -0
  38. package/src/components/locations-map/LocationsMap.web.tsx +10 -0
  39. package/src/components/locations-map/LocationsMapShell.tsx +527 -0
  40. package/src/components/locations-map/LocationsMapView.tsx +108 -0
  41. package/src/components/locations-map/LocationsMapView.web.tsx +331 -0
  42. package/src/components/nav-button/NavButton.tsx +59 -0
  43. package/src/components/next-collection/NextCollection.tsx +621 -0
  44. package/src/components/notifications/NotificationsScreen.tsx +247 -0
  45. package/src/components/page/Page.tsx +64 -0
  46. package/src/components/parapraph/Paragraph.tsx +67 -0
  47. package/src/components/profile/ProfileScreen.tsx +236 -0
  48. package/src/components/recycling-info/RecyclingInfo.tsx +189 -0
  49. package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -0
  50. package/src/components/search/Search.tsx +320 -0
  51. package/src/components/select-street-modal/SelectStreetModal.tsx +475 -0
  52. package/src/components/title/Title.tsx +100 -0
  53. package/src/components/vision/Vision.tsx +447 -0
  54. package/src/components/vision/VisionActionCard.tsx +117 -0
  55. package/src/components/vision/VisionCapture.tsx +30 -0
  56. package/src/components/vision/VisionTapOverlay.tsx +122 -0
  57. package/src/contexts/AnnouncementsContext.tsx +171 -0
  58. package/src/contexts/ChallengesContext.tsx +182 -0
  59. package/src/contexts/LocalContext.tsx +227 -0
  60. package/src/contexts/ThemeContext.tsx +37 -0
  61. package/src/contexts/WastoContext.tsx +127 -0
  62. package/src/helpers/blogPost.ts +72 -0
  63. package/src/helpers/generateQuizQuestions.ts +247 -0
  64. package/src/helpers/getContrastColor.ts +19 -0
  65. package/src/helpers/haptics.ts +20 -0
  66. package/src/helpers/hoursSchedule.ts +230 -0
  67. package/src/helpers/htmlContentToMarkdown.ts +114 -0
  68. package/src/helpers/layout.ts +54 -0
  69. package/src/helpers/loadLinearGradient.ts +22 -0
  70. package/src/helpers/maquetteTheme.ts +76 -0
  71. package/src/helpers/markdownUnderlinePlugin.ts +32 -0
  72. package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -0
  73. package/src/helpers/publicMediaUrl.ts +8 -0
  74. package/src/helpers/resolveApiAssetUrl.ts +21 -0
  75. package/src/helpers/systemRoutes.ts +7 -0
  76. package/src/helpers/themeStyles.ts +114 -0
  77. package/src/helpers/useSafeAreaPadding.ts +14 -0
  78. package/src/hooks/useBadges.ts +100 -0
  79. package/src/hooks/useBlogPosts.ts +105 -0
  80. package/src/hooks/useChallenges.ts +110 -0
  81. package/src/hooks/useCities.ts +56 -0
  82. package/src/hooks/useCityAnnouncements.ts +118 -0
  83. package/src/hooks/useCollectionCalendar.ts +421 -0
  84. package/src/hooks/useColumns.ts +20 -0
  85. package/src/hooks/useConsignes.ts +62 -0
  86. package/src/hooks/useLocations.ts +248 -0
  87. package/src/hooks/useNextCollection.ts +238 -0
  88. package/src/hooks/useRecyclingInfo.ts +90 -0
  89. package/src/hooks/useWastoClient.ts +16 -0
  90. package/src/index.ts +142 -0
  91. package/src/navigation/NavigationContext.tsx +56 -0
  92. package/src/sentry/initSentry.ts +120 -0
  93. package/src/types/Theme.ts +72 -0
  94. package/src/types/css-modules.d.ts +1 -0
@@ -0,0 +1,417 @@
1
+ import { Linking, Platform, Pressable, ScrollView, Share, StyleSheet, Text, View } from "react-native";
2
+ import {
3
+ ChevronUp,
4
+ Clock,
5
+ Copy,
6
+ MapPin,
7
+ Phone,
8
+ X,
9
+ } from "lucide-react-native";
10
+ import { useEffect, useState, type ReactNode } from "react";
11
+ import { Gesture, GestureDetector } from "react-native-gesture-handler";
12
+ import Animated, {
13
+ Easing,
14
+ interpolate,
15
+ runOnJS,
16
+ useAnimatedStyle,
17
+ useSharedValue,
18
+ withTiming,
19
+ } from "react-native-reanimated";
20
+ import { useTheme } from "../../contexts/ThemeContext";
21
+ import { Theme } from "../../types/Theme";
22
+ import { Button } from "../button/Button";
23
+ import {
24
+ LOCATION_CATEGORY_META,
25
+ type MapLocation,
26
+ } from "../../hooks/useLocations";
27
+ import { cardStyle, resolveTheme } from "../../helpers/themeStyles";
28
+ import { SPACE } from "../../helpers/layout";
29
+
30
+ export type LocationSheetProps = {
31
+ location: MapLocation;
32
+ onClose: () => void;
33
+ };
34
+
35
+ const ENTER = { duration: 280, easing: Easing.out(Easing.cubic) };
36
+ const HOURS_ANIM = { duration: 240, easing: Easing.out(Easing.cubic) };
37
+ const DISMISS_Y = 96;
38
+ const DISMISS_V = 900;
39
+
40
+ async function copyText(value: string) {
41
+ try {
42
+ const webNav = (
43
+ globalThis as {
44
+ navigator?: { clipboard?: { writeText: (v: string) => Promise<void> } };
45
+ }
46
+ ).navigator;
47
+ if (Platform.OS === "web" && webNav?.clipboard?.writeText) {
48
+ await webNav.clipboard.writeText(value);
49
+ return;
50
+ }
51
+ await Share.share({ message: value });
52
+ } catch {
53
+ // ignore copy failures
54
+ }
55
+ }
56
+
57
+ export function LocationSheet({
58
+ location,
59
+ onClose,
60
+ }: LocationSheetProps): ReactNode {
61
+ const { theme } = useTheme();
62
+ const t = resolveTheme(theme);
63
+ const themedStyles = createThemedStyles(theme);
64
+ const meta = LOCATION_CATEGORY_META[location.category];
65
+ const [hoursOpen, setHoursOpen] = useState(false);
66
+ const translateY = useSharedValue(48);
67
+ const opacity = useSharedValue(0);
68
+ const hoursProgress = useSharedValue(0);
69
+ const hoursHeight = useSharedValue(0);
70
+
71
+ useEffect(() => {
72
+ setHoursOpen(false);
73
+ hoursProgress.value = 0;
74
+ translateY.value = 48;
75
+ opacity.value = 0;
76
+ translateY.value = withTiming(0, ENTER);
77
+ opacity.value = withTiming(1, { duration: 220, easing: Easing.out(Easing.cubic) });
78
+ }, [hoursProgress, location.id, opacity, translateY]);
79
+
80
+ const closeSheet = () => {
81
+ onClose();
82
+ };
83
+
84
+ const dismiss = () => {
85
+ opacity.value = withTiming(0, { duration: 180, easing: Easing.out(Easing.cubic) });
86
+ translateY.value = withTiming(420, { duration: 220, easing: Easing.in(Easing.cubic) }, (finished) => {
87
+ if (finished) runOnJS(closeSheet)();
88
+ });
89
+ };
90
+
91
+ const pan = Gesture.Pan()
92
+ .activeOffsetY(16)
93
+ .failOffsetX([-24, 24])
94
+ .onUpdate((event) => {
95
+ translateY.value = Math.max(0, event.translationY);
96
+ })
97
+ .onEnd((event) => {
98
+ if (event.translationY > DISMISS_Y || event.velocityY > DISMISS_V) {
99
+ runOnJS(dismiss)();
100
+ return;
101
+ }
102
+ translateY.value = withTiming(0, ENTER);
103
+ });
104
+
105
+ const sheetStyle = useAnimatedStyle(() => ({
106
+ transform: [{ translateY: translateY.value }],
107
+ opacity: opacity.value,
108
+ }), []);
109
+
110
+ const chevronStyle = useAnimatedStyle(() => ({
111
+ transform: [{ rotate: `${interpolate(hoursProgress.value, [0, 1], [180, 0])}deg` }],
112
+ }), []);
113
+
114
+ const hoursBodyStyle = useAnimatedStyle(() => ({
115
+ height: hoursHeight.value * hoursProgress.value,
116
+ opacity: hoursProgress.value,
117
+ overflow: "hidden" as const,
118
+ }), []);
119
+
120
+ const toggleHours = () => {
121
+ const next = !hoursOpen;
122
+ setHoursOpen(next);
123
+ hoursProgress.value = withTiming(next ? 1 : 0, HOURS_ANIM);
124
+ };
125
+
126
+ const openDirections = () => {
127
+ const q = encodeURIComponent(
128
+ location.address || `${location.lat},${location.lon}`,
129
+ );
130
+ void Linking.openURL(`https://maps.google.com/?q=${q}`);
131
+ };
132
+
133
+ const callPhone = () => {
134
+ if (!location.phone) return;
135
+ void Linking.openURL(`tel:${location.phone}`);
136
+ };
137
+
138
+ const hoursRows = location.hoursRows ?? [];
139
+ const hasHours = hoursRows.length > 0 || Boolean(location.hoursDisplay);
140
+ const status = location.hoursStatus;
141
+
142
+ return (
143
+ <GestureDetector gesture={pan}>
144
+ <Animated.View style={[sheetStyle, styles.sheetAnim]}>
145
+ <View
146
+ style={[
147
+ styles.sheet,
148
+ cardStyle(theme),
149
+ {
150
+ borderTopLeftRadius: t.radii.lg,
151
+ borderTopRightRadius: t.radii.lg,
152
+ borderBottomLeftRadius: 0,
153
+ borderBottomRightRadius: 0,
154
+ },
155
+ ]}
156
+ >
157
+ <View style={[styles.handle, { backgroundColor: theme.colors.border }]} />
158
+
159
+ <View style={styles.head}>
160
+ <View style={styles.headText}>
161
+ <Text style={[styles.name, { color: theme.colors.onSurface }]}>
162
+ {location.name}
163
+ </Text>
164
+ <Text style={themedStyles.meta}>{meta.label.toUpperCase()}</Text>
165
+ </View>
166
+ <Pressable
167
+ onPress={dismiss}
168
+ hitSlop={8}
169
+ accessibilityLabel="Fermer"
170
+ style={[
171
+ styles.closeBtn,
172
+ {
173
+ backgroundColor: theme.colors.background,
174
+ borderRadius: t.radii.pill,
175
+ },
176
+ ]}
177
+ >
178
+ <X size={16} color={theme.colors.onSurface} />
179
+ </Pressable>
180
+ </View>
181
+
182
+ <ScrollView
183
+ style={styles.bodyScroll}
184
+ contentContainerStyle={styles.bodyContent}
185
+ showsVerticalScrollIndicator={false}
186
+ >
187
+ {location.address ? (
188
+ <View style={styles.row}>
189
+ <MapPin size={16} color={t.colors.muted} />
190
+ <Text style={themedStyles.address}>{location.address}</Text>
191
+ <Pressable
192
+ onPress={() => void copyText(location.address!)}
193
+ hitSlop={8}
194
+ accessibilityLabel="Copier l’adresse"
195
+ >
196
+ <Copy size={16} color={theme.colors.primary} />
197
+ </Pressable>
198
+ </View>
199
+ ) : null}
200
+
201
+ {location.phone ? (
202
+ <View style={styles.row}>
203
+ <Phone size={16} color={t.colors.muted} />
204
+ <Text style={themedStyles.address}>{location.phone}</Text>
205
+ <Pressable
206
+ onPress={callPhone}
207
+ hitSlop={8}
208
+ accessibilityLabel="Appeler"
209
+ >
210
+ <Phone size={16} color={theme.colors.primary} />
211
+ </Pressable>
212
+ <Pressable
213
+ onPress={() => void copyText(location.phone!)}
214
+ hitSlop={8}
215
+ accessibilityLabel="Copier le numéro"
216
+ >
217
+ <Copy size={16} color={theme.colors.primary} />
218
+ </Pressable>
219
+ </View>
220
+ ) : null}
221
+
222
+ {hasHours ? (
223
+ <View
224
+ style={[
225
+ styles.hoursBox,
226
+ {
227
+ backgroundColor: theme.colors.background,
228
+ borderRadius: t.radii.md,
229
+ },
230
+ ]}
231
+ >
232
+ <Pressable onPress={toggleHours} style={styles.hoursHeader}>
233
+ <Clock size={16} color={t.colors.muted} />
234
+ <Text style={[styles.hoursStatus, { color: t.colors.muted }]}>
235
+ {status ? (
236
+ <>
237
+ <Text
238
+ style={{
239
+ color: status.open
240
+ ? theme.colors.primary
241
+ : theme.colors.error,
242
+ fontWeight: "700",
243
+ }}
244
+ >
245
+ {status.open ? "Ouvert" : "Fermé"}
246
+ </Text>
247
+ {status.text.includes(" - ")
248
+ ? ` - ${status.text.split(" - ").slice(1).join(" - ")}`
249
+ : ""}
250
+ </>
251
+ ) : (
252
+ location.hoursDisplay ?? "Horaires"
253
+ )}
254
+ </Text>
255
+ <Animated.View style={chevronStyle}>
256
+ <ChevronUp size={16} color={theme.colors.primary} />
257
+ </Animated.View>
258
+ </Pressable>
259
+ <Animated.View style={hoursBodyStyle}>
260
+ <View
261
+ style={styles.hoursMeasure}
262
+ onLayout={(event) => {
263
+ hoursHeight.value = event.nativeEvent.layout.height;
264
+ }}
265
+ >
266
+ {hoursRows.length > 0 ? (
267
+ <View style={styles.hoursList}>
268
+ {hoursRows.map((row) => (
269
+ <View key={row.label} style={styles.hoursRow}>
270
+ <Text style={[styles.hoursDay, { color: t.colors.muted }]}>
271
+ {row.label}
272
+ </Text>
273
+ <Text style={[styles.hoursValue, { color: t.colors.muted }]}>
274
+ {row.hours}
275
+ </Text>
276
+ </View>
277
+ ))}
278
+ </View>
279
+ ) : location.hoursDisplay ? (
280
+ <Text style={[styles.hoursFallback, { color: t.colors.muted }]}>
281
+ {location.hoursDisplay}
282
+ </Text>
283
+ ) : null}
284
+ </View>
285
+ </Animated.View>
286
+ </View>
287
+ ) : null}
288
+ </ScrollView>
289
+
290
+ <Button
291
+ onPress={openDirections}
292
+ rightIcon={MapPin}
293
+ style={[styles.cta, { borderRadius: t.radii.md }]}
294
+ >
295
+ Afficher Itinéraire
296
+ </Button>
297
+ </View>
298
+ </Animated.View>
299
+ </GestureDetector>
300
+ );
301
+ }
302
+
303
+ const createThemedStyles = (theme: Theme) =>
304
+ StyleSheet.create({
305
+ meta: {
306
+ color: theme.colors.muted ?? theme.colors.onSurface,
307
+ fontSize: 12,
308
+ fontWeight: "700",
309
+ letterSpacing: 0.4,
310
+ marginTop: 4,
311
+ },
312
+ address: {
313
+ color: theme.colors.onSurface,
314
+ flex: 1,
315
+ fontSize: 14,
316
+ },
317
+ });
318
+
319
+ const styles = StyleSheet.create({
320
+ sheetAnim: {
321
+ maxHeight: "82%",
322
+ },
323
+ sheet: {
324
+ paddingHorizontal: SPACE.pageX,
325
+ paddingTop: 14,
326
+ paddingBottom: SPACE.pageX,
327
+ gap: 24,
328
+ maxHeight: "100%",
329
+ },
330
+ handle: {
331
+ alignSelf: "center",
332
+ width: 40,
333
+ height: 4,
334
+ borderRadius: 2,
335
+ marginBottom: 2,
336
+ },
337
+ head: {
338
+ flexDirection: "row",
339
+ alignItems: "flex-start",
340
+ gap: 10,
341
+ },
342
+ headText: {
343
+ flex: 1,
344
+ },
345
+ closeBtn: {
346
+ width: 28,
347
+ height: 28,
348
+ alignItems: "center",
349
+ justifyContent: "center",
350
+ },
351
+ name: {
352
+ fontSize: 18,
353
+ fontWeight: "800",
354
+ },
355
+ bodyScroll: {
356
+ flexGrow: 0,
357
+ flexShrink: 1,
358
+ minHeight: 132,
359
+ },
360
+ bodyContent: {
361
+ gap: 22,
362
+ paddingBottom: 10,
363
+ },
364
+ row: {
365
+ flexDirection: "row",
366
+ alignItems: "center",
367
+ gap: 10,
368
+ },
369
+ hoursBox: {
370
+ padding: 12,
371
+ paddingBottom: 4,
372
+ },
373
+ hoursHeader: {
374
+ flexDirection: "row",
375
+ alignItems: "center",
376
+ gap: 8,
377
+ paddingBottom: 8,
378
+ },
379
+ hoursStatus: {
380
+ flex: 1,
381
+ fontSize: 14,
382
+ },
383
+ hoursList: {
384
+ gap: 6,
385
+ paddingLeft: 24,
386
+ paddingBottom: 8,
387
+ },
388
+ hoursMeasure: {
389
+ position: "absolute",
390
+ left: 0,
391
+ right: 0,
392
+ },
393
+ hoursRow: {
394
+ flexDirection: "row",
395
+ justifyContent: "space-between",
396
+ alignItems: "center",
397
+ gap: 12,
398
+ },
399
+ hoursDay: {
400
+ fontSize: 13,
401
+ },
402
+ hoursValue: {
403
+ fontSize: 13,
404
+ textAlign: "right",
405
+ flex: 1,
406
+ },
407
+ hoursFallback: {
408
+ fontSize: 13,
409
+ lineHeight: 18,
410
+ paddingLeft: 24,
411
+ paddingBottom: 8,
412
+ },
413
+ cta: {
414
+ height: SPACE.buttonH,
415
+ marginTop: 12,
416
+ },
417
+ });
@@ -0,0 +1,260 @@
1
+ import {
2
+ Camera,
3
+ GeoJSONSource,
4
+ Layer,
5
+ Map,
6
+ type CameraRef,
7
+ type GeoJSONSourceRef,
8
+ type PressEventWithFeatures,
9
+ } from "@maplibre/maplibre-react-native";
10
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
11
+ import { StyleSheet, View, type NativeSyntheticEvent } from "react-native";
12
+ import {
13
+ LOCATION_CATEGORY_META,
14
+ REUNION_CENTER,
15
+ isValidLatLon,
16
+ type LocationCategory,
17
+ type MapLocation,
18
+ } from "../../hooks/useLocations";
19
+ import type { LocationsMapViewProps } from "./LocationsMapView";
20
+ import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
21
+
22
+ export type { LocationsMapProps };
23
+
24
+ const MAP_STYLE = "https://tiles.openfreemap.org/styles/liberty";
25
+ const CLUSTER_RADIUS = 56;
26
+ const CLUSTER_MAX_ZOOM = 16;
27
+ const ZOOM_MIN = 8;
28
+ const ZOOM_MAX = 18;
29
+ const FIT_PADDING = { top: 48, right: 48, bottom: 48, left: 48 };
30
+
31
+ function toGeoJson(locations: MapLocation[]): GeoJSON.FeatureCollection {
32
+ return {
33
+ type: "FeatureCollection",
34
+ features: locations.map((loc) => ({
35
+ type: "Feature",
36
+ geometry: { type: "Point", coordinates: [loc.lon, loc.lat] },
37
+ properties: {
38
+ id: loc.id,
39
+ color: LOCATION_CATEGORY_META[loc.category as LocationCategory].color,
40
+ },
41
+ })),
42
+ };
43
+ }
44
+
45
+ function boundsFromLocations(locations: MapLocation[]): [number, number, number, number] | null {
46
+ if (locations.length === 0) return null;
47
+ let west = locations[0]!.lon;
48
+ let east = locations[0]!.lon;
49
+ let south = locations[0]!.lat;
50
+ let north = locations[0]!.lat;
51
+ for (const loc of locations) {
52
+ west = Math.min(west, loc.lon);
53
+ east = Math.max(east, loc.lon);
54
+ south = Math.min(south, loc.lat);
55
+ north = Math.max(north, loc.lat);
56
+ }
57
+ const pad = west === east && south === north ? 0.01 : 0;
58
+ return [west - pad, south - pad, east + pad, north + pad];
59
+ }
60
+
61
+ function isClusterFeature(feature: GeoJSON.Feature): boolean {
62
+ const props = feature.properties ?? {};
63
+ return props.cluster === true || typeof props.point_count === "number";
64
+ }
65
+
66
+ function NativeMapCanvas({
67
+ locations,
68
+ center,
69
+ selectedId,
70
+ onSelect,
71
+ }: LocationsMapViewProps) {
72
+ const cameraRef = useRef<CameraRef>(null);
73
+ const sourceRef = useRef<GeoJSONSourceRef>(null);
74
+ const [mapReady, setMapReady] = useState(false);
75
+
76
+ const safeCenter = useMemo(() => {
77
+ if (isValidLatLon(center.lat, center.lon)) return center;
78
+ return REUNION_CENTER;
79
+ }, [center]);
80
+
81
+ const validLocations = useMemo(
82
+ () => locations.filter((loc) => isValidLatLon(loc.lat, loc.lon)),
83
+ [locations],
84
+ );
85
+
86
+ const geojson = useMemo(() => toGeoJson(validLocations), [validLocations]);
87
+
88
+ const locationById = useMemo(() => {
89
+ const byId: Record<string, MapLocation> = {};
90
+ for (const loc of validLocations) byId[loc.id] = loc;
91
+ return byId;
92
+ }, [validLocations]);
93
+
94
+ const fitToLocations = useCallback(() => {
95
+ const bounds = boundsFromLocations(validLocations);
96
+ if (!bounds) return;
97
+ cameraRef.current?.fitBounds(bounds, { duration: 400, padding: FIT_PADDING });
98
+ }, [validLocations]);
99
+
100
+ useEffect(() => {
101
+ if (!mapReady) return;
102
+ fitToLocations();
103
+ }, [mapReady, fitToLocations]);
104
+
105
+ const onMapLoaded = useCallback(() => {
106
+ setMapReady(true);
107
+ }, []);
108
+
109
+ const onSourcePress = useCallback(
110
+ async (event: NativeSyntheticEvent<PressEventWithFeatures>) => {
111
+ if (typeof event.stopPropagation === "function") {
112
+ event.stopPropagation();
113
+ }
114
+ const feature = event.nativeEvent.features[0];
115
+ if (!feature) return;
116
+
117
+ if (isClusterFeature(feature)) {
118
+ const clusterId = Number(feature.properties?.cluster_id);
119
+ const coords =
120
+ feature.geometry.type === "Point"
121
+ ? (feature.geometry.coordinates as [number, number])
122
+ : event.nativeEvent.lngLat;
123
+ try {
124
+ const expansion =
125
+ Number.isFinite(clusterId)
126
+ ? await sourceRef.current?.getClusterExpansionZoom(clusterId)
127
+ : undefined;
128
+ const zoom = Math.min(
129
+ ZOOM_MAX,
130
+ typeof expansion === "number" && Number.isFinite(expansion)
131
+ ? expansion
132
+ : 14,
133
+ );
134
+ cameraRef.current?.easeTo({
135
+ center: coords,
136
+ zoom,
137
+ duration: 400,
138
+ easing: "ease",
139
+ });
140
+ } catch {
141
+ /* ignore native cluster lookup errors */
142
+ }
143
+ return;
144
+ }
145
+
146
+ const id = feature.properties?.id;
147
+ const loc = typeof id === "string" ? locationById[id] : undefined;
148
+ if (loc) onSelect(loc);
149
+ },
150
+ [locationById, onSelect],
151
+ );
152
+
153
+ const selectedKey = selectedId ?? "";
154
+
155
+ return (
156
+ <View style={styles.container}>
157
+ <Map
158
+ style={styles.map}
159
+ mapStyle={MAP_STYLE}
160
+ onDidFinishLoadingMap={onMapLoaded}
161
+ >
162
+ <Camera
163
+ ref={cameraRef}
164
+ initialViewState={{
165
+ zoom: 10,
166
+ center: [safeCenter.lon, safeCenter.lat],
167
+ }}
168
+ minZoom={ZOOM_MIN}
169
+ maxZoom={ZOOM_MAX}
170
+ />
171
+ {mapReady && validLocations.length > 0 ? (
172
+ <GeoJSONSource
173
+ id="locations"
174
+ ref={sourceRef}
175
+ data={geojson}
176
+ cluster
177
+ clusterRadius={CLUSTER_RADIUS}
178
+ clusterMaxZoom={CLUSTER_MAX_ZOOM}
179
+ onPress={onSourcePress}
180
+ >
181
+ <Layer
182
+ id="locations-clusters"
183
+ type="circle"
184
+ filter={["has", "point_count"]}
185
+ paint={{
186
+ "circle-color": [
187
+ "step",
188
+ ["get", "point_count"],
189
+ "#34d399",
190
+ 15,
191
+ "#10b981",
192
+ 50,
193
+ "#059669",
194
+ ],
195
+ "circle-radius": [
196
+ "step",
197
+ ["get", "point_count"],
198
+ 18,
199
+ 15,
200
+ 24,
201
+ 50,
202
+ 32,
203
+ ],
204
+ "circle-stroke-color": "#ffffff",
205
+ "circle-stroke-width": 2,
206
+ }}
207
+ />
208
+ <Layer
209
+ id="locations-cluster-count"
210
+ type="symbol"
211
+ filter={["has", "point_count"]}
212
+ layout={{
213
+ "text-field": ["get", "point_count_abbreviated"],
214
+ "text-font": ["Noto Sans Regular"],
215
+ "text-size": 12,
216
+ "text-allow-overlap": true,
217
+ }}
218
+ paint={{ "text-color": "#ffffff" }}
219
+ />
220
+ <Layer
221
+ id="locations-points"
222
+ type="circle"
223
+ filter={["!", ["has", "point_count"]]}
224
+ paint={{
225
+ "circle-radius": [
226
+ "case",
227
+ ["==", ["get", "id"], selectedKey],
228
+ 12,
229
+ 8,
230
+ ],
231
+ "circle-color": ["get", "color"],
232
+ "circle-stroke-color": [
233
+ "case",
234
+ ["==", ["get", "id"], selectedKey],
235
+ "#111827",
236
+ "#ffffff",
237
+ ],
238
+ "circle-stroke-width": 2,
239
+ }}
240
+ />
241
+ </GeoJSONSource>
242
+ ) : null}
243
+ </Map>
244
+ </View>
245
+ );
246
+ }
247
+
248
+ export function LocationsMap(props: LocationsMapProps) {
249
+ return <LocationsMapShell {...props} MapCanvas={NativeMapCanvas} />;
250
+ }
251
+
252
+ const styles = StyleSheet.create({
253
+ container: {
254
+ flex: 1,
255
+ minHeight: 220,
256
+ },
257
+ map: {
258
+ flex: 1,
259
+ },
260
+ });
@@ -0,0 +1,13 @@
1
+ import type { ReactNode } from "react";
2
+ /** Explicit `.web` — Metro platform extensions were not applied for this nested import. */
3
+ import { LocationsMapView } from "./LocationsMapView.web";
4
+ import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
5
+
6
+ export type { LocationsMapProps };
7
+
8
+ /**
9
+ * Web MapLibre canvas. Native uses `LocationsMap.native.tsx` instead of this file.
10
+ */
11
+ export function LocationsMap(props: LocationsMapProps): ReactNode {
12
+ return <LocationsMapShell {...props} MapCanvas={LocationsMapView} />;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { ReactNode } from "react";
2
+ import { LocationsMapView } from "./LocationsMapView";
3
+ import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
4
+
5
+ export type { LocationsMapProps };
6
+
7
+ /** Web entry: ensures MapLibre `.web` canvas (not the pin-only fallback). */
8
+ export function LocationsMap(props: LocationsMapProps): ReactNode {
9
+ return <LocationsMapShell {...props} MapCanvas={LocationsMapView} />;
10
+ }