@wasto/cms-components 1.5.10 → 1.5.11

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 (98) hide show
  1. package/README.md +47 -47
  2. package/dist/index.d.mts +103 -2
  3. package/dist/index.d.ts +103 -2
  4. package/dist/index.js +2861 -2442
  5. package/dist/index.mjs +3651 -3227
  6. package/package.json +2 -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 +391 -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 +527 -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/recycling-info/RecyclingInfo.tsx +189 -189
  49. package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
  50. package/src/components/search/Search.tsx +320 -320
  51. package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
  52. package/src/components/title/Title.tsx +100 -100
  53. package/src/components/vision/Vision.tsx +447 -447
  54. package/src/components/vision/VisionActionCard.tsx +117 -117
  55. package/src/components/vision/VisionCapture.tsx +30 -30
  56. package/src/components/vision/VisionTapOverlay.tsx +122 -122
  57. package/src/contexts/AnnouncementsContext.tsx +171 -171
  58. package/src/contexts/AppDataContext.tsx +458 -0
  59. package/src/contexts/ChallengesContext.tsx +182 -182
  60. package/src/contexts/LocalContext.tsx +227 -227
  61. package/src/contexts/ThemeContext.tsx +37 -37
  62. package/src/contexts/WastoContext.tsx +130 -127
  63. package/src/helpers/blogPost.ts +72 -72
  64. package/src/helpers/generateQuizQuestions.ts +247 -247
  65. package/src/helpers/getContrastColor.ts +18 -18
  66. package/src/helpers/haptics.ts +20 -20
  67. package/src/helpers/hoursSchedule.ts +230 -230
  68. package/src/helpers/htmlContentToMarkdown.ts +114 -114
  69. package/src/helpers/layout.ts +54 -54
  70. package/src/helpers/loadLinearGradient.ts +22 -22
  71. package/src/helpers/mapLocations.ts +170 -0
  72. package/src/helpers/maquetteTheme.ts +76 -76
  73. package/src/helpers/markdownUnderlinePlugin.ts +32 -32
  74. package/src/helpers/nextCollection.ts +122 -0
  75. package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
  76. package/src/helpers/publicMediaUrl.ts +8 -8
  77. package/src/helpers/resolveApiAssetUrl.ts +21 -21
  78. package/src/helpers/systemRoutes.ts +7 -7
  79. package/src/helpers/themeStyles.ts +114 -114
  80. package/src/helpers/ttlCache.ts +41 -0
  81. package/src/helpers/useSafeAreaPadding.ts +14 -14
  82. package/src/hooks/useBadges.ts +100 -100
  83. package/src/hooks/useBlogPosts.ts +109 -105
  84. package/src/hooks/useChallenges.ts +110 -110
  85. package/src/hooks/useCities.ts +56 -56
  86. package/src/hooks/useCityAnnouncements.ts +118 -118
  87. package/src/hooks/useCollectionCalendar.ts +421 -421
  88. package/src/hooks/useColumns.ts +19 -19
  89. package/src/hooks/useConsignes.ts +62 -62
  90. package/src/hooks/useLocations.ts +120 -248
  91. package/src/hooks/useNextCollection.ts +163 -238
  92. package/src/hooks/useRecyclingInfo.ts +90 -90
  93. package/src/hooks/useWastoClient.ts +16 -16
  94. package/src/index.ts +149 -142
  95. package/src/navigation/NavigationContext.tsx +56 -56
  96. package/src/sentry/initSentry.ts +120 -120
  97. package/src/types/Theme.ts +72 -72
  98. package/src/types/css-modules.d.ts +1 -1
@@ -1,114 +1,114 @@
1
- import { ViewStyle } from "react-native";
2
- import type { ResolvedTheme, Theme, ThemeShadowStyle } from "../types/Theme";
3
-
4
- function withAlpha(hex: string, alphaHex: string): string {
5
- const h = hex.replace("#", "").trim();
6
- if (h.length === 3) {
7
- const r = h[0];
8
- const g = h[1];
9
- const b = h[2];
10
- return `#${r}${r}${g}${g}${b}${b}${alphaHex}`;
11
- }
12
- if (h.length === 6) return `#${h}${alphaHex}`;
13
- if (h.length === 8) return `#${h.slice(0, 6)}${alphaHex}`;
14
- return `${hex}`;
15
- }
16
-
17
- const DEFAULT_SHADOW_COLOR = "#0F172A";
18
-
19
- /** Console-like shadow-sm defaults. */
20
- function defaultCardShadow(): ThemeShadowStyle {
21
- return {
22
- shadowColor: DEFAULT_SHADOW_COLOR,
23
- shadowOffset: { width: 0, height: 1 },
24
- shadowOpacity: 0.06,
25
- shadowRadius: 3,
26
- elevation: 1,
27
- };
28
- }
29
-
30
- function defaultSoftShadow(): ThemeShadowStyle {
31
- return {
32
- shadowColor: DEFAULT_SHADOW_COLOR,
33
- shadowOffset: { width: 0, height: 1 },
34
- shadowOpacity: 0.04,
35
- shadowRadius: 2,
36
- elevation: 1,
37
- };
38
- }
39
-
40
- /** Fill optional theme fields with sensible defaults (retrocompat / maquette-like). */
41
- export function resolveTheme(theme: Theme): ResolvedTheme {
42
- // Maquette default principal radius when omitted (cards ~20).
43
- const radius = theme.radius ?? 20;
44
- const primary = theme.colors.primary;
45
-
46
- return {
47
- ...theme,
48
- colors: {
49
- ...theme.colors,
50
- primarySoft: theme.colors.primarySoft ?? withAlpha(primary, "22"),
51
- surfaceElevated: theme.colors.surfaceElevated ?? theme.colors.surface,
52
- muted: theme.colors.muted ?? withAlpha(theme.colors.onSurface, "99"),
53
- },
54
- radii: theme.radii ?? {
55
- sm: Math.max(12, Math.round(radius * 0.6)),
56
- md: Math.max(14, Math.round(radius * 0.8)),
57
- lg: Math.max(radius, Math.round(radius * 1.2)),
58
- pill: 999,
59
- },
60
- shadow: {
61
- card: theme.shadow?.card ?? defaultCardShadow(),
62
- soft: theme.shadow?.soft ?? defaultSoftShadow(),
63
- },
64
- };
65
- }
66
-
67
- /**
68
- * Soft elevation tinted with a brand / category color.
69
- * Prefer border + category fill for cards; use sparingly (e.g. active chips).
70
- */
71
- export function coloredShadow(hex: string, opacity = 0.12): ThemeShadowStyle {
72
- return {
73
- shadowColor: hex,
74
- shadowOffset: { width: 0, height: 2 },
75
- shadowOpacity: opacity,
76
- shadowRadius: 4,
77
- elevation: 2,
78
- };
79
- }
80
-
81
- /** Shared card: surface + border + light shadow (console / shadcn). */
82
- export function cardStyle(theme: Theme, opts?: { elevated?: boolean }): ViewStyle {
83
- const t = resolveTheme(theme);
84
- return {
85
- backgroundColor: opts?.elevated ? t.colors.surfaceElevated : t.colors.surface,
86
- borderRadius: t.radii.lg,
87
- borderWidth: 1,
88
- borderColor: t.colors.border,
89
- ...t.shadow.card,
90
- };
91
- }
92
-
93
- export function softCardStyle(theme: Theme): ViewStyle {
94
- const t = resolveTheme(theme);
95
- return {
96
- backgroundColor: t.colors.surface,
97
- borderRadius: t.radii.md,
98
- borderWidth: 1,
99
- borderColor: t.colors.border,
100
- ...t.shadow.soft,
101
- };
102
- }
103
-
104
- /** Inset grouped list section: one surface, rows separated by internal hairlines. */
105
- export function groupedSectionStyle(theme: Theme): ViewStyle {
106
- const t = resolveTheme(theme);
107
- return {
108
- backgroundColor: t.colors.surface,
109
- borderRadius: t.radii.lg,
110
- borderWidth: 1,
111
- borderColor: t.colors.border,
112
- overflow: "hidden",
113
- };
114
- }
1
+ import { ViewStyle } from "react-native";
2
+ import type { ResolvedTheme, Theme, ThemeShadowStyle } from "../types/Theme";
3
+
4
+ function withAlpha(hex: string, alphaHex: string): string {
5
+ const h = hex.replace("#", "").trim();
6
+ if (h.length === 3) {
7
+ const r = h[0];
8
+ const g = h[1];
9
+ const b = h[2];
10
+ return `#${r}${r}${g}${g}${b}${b}${alphaHex}`;
11
+ }
12
+ if (h.length === 6) return `#${h}${alphaHex}`;
13
+ if (h.length === 8) return `#${h.slice(0, 6)}${alphaHex}`;
14
+ return `${hex}`;
15
+ }
16
+
17
+ const DEFAULT_SHADOW_COLOR = "#0F172A";
18
+
19
+ /** Console-like shadow-sm defaults. */
20
+ function defaultCardShadow(): ThemeShadowStyle {
21
+ return {
22
+ shadowColor: DEFAULT_SHADOW_COLOR,
23
+ shadowOffset: { width: 0, height: 1 },
24
+ shadowOpacity: 0.06,
25
+ shadowRadius: 3,
26
+ elevation: 1,
27
+ };
28
+ }
29
+
30
+ function defaultSoftShadow(): ThemeShadowStyle {
31
+ return {
32
+ shadowColor: DEFAULT_SHADOW_COLOR,
33
+ shadowOffset: { width: 0, height: 1 },
34
+ shadowOpacity: 0.04,
35
+ shadowRadius: 2,
36
+ elevation: 1,
37
+ };
38
+ }
39
+
40
+ /** Fill optional theme fields with sensible defaults (retrocompat / maquette-like). */
41
+ export function resolveTheme(theme: Theme): ResolvedTheme {
42
+ // Maquette default principal radius when omitted (cards ~20).
43
+ const radius = theme.radius ?? 20;
44
+ const primary = theme.colors.primary;
45
+
46
+ return {
47
+ ...theme,
48
+ colors: {
49
+ ...theme.colors,
50
+ primarySoft: theme.colors.primarySoft ?? withAlpha(primary, "22"),
51
+ surfaceElevated: theme.colors.surfaceElevated ?? theme.colors.surface,
52
+ muted: theme.colors.muted ?? withAlpha(theme.colors.onSurface, "99"),
53
+ },
54
+ radii: theme.radii ?? {
55
+ sm: Math.max(12, Math.round(radius * 0.6)),
56
+ md: Math.max(14, Math.round(radius * 0.8)),
57
+ lg: Math.max(radius, Math.round(radius * 1.2)),
58
+ pill: 999,
59
+ },
60
+ shadow: {
61
+ card: theme.shadow?.card ?? defaultCardShadow(),
62
+ soft: theme.shadow?.soft ?? defaultSoftShadow(),
63
+ },
64
+ };
65
+ }
66
+
67
+ /**
68
+ * Soft elevation tinted with a brand / category color.
69
+ * Prefer border + category fill for cards; use sparingly (e.g. active chips).
70
+ */
71
+ export function coloredShadow(hex: string, opacity = 0.12): ThemeShadowStyle {
72
+ return {
73
+ shadowColor: hex,
74
+ shadowOffset: { width: 0, height: 2 },
75
+ shadowOpacity: opacity,
76
+ shadowRadius: 4,
77
+ elevation: 2,
78
+ };
79
+ }
80
+
81
+ /** Shared card: surface + border + light shadow (console / shadcn). */
82
+ export function cardStyle(theme: Theme, opts?: { elevated?: boolean }): ViewStyle {
83
+ const t = resolveTheme(theme);
84
+ return {
85
+ backgroundColor: opts?.elevated ? t.colors.surfaceElevated : t.colors.surface,
86
+ borderRadius: t.radii.lg,
87
+ borderWidth: 1,
88
+ borderColor: t.colors.border,
89
+ ...t.shadow.card,
90
+ };
91
+ }
92
+
93
+ export function softCardStyle(theme: Theme): ViewStyle {
94
+ const t = resolveTheme(theme);
95
+ return {
96
+ backgroundColor: t.colors.surface,
97
+ borderRadius: t.radii.md,
98
+ borderWidth: 1,
99
+ borderColor: t.colors.border,
100
+ ...t.shadow.soft,
101
+ };
102
+ }
103
+
104
+ /** Inset grouped list section: one surface, rows separated by internal hairlines. */
105
+ export function groupedSectionStyle(theme: Theme): ViewStyle {
106
+ const t = resolveTheme(theme);
107
+ return {
108
+ backgroundColor: t.colors.surface,
109
+ borderRadius: t.radii.lg,
110
+ borderWidth: 1,
111
+ borderColor: t.colors.border,
112
+ overflow: "hidden",
113
+ };
114
+ }
@@ -0,0 +1,41 @@
1
+ import AsyncStorage from "@react-native-async-storage/async-storage";
2
+
3
+ export const APP_DATA_CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
4
+
5
+ type CacheEnvelope<T> = {
6
+ savedAt: number;
7
+ data: T;
8
+ };
9
+
10
+ export async function readTtlCache<T>(
11
+ key: string,
12
+ ttlMs: number = APP_DATA_CACHE_TTL_MS,
13
+ ): Promise<T | null> {
14
+ try {
15
+ const raw = await AsyncStorage.getItem(key);
16
+ if (!raw) return null;
17
+ const parsed = JSON.parse(raw) as CacheEnvelope<T>;
18
+ if (
19
+ !parsed ||
20
+ typeof parsed.savedAt !== "number" ||
21
+ parsed.data === undefined
22
+ ) {
23
+ return null;
24
+ }
25
+ if (Date.now() - parsed.savedAt > ttlMs) {
26
+ return null;
27
+ }
28
+ return parsed.data;
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+
34
+ export async function writeTtlCache<T>(key: string, data: T): Promise<void> {
35
+ const envelope: CacheEnvelope<T> = { savedAt: Date.now(), data };
36
+ await AsyncStorage.setItem(key, JSON.stringify(envelope));
37
+ }
38
+
39
+ export async function clearTtlCache(key: string): Promise<void> {
40
+ await AsyncStorage.removeItem(key);
41
+ }
@@ -1,14 +1,14 @@
1
- import { useSafeAreaInsets } from "react-native-safe-area-context";
2
-
3
- export type SafeAreaEdge = "top" | "bottom" | "left" | "right";
4
-
5
- /** Padding on a regular RN `View` — avoids Fabric `SafeAreaView` / codegen in bundled libs. */
6
- export function useSafeAreaPadding(edges: readonly SafeAreaEdge[]) {
7
- const insets = useSafeAreaInsets();
8
- return {
9
- ...(edges.includes("top") ? { paddingTop: insets.top } : null),
10
- ...(edges.includes("bottom") ? { paddingBottom: insets.bottom } : null),
11
- ...(edges.includes("left") ? { paddingLeft: insets.left } : null),
12
- ...(edges.includes("right") ? { paddingRight: insets.right } : null),
13
- };
14
- }
1
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
2
+
3
+ export type SafeAreaEdge = "top" | "bottom" | "left" | "right";
4
+
5
+ /** Padding on a regular RN `View` — avoids Fabric `SafeAreaView` / codegen in bundled libs. */
6
+ export function useSafeAreaPadding(edges: readonly SafeAreaEdge[]) {
7
+ const insets = useSafeAreaInsets();
8
+ return {
9
+ ...(edges.includes("top") ? { paddingTop: insets.top } : null),
10
+ ...(edges.includes("bottom") ? { paddingBottom: insets.bottom } : null),
11
+ ...(edges.includes("left") ? { paddingLeft: insets.left } : null),
12
+ ...(edges.includes("right") ? { paddingRight: insets.right } : null),
13
+ };
14
+ }
@@ -1,100 +1,100 @@
1
- import { useCallback, useEffect, useMemo, useState } from "react";
2
- import { useLocal } from "../contexts/LocalContext";
3
- import { useWastoClient } from "./useWastoClient";
4
-
5
- export type Badge = {
6
- id: string;
7
- name: string;
8
- description?: string;
9
- imageUrl?: string;
10
- icon?: string;
11
- challenge?: { id: string; name: string; order?: number };
12
- [key: string]: unknown;
13
- };
14
-
15
- export type PaginationMeta = {
16
- page: number;
17
- pageSize: number;
18
- total: number;
19
- pageCount: number;
20
- hasNextPage: boolean;
21
- hasPreviousPage: boolean;
22
- [key: string]: unknown;
23
- };
24
-
25
- export type UseBadgesOptions = {
26
- /** Si omis, utilise `LocalContext.selectedCityId`. */
27
- cityId?: string | null;
28
- page?: number;
29
- pageSize?: number;
30
- };
31
-
32
- export type UseBadgesResult = {
33
- cityId: string | null;
34
- badges: Badge[];
35
- meta: PaginationMeta | null;
36
- isLoading: boolean;
37
- error: string | null;
38
- refetch: () => Promise<void>;
39
- getBadgeById: (id: string) => Badge | undefined;
40
- };
41
-
42
- export function useBadges(options: UseBadgesOptions = {}): UseBadgesResult {
43
- const { selectedCityId } = useLocal();
44
-
45
- const resolvedCityId = options.cityId ?? selectedCityId ?? null;
46
- const page = options.page ?? 1;
47
- const pageSize = options.pageSize ?? 100;
48
-
49
- const client = useWastoClient();
50
-
51
- const [badges, setBadges] = useState<Badge[]>([]);
52
- const [meta, setMeta] = useState<PaginationMeta | null>(null);
53
- const [isLoading, setIsLoading] = useState<boolean>(false);
54
- const [error, setError] = useState<string | null>(null);
55
-
56
- const fetchBadges = useCallback(async () => {
57
- if (!resolvedCityId) {
58
- setBadges([]);
59
- setMeta(null);
60
- setIsLoading(false);
61
- setError(null);
62
- return;
63
- }
64
-
65
- try {
66
- setIsLoading(true);
67
- setError(null);
68
- const res = await client.public.cities.getBadges(resolvedCityId, { page, pageSize });
69
- const data = (res as { data?: unknown })?.data;
70
- const meta = (res as { meta?: unknown })?.meta;
71
- setBadges(Array.isArray(data) ? (data as Badge[]) : []);
72
- setMeta(meta && typeof meta === "object" ? (meta as PaginationMeta) : null);
73
- } catch (err) {
74
- const message =
75
- err instanceof Error ? err.message : typeof err === "string" ? err : "Impossible de charger les badges";
76
- setError(message);
77
- setBadges([]);
78
- setMeta(null);
79
- } finally {
80
- setIsLoading(false);
81
- }
82
- }, [client.public.cities, page, pageSize, resolvedCityId]);
83
-
84
- useEffect(() => {
85
- void fetchBadges();
86
- }, [fetchBadges]);
87
-
88
- const getBadgeById = useCallback((id: string) => badges.find((b) => b.id === id), [badges]);
89
-
90
- return {
91
- cityId: resolvedCityId,
92
- badges,
93
- meta,
94
- isLoading,
95
- error,
96
- refetch: fetchBadges,
97
- getBadgeById,
98
- };
99
- }
100
-
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { useLocal } from "../contexts/LocalContext";
3
+ import { useWastoClient } from "./useWastoClient";
4
+
5
+ export type Badge = {
6
+ id: string;
7
+ name: string;
8
+ description?: string;
9
+ imageUrl?: string;
10
+ icon?: string;
11
+ challenge?: { id: string; name: string; order?: number };
12
+ [key: string]: unknown;
13
+ };
14
+
15
+ export type PaginationMeta = {
16
+ page: number;
17
+ pageSize: number;
18
+ total: number;
19
+ pageCount: number;
20
+ hasNextPage: boolean;
21
+ hasPreviousPage: boolean;
22
+ [key: string]: unknown;
23
+ };
24
+
25
+ export type UseBadgesOptions = {
26
+ /** Si omis, utilise `LocalContext.selectedCityId`. */
27
+ cityId?: string | null;
28
+ page?: number;
29
+ pageSize?: number;
30
+ };
31
+
32
+ export type UseBadgesResult = {
33
+ cityId: string | null;
34
+ badges: Badge[];
35
+ meta: PaginationMeta | null;
36
+ isLoading: boolean;
37
+ error: string | null;
38
+ refetch: () => Promise<void>;
39
+ getBadgeById: (id: string) => Badge | undefined;
40
+ };
41
+
42
+ export function useBadges(options: UseBadgesOptions = {}): UseBadgesResult {
43
+ const { selectedCityId } = useLocal();
44
+
45
+ const resolvedCityId = options.cityId ?? selectedCityId ?? null;
46
+ const page = options.page ?? 1;
47
+ const pageSize = options.pageSize ?? 100;
48
+
49
+ const client = useWastoClient();
50
+
51
+ const [badges, setBadges] = useState<Badge[]>([]);
52
+ const [meta, setMeta] = useState<PaginationMeta | null>(null);
53
+ const [isLoading, setIsLoading] = useState<boolean>(false);
54
+ const [error, setError] = useState<string | null>(null);
55
+
56
+ const fetchBadges = useCallback(async () => {
57
+ if (!resolvedCityId) {
58
+ setBadges([]);
59
+ setMeta(null);
60
+ setIsLoading(false);
61
+ setError(null);
62
+ return;
63
+ }
64
+
65
+ try {
66
+ setIsLoading(true);
67
+ setError(null);
68
+ const res = await client.public.cities.getBadges(resolvedCityId, { page, pageSize });
69
+ const data = (res as { data?: unknown })?.data;
70
+ const meta = (res as { meta?: unknown })?.meta;
71
+ setBadges(Array.isArray(data) ? (data as Badge[]) : []);
72
+ setMeta(meta && typeof meta === "object" ? (meta as PaginationMeta) : null);
73
+ } catch (err) {
74
+ const message =
75
+ err instanceof Error ? err.message : typeof err === "string" ? err : "Impossible de charger les badges";
76
+ setError(message);
77
+ setBadges([]);
78
+ setMeta(null);
79
+ } finally {
80
+ setIsLoading(false);
81
+ }
82
+ }, [client.public.cities, page, pageSize, resolvedCityId]);
83
+
84
+ useEffect(() => {
85
+ void fetchBadges();
86
+ }, [fetchBadges]);
87
+
88
+ const getBadgeById = useCallback((id: string) => badges.find((b) => b.id === id), [badges]);
89
+
90
+ return {
91
+ cityId: resolvedCityId,
92
+ badges,
93
+ meta,
94
+ isLoading,
95
+ error,
96
+ refetch: fetchBadges,
97
+ getBadgeById,
98
+ };
99
+ }
100
+