@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,20 +1,20 @@
1
- import { useMemo } from "react";
2
-
3
- export function useColumns<T = any>(
4
- data: T[],
5
- itemsPerRow: number = 4,
6
- ): (T | null)[][] {
7
- return useMemo(() => {
8
- const rows: (T | null)[][] = [];
9
-
10
- for (let i = 0; i < data.length; i += itemsPerRow) {
11
- const row: (T | null)[] = data.slice(i, i + itemsPerRow);
12
- while (row.length < itemsPerRow) {
13
- row.push(null);
14
- }
15
- rows.push(row);
16
- }
17
-
18
- return rows;
19
- }, [data]);
1
+ import { useMemo } from "react";
2
+
3
+ export function useColumns<T = any>(
4
+ data: T[],
5
+ itemsPerRow: number = 4,
6
+ ): (T | null)[][] {
7
+ return useMemo(() => {
8
+ const rows: (T | null)[][] = [];
9
+
10
+ for (let i = 0; i < data.length; i += itemsPerRow) {
11
+ const row: (T | null)[] = data.slice(i, i + itemsPerRow);
12
+ while (row.length < itemsPerRow) {
13
+ row.push(null);
14
+ }
15
+ rows.push(row);
16
+ }
17
+
18
+ return rows;
19
+ }, [data]);
20
20
  }
@@ -1,62 +1,62 @@
1
- import { useMemo } from "react";
2
- import { normalizeWasteTypeToRecyclingInfo } from "../helpers/normalizeWasteTypeRecyclingInfo";
3
- import { useNextCollection } from "./useNextCollection";
4
-
5
- export type WasteTypeForConsignes = {
6
- name: string;
7
- imageUrl?: string;
8
- rules?: string[];
9
- color?: string;
10
- details?: Array<{
11
- id: string | number;
12
- material?: string;
13
- description?: string;
14
- imageUrl?: string;
15
- }>;
16
- };
17
-
18
- export type CityForConsignes = {
19
- general_collection_rules?: Record<string, string>;
20
- [key: string]: unknown;
21
- };
22
-
23
- export type UseConsignesResult = {
24
- currentCity: CityForConsignes | null;
25
- wasteType: WasteTypeForConsignes | null;
26
- isLoading: boolean;
27
- error: string | null;
28
- };
29
-
30
- /**
31
- * Prépare les données pour la modale de consignes à partir de:
32
- * - la ville courante (useNextCollection.city)
33
- * - la liste des wasteTypes (useNextCollection.wasteTypes)
34
- */
35
- export function useConsignes(wasteTypeId: string | null | undefined): UseConsignesResult {
36
- const { city, wasteTypes, isLoading, error } = useNextCollection();
37
-
38
- const wasteType = useMemo<WasteTypeForConsignes | null>(() => {
39
- if (!wasteTypeId) return null;
40
-
41
- const wt = (wasteTypes ?? []).find((w) => w.id === wasteTypeId);
42
- if (!wt) return null;
43
-
44
- const info = normalizeWasteTypeToRecyclingInfo(wt);
45
- if (!info) return null;
46
-
47
- return {
48
- name: info.name,
49
- imageUrl: info.imageUrl,
50
- rules: info.rules,
51
- details: info.details,
52
- color: info.color
53
- };
54
- }, [wasteTypeId, wasteTypes]);
55
-
56
- return {
57
- currentCity: (city as any) ?? null,
58
- wasteType,
59
- isLoading,
60
- error,
61
- };
62
- }
1
+ import { useMemo } from "react";
2
+ import { normalizeWasteTypeToRecyclingInfo } from "../helpers/normalizeWasteTypeRecyclingInfo";
3
+ import { useNextCollection } from "./useNextCollection";
4
+
5
+ export type WasteTypeForConsignes = {
6
+ name: string;
7
+ imageUrl?: string;
8
+ rules?: string[];
9
+ color?: string;
10
+ details?: Array<{
11
+ id: string | number;
12
+ material?: string;
13
+ description?: string;
14
+ imageUrl?: string;
15
+ }>;
16
+ };
17
+
18
+ export type CityForConsignes = {
19
+ general_collection_rules?: Record<string, string>;
20
+ [key: string]: unknown;
21
+ };
22
+
23
+ export type UseConsignesResult = {
24
+ currentCity: CityForConsignes | null;
25
+ wasteType: WasteTypeForConsignes | null;
26
+ isLoading: boolean;
27
+ error: string | null;
28
+ };
29
+
30
+ /**
31
+ * Prépare les données pour la modale de consignes à partir de:
32
+ * - la ville courante (useNextCollection.city)
33
+ * - la liste des wasteTypes (useNextCollection.wasteTypes)
34
+ */
35
+ export function useConsignes(wasteTypeId: string | null | undefined): UseConsignesResult {
36
+ const { city, wasteTypes, isLoading, error } = useNextCollection();
37
+
38
+ const wasteType = useMemo<WasteTypeForConsignes | null>(() => {
39
+ if (!wasteTypeId) return null;
40
+
41
+ const wt = (wasteTypes ?? []).find((w) => w.id === wasteTypeId);
42
+ if (!wt) return null;
43
+
44
+ const info = normalizeWasteTypeToRecyclingInfo(wt);
45
+ if (!info) return null;
46
+
47
+ return {
48
+ name: info.name,
49
+ imageUrl: info.imageUrl,
50
+ rules: info.rules,
51
+ details: info.details,
52
+ color: info.color
53
+ };
54
+ }, [wasteTypeId, wasteTypes]);
55
+
56
+ return {
57
+ currentCity: (city as any) ?? null,
58
+ wasteType,
59
+ isLoading,
60
+ error,
61
+ };
62
+ }
@@ -1,248 +1,120 @@
1
- import { useCallback, useEffect, useMemo, useState } from "react";
2
- import { MAX_PAGE_SIZE } from "@wasto/sdk";
3
- import { useLocal } from "../contexts/LocalContext";
4
- import {
5
- buildHoursSchedule,
6
- type HoursDayRow,
7
- type HoursStatus,
8
- } from "../helpers/hoursSchedule";
9
- import { useWastoClient } from "./useWastoClient";
10
-
11
- export type LocationCategory = "recycling" | "decheterie" | "collection_place" | "sorting_center";
12
-
13
- export type MapLocation = {
14
- id: string;
15
- name: string;
16
- category: LocationCategory;
17
- address?: string;
18
- phone?: string;
19
- hoursDisplay?: string;
20
- hoursRows?: HoursDayRow[];
21
- hoursStatus?: HoursStatus | null;
22
- lat: number;
23
- lon: number;
24
- badges?: string[];
25
- };
26
-
27
- export const LOCATION_CATEGORY_META: Record<
28
- LocationCategory,
29
- { label: string; color: string }
30
- > = {
31
- recycling: { label: "Points de collecte", color: "#00C2EE" },
32
- decheterie: { label: "Déchèteries", color: "#ea580c" },
33
- collection_place: { label: "Lieux de ramassage", color: "#7c3aed" },
34
- sorting_center: { label: "Centres de tri", color: "#8B00D8" },
35
- };
36
-
37
- export const REUNION_CENTER = { lat: -21.115, lon: 55.53 };
38
- const PAGE_SIZE = MAX_PAGE_SIZE;
39
-
40
- /** GeoJSON order is [lon, lat]. Rejects NaN / out-of-range. */
41
- export function isValidLatLon(lat: number, lon: number): boolean {
42
- return (
43
- Number.isFinite(lat) &&
44
- Number.isFinite(lon) &&
45
- lat >= -90 &&
46
- lat <= 90 &&
47
- lon >= -180 &&
48
- lon <= 180
49
- );
50
- }
51
-
52
- function toNumber(value: unknown): number | null {
53
- if (typeof value === "number") return Number.isFinite(value) ? value : null;
54
- if (typeof value === "string" && value.trim() !== "") {
55
- const n = Number(value);
56
- return Number.isFinite(n) ? n : null;
57
- }
58
- return null;
59
- }
60
-
61
- /** Named lon/lat fields — no SVG conversion. */
62
- function parseLngLat(
63
- lonCandidate: unknown,
64
- latCandidate: unknown,
65
- ): { lat: number; lon: number } | null {
66
- const lon = toNumber(lonCandidate);
67
- const lat = toNumber(latCandidate);
68
- if (lon == null || lat == null || !isValidLatLon(lat, lon)) return null;
69
- return { lat, lon };
70
- }
71
-
72
- /**
73
- * Prefer WGS84 latitude/longitude. Legacy coordinateX/Y are aliases
74
- * (X = longitude, Y = latitude) already in WGS84 after API migration.
75
- */
76
- function parseRecyclingPointCoords(p: Record<string, unknown>): { lat: number; lon: number } | null {
77
- const details =
78
- p.details != null && typeof p.details === "object"
79
- ? (p.details as Record<string, unknown>)
80
- : null;
81
-
82
- const named = parseLngLat(
83
- p.longitude ?? p.lon ?? details?.longitude ?? details?.lon,
84
- p.latitude ?? p.lat ?? details?.latitude ?? details?.lat,
85
- );
86
- if (named) return named;
87
-
88
- // Legacy aliases: coordinateX = longitude, coordinateY = latitude
89
- return parseLngLat(p.coordinateX, p.coordinateY);
90
- }
91
-
92
- function categorizeRecyclingType(type?: string): LocationCategory {
93
- const t = (type ?? "").toLowerCase();
94
- if (t.includes("déchèterie") || t.includes("decheterie") || t.includes("dechetterie")) {
95
- return "decheterie";
96
- }
97
- if (t.includes("tri") || t.includes("sorting")) {
98
- return "sorting_center";
99
- }
100
- return "recycling";
101
- }
102
-
103
- function asArray(res: unknown): unknown[] {
104
- if (Array.isArray(res)) return res;
105
- const data = (res as { data?: unknown })?.data;
106
- return Array.isArray(data) ? data : [];
107
- }
108
-
109
- function totalPagesFrom(res: unknown): number {
110
- const meta = (res as { meta?: { totalPages?: number } })?.meta;
111
- const totalPages = meta?.totalPages;
112
- return typeof totalPages === "number" && totalPages >= 1 ? totalPages : 1;
113
- }
114
-
115
- type PaginatedFetcher = (params: { page: number; pageSize: number }) => Promise<unknown>;
116
-
117
- async function fetchAllPages(fetchPage: PaginatedFetcher): Promise<unknown[]> {
118
- const first = await fetchPage({ page: 1, pageSize: PAGE_SIZE });
119
- const items = [...asArray(first)];
120
- const totalPages = totalPagesFrom(first);
121
-
122
- for (let page = 2; page <= totalPages; page++) {
123
- const res = await fetchPage({ page, pageSize: PAGE_SIZE });
124
- items.push(...asArray(res));
125
- }
126
-
127
- return items;
128
- }
129
-
130
- export type UseLocationsResult = {
131
- locations: MapLocation[];
132
- isLoading: boolean;
133
- error: string | null;
134
- center: { lat: number; lon: number };
135
- refetch: () => Promise<void>;
136
- };
137
-
138
- export function useLocations(): UseLocationsResult {
139
- const { selectedCityId } = useLocal();
140
- const client = useWastoClient();
141
-
142
- const [locations, setLocations] = useState<MapLocation[]>([]);
143
- const [isLoading, setIsLoading] = useState(false);
144
- const [error, setError] = useState<string | null>(null);
145
-
146
- const fetchLocations = useCallback(async () => {
147
- if (!selectedCityId) {
148
- setLocations([]);
149
- setIsLoading(false);
150
- setError(null);
151
- return;
152
- }
153
-
154
- try {
155
- setIsLoading(true);
156
- setError(null);
157
- const [points, places] = await Promise.all([
158
- fetchAllPages((params) =>
159
- client.public.cities.getRecyclingPoints(selectedCityId, params),
160
- ),
161
- fetchAllPages((params) =>
162
- client.public.cities.getWasteCollectionPlaces(selectedCityId, params),
163
- ),
164
- ]);
165
-
166
- const out: MapLocation[] = [];
167
-
168
- for (const raw of points) {
169
- const p = raw as Record<string, unknown>;
170
- const coords = parseRecyclingPointCoords(p);
171
- if (!coords) continue;
172
- const id = String(p.id ?? "");
173
- if (!id) continue;
174
- const hoursSource = {
175
- hours: typeof p.hours === "string" ? p.hours : null,
176
- details:
177
- p.details != null && typeof p.details === "object"
178
- ? (p.details as Record<string, unknown>)
179
- : null,
180
- };
181
- const schedule = buildHoursSchedule(hoursSource);
182
- out.push({
183
- id: `rp-${id}`,
184
- name: String(p.name ?? "Point de collecte"),
185
- category: categorizeRecyclingType(typeof p.type === "string" ? p.type : undefined),
186
- address: typeof p.address === "string" ? p.address : undefined,
187
- phone: typeof p.phone === "string" ? p.phone : undefined,
188
- hoursDisplay: schedule.summary ?? undefined,
189
- hoursRows: schedule.rows.length ? schedule.rows : undefined,
190
- hoursStatus: schedule.status,
191
- lat: coords.lat,
192
- lon: coords.lon,
193
- badges: schedule.status ? [schedule.status.text] : schedule.summary ? [schedule.summary] : undefined,
194
- });
195
- }
196
-
197
- for (const raw of places) {
198
- const place = raw as Record<string, unknown>;
199
- const locs = Array.isArray(place.attachedLocations) ? place.attachedLocations : [];
200
- const loc = locs.find((item) => {
201
- const l = item as Record<string, unknown>;
202
- return l.latitude != null && l.longitude != null;
203
- }) as Record<string, unknown> | undefined;
204
- if (!loc) continue;
205
- const coords = parseLngLat(loc.longitude, loc.latitude);
206
- if (!coords) continue;
207
- const id = String(place.id ?? loc.id ?? "");
208
- if (!id) continue;
209
- out.push({
210
- id: `cp-${id}`,
211
- name: String(place.name ?? loc.name ?? "Lieu de ramassage"),
212
- category: "collection_place",
213
- address: typeof loc.reference === "string" ? loc.reference : undefined,
214
- lat: coords.lat,
215
- lon: coords.lon,
216
- });
217
- }
218
-
219
- setLocations(out);
220
- } catch (err) {
221
- setError(err instanceof Error ? err.message : "Impossible de charger les lieux");
222
- setLocations([]);
223
- } finally {
224
- setIsLoading(false);
225
- }
226
- }, [client.public.cities, selectedCityId]);
227
-
228
- useEffect(() => {
229
- void fetchLocations();
230
- }, [fetchLocations]);
231
-
232
- const center = useMemo(() => {
233
- const valid = locations.filter((l) => isValidLatLon(l.lat, l.lon));
234
- if (valid.length === 0) return REUNION_CENTER;
235
- const lat = valid.reduce((sum, l) => sum + l.lat, 0) / valid.length;
236
- const lon = valid.reduce((sum, l) => sum + l.lon, 0) / valid.length;
237
- if (!isValidLatLon(lat, lon)) return REUNION_CENTER;
238
- return { lat, lon };
239
- }, [locations]);
240
-
241
- return {
242
- locations,
243
- isLoading,
244
- error,
245
- center,
246
- refetch: fetchLocations,
247
- };
248
- }
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { MAX_PAGE_SIZE } from "@wasto/sdk";
3
+ import { useLocal } from "../contexts/LocalContext";
4
+ import { useOptionalAppData } from "../contexts/AppDataContext";
5
+ import {
6
+ computeMapCenter,
7
+ isValidLatLon,
8
+ LOCATION_CATEGORY_META,
9
+ normalizeMapLocations,
10
+ REUNION_CENTER,
11
+ type LocationCategory,
12
+ type MapLocation,
13
+ } from "../helpers/mapLocations";
14
+ import { useWastoClient } from "./useWastoClient";
15
+
16
+ export type { LocationCategory, MapLocation };
17
+ export { LOCATION_CATEGORY_META, REUNION_CENTER, isValidLatLon };
18
+
19
+ const PAGE_SIZE = MAX_PAGE_SIZE;
20
+
21
+ function asArray(res: unknown): unknown[] {
22
+ if (Array.isArray(res)) return res;
23
+ const data = (res as { data?: unknown })?.data;
24
+ return Array.isArray(data) ? data : [];
25
+ }
26
+
27
+ function totalPagesFrom(res: unknown): number {
28
+ const meta = (res as { meta?: { totalPages?: number } })?.meta;
29
+ const totalPages = meta?.totalPages;
30
+ return typeof totalPages === "number" && totalPages >= 1 ? totalPages : 1;
31
+ }
32
+
33
+ type PaginatedFetcher = (params: { page: number; pageSize: number }) => Promise<unknown>;
34
+
35
+ async function fetchAllPages(fetchPage: PaginatedFetcher): Promise<unknown[]> {
36
+ const first = await fetchPage({ page: 1, pageSize: PAGE_SIZE });
37
+ const items = [...asArray(first)];
38
+ const totalPages = totalPagesFrom(first);
39
+
40
+ for (let page = 2; page <= totalPages; page++) {
41
+ const res = await fetchPage({ page, pageSize: PAGE_SIZE });
42
+ items.push(...asArray(res));
43
+ }
44
+
45
+ return items;
46
+ }
47
+
48
+ export type UseLocationsResult = {
49
+ locations: MapLocation[];
50
+ isLoading: boolean;
51
+ error: string | null;
52
+ center: { lat: number; lon: number };
53
+ refetch: () => Promise<void>;
54
+ };
55
+
56
+ export function useLocations(): UseLocationsResult {
57
+ const { selectedCityId } = useLocal();
58
+ const appData = useOptionalAppData();
59
+ const client = useWastoClient();
60
+
61
+ const [locations, setLocations] = useState<MapLocation[]>([]);
62
+ const [isLoading, setIsLoading] = useState(false);
63
+ const [error, setError] = useState<string | null>(null);
64
+
65
+ const useShared = Boolean(appData);
66
+
67
+ const fetchLocations = useCallback(async () => {
68
+ if (useShared && appData) {
69
+ await appData.refreshCachedData();
70
+ return;
71
+ }
72
+
73
+ if (!selectedCityId) {
74
+ setLocations([]);
75
+ setIsLoading(false);
76
+ setError(null);
77
+ return;
78
+ }
79
+
80
+ try {
81
+ setIsLoading(true);
82
+ setError(null);
83
+ const [points, places] = await Promise.all([
84
+ fetchAllPages((params) =>
85
+ client.public.cities.getRecyclingPoints(selectedCityId, params),
86
+ ),
87
+ fetchAllPages((params) =>
88
+ client.public.cities.getWasteCollectionPlaces(selectedCityId, params),
89
+ ),
90
+ ]);
91
+
92
+ setLocations(normalizeMapLocations(points, places));
93
+ } catch (err) {
94
+ setError(err instanceof Error ? err.message : "Impossible de charger les lieux");
95
+ setLocations([]);
96
+ } finally {
97
+ setIsLoading(false);
98
+ }
99
+ }, [appData, client.public.cities, selectedCityId, useShared]);
100
+
101
+ useEffect(() => {
102
+ if (useShared) return;
103
+ void fetchLocations();
104
+ }, [fetchLocations, useShared]);
105
+
106
+ const sharedLocations = useShared && appData ? appData.locations : locations;
107
+ const center = useMemo(
108
+ () =>
109
+ useShared && appData ? appData.mapCenter : computeMapCenter(sharedLocations),
110
+ [appData, sharedLocations, useShared],
111
+ );
112
+
113
+ return {
114
+ locations: sharedLocations,
115
+ isLoading: useShared && appData ? appData.isMapLoading : isLoading,
116
+ error: useShared && appData ? appData.mapError : error,
117
+ center,
118
+ refetch: fetchLocations,
119
+ };
120
+ }