@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.
- package/README.md +47 -47
- package/dist/index.d.mts +181 -51
- package/dist/index.d.ts +181 -51
- package/dist/index.js +3614 -3015
- package/dist/index.mjs +3021 -2418
- package/package.json +12 -2
- package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
- package/src/components/article/Article.tsx +21 -21
- package/src/components/article/ArticleCard.tsx +81 -81
- package/src/components/article/ArticleExcerpts.tsx +80 -80
- package/src/components/article/ArticleList.tsx +114 -114
- package/src/components/article/ArticleMarkdown.tsx +170 -170
- package/src/components/article/ArticleReaderModal.tsx +93 -93
- package/src/components/article/ArticleSingle.tsx +57 -57
- package/src/components/bottom-tab/BottomTab.tsx +392 -392
- package/src/components/button/Button.tsx +154 -154
- package/src/components/challenge/Badges.tsx +84 -84
- package/src/components/challenge/BadgesModal.tsx +166 -166
- package/src/components/challenge/Challenge.tsx +380 -380
- package/src/components/challenge/ChallengeModal.tsx +231 -231
- package/src/components/challenge/ChallengeVignette.tsx +249 -249
- package/src/components/challenge/ChallengesModal.tsx +243 -243
- package/src/components/challenge/QuizModal.tsx +381 -381
- package/src/components/challenge/ResultModal.tsx +144 -144
- package/src/components/chat/Chat.tsx +928 -928
- package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
- package/src/components/columns/Columns.tsx +33 -33
- package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
- package/src/components/content-inset/ContentInset.tsx +33 -33
- package/src/components/header/Header.tsx +415 -391
- package/src/components/image/Image.tsx +15 -15
- package/src/components/image/ImageFrame.tsx +102 -102
- package/src/components/image/ImageMedia.tsx +31 -31
- package/src/components/image/ImageUrl.tsx +30 -30
- package/src/components/locations-map/LocationSheet.tsx +417 -417
- package/src/components/locations-map/LocationsMap.native.tsx +260 -260
- package/src/components/locations-map/LocationsMap.tsx +13 -13
- package/src/components/locations-map/LocationsMap.web.tsx +10 -10
- package/src/components/locations-map/LocationsMapShell.tsx +546 -527
- package/src/components/locations-map/LocationsMapView.tsx +108 -108
- package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
- package/src/components/nav-button/NavButton.tsx +59 -59
- package/src/components/next-collection/NextCollection.tsx +636 -621
- package/src/components/notifications/NotificationsScreen.tsx +247 -247
- package/src/components/page/Page.tsx +102 -64
- package/src/components/parapraph/Paragraph.tsx +67 -67
- package/src/components/profile/ProfileScreen.tsx +236 -236
- package/src/components/push/PushTokenRegistrar.tsx +47 -0
- package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
- package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
- package/src/components/search/Search.tsx +320 -320
- package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
- package/src/components/title/Title.tsx +100 -100
- package/src/components/vision/Vision.tsx +447 -447
- package/src/components/vision/VisionActionCard.tsx +117 -117
- package/src/components/vision/VisionCapture.tsx +30 -30
- package/src/components/vision/VisionTapOverlay.tsx +122 -122
- package/src/contexts/AnnouncementsContext.tsx +171 -171
- package/src/contexts/AppDataContext.tsx +458 -0
- package/src/contexts/ChallengesContext.tsx +182 -182
- package/src/contexts/HeaderConfigContext.tsx +29 -0
- package/src/contexts/LocalContext.tsx +227 -227
- package/src/contexts/ThemeContext.tsx +37 -37
- package/src/contexts/WastoContext.tsx +132 -127
- package/src/helpers/blogPost.ts +72 -72
- package/src/helpers/generateQuizQuestions.ts +247 -247
- package/src/helpers/getContrastColor.ts +18 -18
- package/src/helpers/haptics.ts +20 -20
- package/src/helpers/hoursSchedule.ts +230 -230
- package/src/helpers/htmlContentToMarkdown.ts +114 -114
- package/src/helpers/layout.ts +54 -54
- package/src/helpers/loadLinearGradient.ts +22 -22
- package/src/helpers/mapLocations.ts +170 -0
- package/src/helpers/maquetteTheme.ts +76 -76
- package/src/helpers/markdownUnderlinePlugin.ts +32 -32
- package/src/helpers/nextCollection.ts +122 -0
- package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
- package/src/helpers/publicMediaUrl.ts +8 -8
- package/src/helpers/resolveApiAssetUrl.ts +21 -21
- package/src/helpers/systemRoutes.ts +7 -7
- package/src/helpers/themeStyles.ts +114 -114
- package/src/helpers/ttlCache.ts +41 -0
- package/src/helpers/useSafeAreaPadding.ts +14 -14
- package/src/hooks/useBadges.ts +100 -100
- package/src/hooks/useBlogPosts.ts +109 -105
- package/src/hooks/useChallenges.ts +110 -110
- package/src/hooks/useCities.ts +56 -56
- package/src/hooks/useCityAnnouncements.ts +118 -118
- package/src/hooks/useCollectionCalendar.ts +421 -421
- package/src/hooks/useColumns.ts +19 -19
- package/src/hooks/useConsignes.ts +62 -62
- package/src/hooks/useLocations.ts +120 -248
- package/src/hooks/useNextCollection.ts +163 -238
- package/src/hooks/useRecyclingInfo.ts +90 -90
- package/src/hooks/useWastoClient.ts +16 -16
- package/src/index.ts +161 -142
- package/src/navigation/NavigationContext.tsx +56 -56
- package/src/push/registerExpoPushToken.ts +133 -0
- package/src/sentry/initSentry.ts +120 -120
- package/src/types/Theme.ts +72 -72
- package/src/types/css-modules.d.ts +1 -1
|
@@ -1,105 +1,109 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
city.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
setPost(
|
|
93
|
-
setError(
|
|
94
|
-
}
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { useWasto } from "../contexts/WastoContext";
|
|
3
|
+
import { normalizeBlogPost, type BlogPost } from "../helpers/blogPost";
|
|
4
|
+
import { useNextCollection } from "./useNextCollection";
|
|
5
|
+
import { useWastoClient } from "./useWastoClient";
|
|
6
|
+
|
|
7
|
+
function cityGroupIdFromCity(city: Record<string, unknown> | null): string | undefined {
|
|
8
|
+
if (!city) return undefined;
|
|
9
|
+
const raw =
|
|
10
|
+
city.cityGroupId ??
|
|
11
|
+
city.city_group_id ??
|
|
12
|
+
(city.cityGroup != null && typeof city.cityGroup === "object"
|
|
13
|
+
? (city.cityGroup as { id?: unknown }).id
|
|
14
|
+
: undefined);
|
|
15
|
+
return typeof raw === "string" && raw.trim() ? raw.trim() : undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type UseBlogPostsResult = {
|
|
19
|
+
posts: BlogPost[];
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
error: string | null;
|
|
22
|
+
refetch: () => Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function useBlogPosts(options: { pageSize?: number } = {}): UseBlogPostsResult {
|
|
26
|
+
const { city } = useNextCollection();
|
|
27
|
+
const { cityGroupId: contextCityGroupId } = useWasto();
|
|
28
|
+
const client = useWastoClient();
|
|
29
|
+
const pageSize = options.pageSize ?? 50;
|
|
30
|
+
const cityGroupId =
|
|
31
|
+
cityGroupIdFromCity(city as Record<string, unknown> | null) ??
|
|
32
|
+
(contextCityGroupId?.trim() || undefined);
|
|
33
|
+
|
|
34
|
+
const [posts, setPosts] = useState<BlogPost[]>([]);
|
|
35
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
36
|
+
const [error, setError] = useState<string | null>(null);
|
|
37
|
+
|
|
38
|
+
const fetchPosts = useCallback(async () => {
|
|
39
|
+
try {
|
|
40
|
+
setIsLoading(true);
|
|
41
|
+
setError(null);
|
|
42
|
+
const res = await client.public.blogPosts.list(cityGroupId, { pageSize });
|
|
43
|
+
const data = (res as { data?: unknown })?.data;
|
|
44
|
+
const list = Array.isArray(data) ? data : [];
|
|
45
|
+
setPosts(list.map(normalizeBlogPost).filter((p): p is BlogPost => p != null));
|
|
46
|
+
} catch (err) {
|
|
47
|
+
setError(
|
|
48
|
+
err instanceof Error ? err.message : "Impossible de charger les articles"
|
|
49
|
+
);
|
|
50
|
+
setPosts([]);
|
|
51
|
+
} finally {
|
|
52
|
+
setIsLoading(false);
|
|
53
|
+
}
|
|
54
|
+
}, [cityGroupId, client.public.blogPosts, pageSize]);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
void fetchPosts();
|
|
58
|
+
}, [fetchPosts]);
|
|
59
|
+
|
|
60
|
+
return { posts, isLoading, error, refetch: fetchPosts };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type UseBlogPostResult = {
|
|
64
|
+
post: BlogPost | null;
|
|
65
|
+
isLoading: boolean;
|
|
66
|
+
error: string | null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export function useBlogPost(articleId: string): UseBlogPostResult {
|
|
70
|
+
const client = useWastoClient();
|
|
71
|
+
const [post, setPost] = useState<BlogPost | null>(null);
|
|
72
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
73
|
+
const [error, setError] = useState<string | null>(null);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const id = articleId.trim();
|
|
77
|
+
if (!id) {
|
|
78
|
+
setPost(null);
|
|
79
|
+
setError(null);
|
|
80
|
+
setIsLoading(false);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let cancelled = false;
|
|
85
|
+
const run = async () => {
|
|
86
|
+
try {
|
|
87
|
+
setIsLoading(true);
|
|
88
|
+
setError(null);
|
|
89
|
+
const res = await client.public.blogPosts.getById(id);
|
|
90
|
+
if (cancelled) return;
|
|
91
|
+
const normalized = normalizeBlogPost(res);
|
|
92
|
+
setPost(normalized);
|
|
93
|
+
if (!normalized) setError("Article introuvable");
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (cancelled) return;
|
|
96
|
+
setPost(null);
|
|
97
|
+
setError(err instanceof Error ? err.message : "Impossible de charger l'article");
|
|
98
|
+
} finally {
|
|
99
|
+
if (!cancelled) setIsLoading(false);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
void run();
|
|
103
|
+
return () => {
|
|
104
|
+
cancelled = true;
|
|
105
|
+
};
|
|
106
|
+
}, [articleId, client.public.blogPosts]);
|
|
107
|
+
|
|
108
|
+
return { post, isLoading, error };
|
|
109
|
+
}
|
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { useChallengesContext } from "../contexts/ChallengesContext";
|
|
2
|
-
|
|
3
|
-
export type Challenge = {
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
imageUrl?: string | null;
|
|
8
|
-
enabled?: boolean;
|
|
9
|
-
startDate?: string;
|
|
10
|
-
endDate?: string;
|
|
11
|
-
order?: number;
|
|
12
|
-
requiredChallengeId?: string | null;
|
|
13
|
-
requiredChallenge?: { id: string; name: string } | null;
|
|
14
|
-
series?: Array<{
|
|
15
|
-
id: string;
|
|
16
|
-
challengeId: string;
|
|
17
|
-
name: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
imageUrl?: string | null;
|
|
20
|
-
order?: number;
|
|
21
|
-
quizQuestions?: Array<{
|
|
22
|
-
id: string;
|
|
23
|
-
material?: string;
|
|
24
|
-
question?: string;
|
|
25
|
-
correctWasteTypeId?: string;
|
|
26
|
-
order?: number;
|
|
27
|
-
imageUrl?: string | null;
|
|
28
|
-
kind?: string | null;
|
|
29
|
-
options?: unknown;
|
|
30
|
-
explanationText?: string | null;
|
|
31
|
-
explanationDetailId?: string | null;
|
|
32
|
-
explanationDetail?: {
|
|
33
|
-
material?: string | null;
|
|
34
|
-
description?: string | null;
|
|
35
|
-
instructions?: string | null;
|
|
36
|
-
} | null;
|
|
37
|
-
}>;
|
|
38
|
-
}>;
|
|
39
|
-
badge?: {
|
|
40
|
-
id: string;
|
|
41
|
-
challengeId: string;
|
|
42
|
-
name: string;
|
|
43
|
-
description?: string;
|
|
44
|
-
icon?: string;
|
|
45
|
-
imageUrl?: string;
|
|
46
|
-
} | null;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export type SeriesProgress = {
|
|
50
|
-
seriesId: string;
|
|
51
|
-
score: number;
|
|
52
|
-
completedAt: string;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type ChallengeSeriesWithProgress = NonNullable<Challenge["series"]>[number] & {
|
|
56
|
-
progression?: SeriesProgress;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/** `Omit<Challenge, "series">` évite que `series` de `Challenge` écrase le type enrichi. */
|
|
60
|
-
export type ChallengeWithProgress = Omit<Challenge, "series"> & {
|
|
61
|
-
progression?: UserProgress;
|
|
62
|
-
series?: ChallengeSeriesWithProgress[];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export type UserProgress = {
|
|
66
|
-
challengeId: string;
|
|
67
|
-
challengeName?: string;
|
|
68
|
-
score?: number;
|
|
69
|
-
completedAt: string;
|
|
70
|
-
badge?: Challenge["badge"];
|
|
71
|
-
series?: SeriesProgress[];
|
|
72
|
-
[key: string]: unknown;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export type AcquiredBadge = {
|
|
76
|
-
badgeId: string;
|
|
77
|
-
challengeId: string;
|
|
78
|
-
earnedAt: string;
|
|
79
|
-
badge?: Challenge["badge"];
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export type UseChallengesOptions = {
|
|
83
|
-
/** Conservé pour compat ; le store partagé utilise LocalContext. */
|
|
84
|
-
cityId?: string | null;
|
|
85
|
-
pageSize?: number;
|
|
86
|
-
deviceId?: string | null;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export type UseChallengesResult = {
|
|
90
|
-
cityId: string | null;
|
|
91
|
-
challenges: ChallengeWithProgress[];
|
|
92
|
-
userProgress: UserProgress[];
|
|
93
|
-
/** Progression indexée par `challengeId` (pratique pour l'affichage). */
|
|
94
|
-
progressByChallengeId: Record<string, UserProgress>;
|
|
95
|
-
/** Raccourci pour récupérer la progression d'un challenge. */
|
|
96
|
-
getProgressByChallengeId: (challengeId: string) => UserProgress | undefined;
|
|
97
|
-
acquiredBadges: AcquiredBadge[];
|
|
98
|
-
isLoading: boolean;
|
|
99
|
-
error: string | null;
|
|
100
|
-
refetch: () => Promise<void>;
|
|
101
|
-
getChallengeById: (id: string) => ChallengeWithProgress | undefined;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Shared challenges store (via ChallengesProvider inside WastoProvider).
|
|
106
|
-
* Options are ignored — city/device come from LocalContext so all screens stay in sync.
|
|
107
|
-
*/
|
|
108
|
-
export function useChallenges(_options: UseChallengesOptions = {}): UseChallengesResult {
|
|
109
|
-
return useChallengesContext();
|
|
110
|
-
}
|
|
1
|
+
import { useChallengesContext } from "../contexts/ChallengesContext";
|
|
2
|
+
|
|
3
|
+
export type Challenge = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
imageUrl?: string | null;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
startDate?: string;
|
|
10
|
+
endDate?: string;
|
|
11
|
+
order?: number;
|
|
12
|
+
requiredChallengeId?: string | null;
|
|
13
|
+
requiredChallenge?: { id: string; name: string } | null;
|
|
14
|
+
series?: Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
challengeId: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
imageUrl?: string | null;
|
|
20
|
+
order?: number;
|
|
21
|
+
quizQuestions?: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
material?: string;
|
|
24
|
+
question?: string;
|
|
25
|
+
correctWasteTypeId?: string;
|
|
26
|
+
order?: number;
|
|
27
|
+
imageUrl?: string | null;
|
|
28
|
+
kind?: string | null;
|
|
29
|
+
options?: unknown;
|
|
30
|
+
explanationText?: string | null;
|
|
31
|
+
explanationDetailId?: string | null;
|
|
32
|
+
explanationDetail?: {
|
|
33
|
+
material?: string | null;
|
|
34
|
+
description?: string | null;
|
|
35
|
+
instructions?: string | null;
|
|
36
|
+
} | null;
|
|
37
|
+
}>;
|
|
38
|
+
}>;
|
|
39
|
+
badge?: {
|
|
40
|
+
id: string;
|
|
41
|
+
challengeId: string;
|
|
42
|
+
name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
icon?: string;
|
|
45
|
+
imageUrl?: string;
|
|
46
|
+
} | null;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type SeriesProgress = {
|
|
50
|
+
seriesId: string;
|
|
51
|
+
score: number;
|
|
52
|
+
completedAt: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type ChallengeSeriesWithProgress = NonNullable<Challenge["series"]>[number] & {
|
|
56
|
+
progression?: SeriesProgress;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** `Omit<Challenge, "series">` évite que `series` de `Challenge` écrase le type enrichi. */
|
|
60
|
+
export type ChallengeWithProgress = Omit<Challenge, "series"> & {
|
|
61
|
+
progression?: UserProgress;
|
|
62
|
+
series?: ChallengeSeriesWithProgress[];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type UserProgress = {
|
|
66
|
+
challengeId: string;
|
|
67
|
+
challengeName?: string;
|
|
68
|
+
score?: number;
|
|
69
|
+
completedAt: string;
|
|
70
|
+
badge?: Challenge["badge"];
|
|
71
|
+
series?: SeriesProgress[];
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type AcquiredBadge = {
|
|
76
|
+
badgeId: string;
|
|
77
|
+
challengeId: string;
|
|
78
|
+
earnedAt: string;
|
|
79
|
+
badge?: Challenge["badge"];
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type UseChallengesOptions = {
|
|
83
|
+
/** Conservé pour compat ; le store partagé utilise LocalContext. */
|
|
84
|
+
cityId?: string | null;
|
|
85
|
+
pageSize?: number;
|
|
86
|
+
deviceId?: string | null;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type UseChallengesResult = {
|
|
90
|
+
cityId: string | null;
|
|
91
|
+
challenges: ChallengeWithProgress[];
|
|
92
|
+
userProgress: UserProgress[];
|
|
93
|
+
/** Progression indexée par `challengeId` (pratique pour l'affichage). */
|
|
94
|
+
progressByChallengeId: Record<string, UserProgress>;
|
|
95
|
+
/** Raccourci pour récupérer la progression d'un challenge. */
|
|
96
|
+
getProgressByChallengeId: (challengeId: string) => UserProgress | undefined;
|
|
97
|
+
acquiredBadges: AcquiredBadge[];
|
|
98
|
+
isLoading: boolean;
|
|
99
|
+
error: string | null;
|
|
100
|
+
refetch: () => Promise<void>;
|
|
101
|
+
getChallengeById: (id: string) => ChallengeWithProgress | undefined;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Shared challenges store (via ChallengesProvider inside WastoProvider).
|
|
106
|
+
* Options are ignored — city/device come from LocalContext so all screens stay in sync.
|
|
107
|
+
*/
|
|
108
|
+
export function useChallenges(_options: UseChallengesOptions = {}): UseChallengesResult {
|
|
109
|
+
return useChallengesContext();
|
|
110
|
+
}
|
package/src/hooks/useCities.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { useWastoClient } from "./useWastoClient";
|
|
3
|
-
|
|
4
|
-
export type City = {
|
|
5
|
-
id: string;
|
|
6
|
-
name: string;
|
|
7
|
-
status?: "NON_ACTIF" | "INCOMPLET" | "ACTIF" | "MAINTENANCE";
|
|
8
|
-
[key: string]: unknown;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type UseCitiesResult = {
|
|
12
|
-
cities: City[];
|
|
13
|
-
isLoading: boolean;
|
|
14
|
-
error: string | null;
|
|
15
|
-
refetch: () => Promise<void>;
|
|
16
|
-
getCityById: (id: string) => City | undefined;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type UseCitiesOptions = {
|
|
20
|
-
pageSize?: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export function useCities(options: UseCitiesOptions = {}): UseCitiesResult {
|
|
24
|
-
const client = useWastoClient();
|
|
25
|
-
|
|
26
|
-
const [cities, setCities] = useState<City[]>([]);
|
|
27
|
-
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
28
|
-
const [error, setError] = useState<string | null>(null);
|
|
29
|
-
|
|
30
|
-
const pageSize = options.pageSize ?? 100;
|
|
31
|
-
|
|
32
|
-
const fetchCities = useCallback(async () => {
|
|
33
|
-
try {
|
|
34
|
-
setIsLoading(true);
|
|
35
|
-
setError(null);
|
|
36
|
-
const res = await client.public.cities.findAll({ pageSize });
|
|
37
|
-
const data = (res as { data?: unknown })?.data;
|
|
38
|
-
setCities(Array.isArray(data) ? (data as City[]) : []);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
const message =
|
|
41
|
-
err instanceof Error ? err.message : typeof err === "string" ? err : "Impossible de charger les villes";
|
|
42
|
-
setError(message);
|
|
43
|
-
setCities([]);
|
|
44
|
-
} finally {
|
|
45
|
-
setIsLoading(false);
|
|
46
|
-
}
|
|
47
|
-
}, [client, pageSize]);
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
void fetchCities();
|
|
51
|
-
}, [fetchCities]);
|
|
52
|
-
|
|
53
|
-
const getCityById = useCallback((id: string) => cities.find((c) => c.id === id), [cities]);
|
|
54
|
-
|
|
55
|
-
return { cities, isLoading, error, refetch: fetchCities, getCityById };
|
|
56
|
-
}
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useWastoClient } from "./useWastoClient";
|
|
3
|
+
|
|
4
|
+
export type City = {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
status?: "NON_ACTIF" | "INCOMPLET" | "ACTIF" | "MAINTENANCE";
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type UseCitiesResult = {
|
|
12
|
+
cities: City[];
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
error: string | null;
|
|
15
|
+
refetch: () => Promise<void>;
|
|
16
|
+
getCityById: (id: string) => City | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type UseCitiesOptions = {
|
|
20
|
+
pageSize?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function useCities(options: UseCitiesOptions = {}): UseCitiesResult {
|
|
24
|
+
const client = useWastoClient();
|
|
25
|
+
|
|
26
|
+
const [cities, setCities] = useState<City[]>([]);
|
|
27
|
+
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
28
|
+
const [error, setError] = useState<string | null>(null);
|
|
29
|
+
|
|
30
|
+
const pageSize = options.pageSize ?? 100;
|
|
31
|
+
|
|
32
|
+
const fetchCities = useCallback(async () => {
|
|
33
|
+
try {
|
|
34
|
+
setIsLoading(true);
|
|
35
|
+
setError(null);
|
|
36
|
+
const res = await client.public.cities.findAll({ pageSize });
|
|
37
|
+
const data = (res as { data?: unknown })?.data;
|
|
38
|
+
setCities(Array.isArray(data) ? (data as City[]) : []);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
const message =
|
|
41
|
+
err instanceof Error ? err.message : typeof err === "string" ? err : "Impossible de charger les villes";
|
|
42
|
+
setError(message);
|
|
43
|
+
setCities([]);
|
|
44
|
+
} finally {
|
|
45
|
+
setIsLoading(false);
|
|
46
|
+
}
|
|
47
|
+
}, [client, pageSize]);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
void fetchCities();
|
|
51
|
+
}, [fetchCities]);
|
|
52
|
+
|
|
53
|
+
const getCityById = useCallback((id: string) => cities.find((c) => c.id === id), [cities]);
|
|
54
|
+
|
|
55
|
+
return { cities, isLoading, error, refetch: fetchCities, getCityById };
|
|
56
|
+
}
|