@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.
- package/README.md +47 -47
- package/dist/index.d.mts +103 -2
- package/dist/index.d.ts +103 -2
- package/dist/index.js +2861 -2442
- package/dist/index.mjs +3651 -3227
- package/package.json +2 -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 +391 -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 +527 -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/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/LocalContext.tsx +227 -227
- package/src/contexts/ThemeContext.tsx +37 -37
- package/src/contexts/WastoContext.tsx +130 -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 +149 -142
- package/src/navigation/NavigationContext.tsx +56 -56
- package/src/sentry/initSentry.ts +120 -120
- package/src/types/Theme.ts +72 -72
- package/src/types/css-modules.d.ts +1 -1
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
PropsWithChildren,
|
|
4
|
-
useCallback,
|
|
5
|
-
useContext,
|
|
6
|
-
useEffect,
|
|
7
|
-
useMemo,
|
|
8
|
-
useState,
|
|
9
|
-
type ReactNode,
|
|
10
|
-
} from "react";
|
|
11
|
-
import { useLocal } from "./LocalContext";
|
|
12
|
-
import { useWastoClient } from "../hooks/useWastoClient";
|
|
13
|
-
import type {
|
|
14
|
-
AcquiredBadge,
|
|
15
|
-
Challenge,
|
|
16
|
-
ChallengeWithProgress,
|
|
17
|
-
UseChallengesResult,
|
|
18
|
-
UserProgress,
|
|
19
|
-
} from "../hooks/useChallenges";
|
|
20
|
-
|
|
21
|
-
const ChallengesContext = createContext<UseChallengesResult | undefined>(undefined);
|
|
22
|
-
|
|
23
|
-
export type ChallengesProviderProps = PropsWithChildren & {
|
|
24
|
-
pageSize?: number;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Shared challenges + progress store so Challenge, ChallengeVignette and QuizModal
|
|
29
|
-
* all see the same data after a quiz completion refetch.
|
|
30
|
-
*/
|
|
31
|
-
export function ChallengesProvider({
|
|
32
|
-
children,
|
|
33
|
-
pageSize = 100,
|
|
34
|
-
}: ChallengesProviderProps): ReactNode {
|
|
35
|
-
const { selectedCityId, deviceId } = useLocal();
|
|
36
|
-
const client = useWastoClient();
|
|
37
|
-
|
|
38
|
-
const [rawChallenges, setRawChallenges] = useState<Challenge[]>([]);
|
|
39
|
-
const [userProgress, setUserProgress] = useState<UserProgress[]>([]);
|
|
40
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
41
|
-
const [error, setError] = useState<string | null>(null);
|
|
42
|
-
|
|
43
|
-
const fetchChallenges = useCallback(async () => {
|
|
44
|
-
if (!selectedCityId) {
|
|
45
|
-
setRawChallenges([]);
|
|
46
|
-
setUserProgress([]);
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
setError(null);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
setIsLoading(true);
|
|
54
|
-
setError(null);
|
|
55
|
-
const [challengesRes, progressRes] = await Promise.all([
|
|
56
|
-
client.public.cities.getChallenges(selectedCityId, { pageSize }),
|
|
57
|
-
deviceId ? client.public.challenges.getProgress(deviceId) : Promise.resolve(null),
|
|
58
|
-
]);
|
|
59
|
-
|
|
60
|
-
const data = (challengesRes as { data?: unknown })?.data;
|
|
61
|
-
setRawChallenges(Array.isArray(data) ? (data as Challenge[]) : []);
|
|
62
|
-
|
|
63
|
-
if (deviceId) {
|
|
64
|
-
setUserProgress(Array.isArray(progressRes) ? (progressRes as UserProgress[]) : []);
|
|
65
|
-
} else {
|
|
66
|
-
setUserProgress([]);
|
|
67
|
-
}
|
|
68
|
-
} catch (err) {
|
|
69
|
-
const message =
|
|
70
|
-
err instanceof Error
|
|
71
|
-
? err.message
|
|
72
|
-
: typeof err === "string"
|
|
73
|
-
? err
|
|
74
|
-
: "Impossible de charger les challenges";
|
|
75
|
-
setError(message);
|
|
76
|
-
setRawChallenges([]);
|
|
77
|
-
setUserProgress([]);
|
|
78
|
-
} finally {
|
|
79
|
-
setIsLoading(false);
|
|
80
|
-
}
|
|
81
|
-
}, [client.public.challenges, client.public.cities, deviceId, pageSize, selectedCityId]);
|
|
82
|
-
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
void fetchChallenges();
|
|
85
|
-
}, [fetchChallenges]);
|
|
86
|
-
|
|
87
|
-
const acquiredBadges = useMemo<AcquiredBadge[]>(() => {
|
|
88
|
-
const list: AcquiredBadge[] = [];
|
|
89
|
-
for (const p of userProgress) {
|
|
90
|
-
const badge = p.badge ?? undefined;
|
|
91
|
-
const badgeId = (badge as { id?: string } | undefined)?.id;
|
|
92
|
-
if (typeof badgeId !== "string" || !badgeId.trim()) continue;
|
|
93
|
-
list.push({
|
|
94
|
-
badgeId,
|
|
95
|
-
challengeId: p.challengeId,
|
|
96
|
-
earnedAt: p.completedAt,
|
|
97
|
-
badge,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return list;
|
|
101
|
-
}, [userProgress]);
|
|
102
|
-
|
|
103
|
-
const progressByChallengeId = useMemo<Record<string, UserProgress>>(() => {
|
|
104
|
-
const map: Record<string, UserProgress> = {};
|
|
105
|
-
for (const p of userProgress) {
|
|
106
|
-
if (p?.challengeId) {
|
|
107
|
-
map[p.challengeId] = p;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return map;
|
|
111
|
-
}, [userProgress]);
|
|
112
|
-
|
|
113
|
-
const getProgressByChallengeId = useCallback(
|
|
114
|
-
(challengeId: string) => progressByChallengeId[challengeId],
|
|
115
|
-
[progressByChallengeId],
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const challenges = useMemo<ChallengeWithProgress[]>(() => {
|
|
119
|
-
return rawChallenges.map((c) => {
|
|
120
|
-
const progression = progressByChallengeId[c.id];
|
|
121
|
-
const seriesProgress = Array.isArray(progression?.series)
|
|
122
|
-
? progression.series
|
|
123
|
-
: [];
|
|
124
|
-
const seriesById = new Map(
|
|
125
|
-
seriesProgress.map((s) => [s.seriesId, s]),
|
|
126
|
-
);
|
|
127
|
-
const series = c.series?.map((s) => ({
|
|
128
|
-
...s,
|
|
129
|
-
progression: seriesById.get(s.id),
|
|
130
|
-
}));
|
|
131
|
-
return {
|
|
132
|
-
...c,
|
|
133
|
-
progression,
|
|
134
|
-
series,
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
}, [progressByChallengeId, rawChallenges]);
|
|
138
|
-
|
|
139
|
-
const getChallengeById = useCallback(
|
|
140
|
-
(id: string) => challenges.find((c) => c.id === id),
|
|
141
|
-
[challenges],
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const value = useMemo<UseChallengesResult>(
|
|
145
|
-
() => ({
|
|
146
|
-
cityId: selectedCityId,
|
|
147
|
-
challenges,
|
|
148
|
-
userProgress,
|
|
149
|
-
progressByChallengeId,
|
|
150
|
-
getProgressByChallengeId,
|
|
151
|
-
acquiredBadges,
|
|
152
|
-
isLoading,
|
|
153
|
-
error,
|
|
154
|
-
refetch: fetchChallenges,
|
|
155
|
-
getChallengeById,
|
|
156
|
-
}),
|
|
157
|
-
[
|
|
158
|
-
acquiredBadges,
|
|
159
|
-
challenges,
|
|
160
|
-
error,
|
|
161
|
-
fetchChallenges,
|
|
162
|
-
getChallengeById,
|
|
163
|
-
getProgressByChallengeId,
|
|
164
|
-
isLoading,
|
|
165
|
-
progressByChallengeId,
|
|
166
|
-
selectedCityId,
|
|
167
|
-
userProgress,
|
|
168
|
-
],
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
return (
|
|
172
|
-
<ChallengesContext.Provider value={value}>{children}</ChallengesContext.Provider>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function useChallengesContext(): UseChallengesResult {
|
|
177
|
-
const context = useContext(ChallengesContext);
|
|
178
|
-
if (!context) {
|
|
179
|
-
throw new Error("useChallenges must be used within a ChallengesProvider.");
|
|
180
|
-
}
|
|
181
|
-
return context;
|
|
182
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
PropsWithChildren,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useState,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { useLocal } from "./LocalContext";
|
|
12
|
+
import { useWastoClient } from "../hooks/useWastoClient";
|
|
13
|
+
import type {
|
|
14
|
+
AcquiredBadge,
|
|
15
|
+
Challenge,
|
|
16
|
+
ChallengeWithProgress,
|
|
17
|
+
UseChallengesResult,
|
|
18
|
+
UserProgress,
|
|
19
|
+
} from "../hooks/useChallenges";
|
|
20
|
+
|
|
21
|
+
const ChallengesContext = createContext<UseChallengesResult | undefined>(undefined);
|
|
22
|
+
|
|
23
|
+
export type ChallengesProviderProps = PropsWithChildren & {
|
|
24
|
+
pageSize?: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Shared challenges + progress store so Challenge, ChallengeVignette and QuizModal
|
|
29
|
+
* all see the same data after a quiz completion refetch.
|
|
30
|
+
*/
|
|
31
|
+
export function ChallengesProvider({
|
|
32
|
+
children,
|
|
33
|
+
pageSize = 100,
|
|
34
|
+
}: ChallengesProviderProps): ReactNode {
|
|
35
|
+
const { selectedCityId, deviceId } = useLocal();
|
|
36
|
+
const client = useWastoClient();
|
|
37
|
+
|
|
38
|
+
const [rawChallenges, setRawChallenges] = useState<Challenge[]>([]);
|
|
39
|
+
const [userProgress, setUserProgress] = useState<UserProgress[]>([]);
|
|
40
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
41
|
+
const [error, setError] = useState<string | null>(null);
|
|
42
|
+
|
|
43
|
+
const fetchChallenges = useCallback(async () => {
|
|
44
|
+
if (!selectedCityId) {
|
|
45
|
+
setRawChallenges([]);
|
|
46
|
+
setUserProgress([]);
|
|
47
|
+
setIsLoading(false);
|
|
48
|
+
setError(null);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
setIsLoading(true);
|
|
54
|
+
setError(null);
|
|
55
|
+
const [challengesRes, progressRes] = await Promise.all([
|
|
56
|
+
client.public.cities.getChallenges(selectedCityId, { pageSize }),
|
|
57
|
+
deviceId ? client.public.challenges.getProgress(deviceId) : Promise.resolve(null),
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const data = (challengesRes as { data?: unknown })?.data;
|
|
61
|
+
setRawChallenges(Array.isArray(data) ? (data as Challenge[]) : []);
|
|
62
|
+
|
|
63
|
+
if (deviceId) {
|
|
64
|
+
setUserProgress(Array.isArray(progressRes) ? (progressRes as UserProgress[]) : []);
|
|
65
|
+
} else {
|
|
66
|
+
setUserProgress([]);
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
const message =
|
|
70
|
+
err instanceof Error
|
|
71
|
+
? err.message
|
|
72
|
+
: typeof err === "string"
|
|
73
|
+
? err
|
|
74
|
+
: "Impossible de charger les challenges";
|
|
75
|
+
setError(message);
|
|
76
|
+
setRawChallenges([]);
|
|
77
|
+
setUserProgress([]);
|
|
78
|
+
} finally {
|
|
79
|
+
setIsLoading(false);
|
|
80
|
+
}
|
|
81
|
+
}, [client.public.challenges, client.public.cities, deviceId, pageSize, selectedCityId]);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
void fetchChallenges();
|
|
85
|
+
}, [fetchChallenges]);
|
|
86
|
+
|
|
87
|
+
const acquiredBadges = useMemo<AcquiredBadge[]>(() => {
|
|
88
|
+
const list: AcquiredBadge[] = [];
|
|
89
|
+
for (const p of userProgress) {
|
|
90
|
+
const badge = p.badge ?? undefined;
|
|
91
|
+
const badgeId = (badge as { id?: string } | undefined)?.id;
|
|
92
|
+
if (typeof badgeId !== "string" || !badgeId.trim()) continue;
|
|
93
|
+
list.push({
|
|
94
|
+
badgeId,
|
|
95
|
+
challengeId: p.challengeId,
|
|
96
|
+
earnedAt: p.completedAt,
|
|
97
|
+
badge,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return list;
|
|
101
|
+
}, [userProgress]);
|
|
102
|
+
|
|
103
|
+
const progressByChallengeId = useMemo<Record<string, UserProgress>>(() => {
|
|
104
|
+
const map: Record<string, UserProgress> = {};
|
|
105
|
+
for (const p of userProgress) {
|
|
106
|
+
if (p?.challengeId) {
|
|
107
|
+
map[p.challengeId] = p;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return map;
|
|
111
|
+
}, [userProgress]);
|
|
112
|
+
|
|
113
|
+
const getProgressByChallengeId = useCallback(
|
|
114
|
+
(challengeId: string) => progressByChallengeId[challengeId],
|
|
115
|
+
[progressByChallengeId],
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const challenges = useMemo<ChallengeWithProgress[]>(() => {
|
|
119
|
+
return rawChallenges.map((c) => {
|
|
120
|
+
const progression = progressByChallengeId[c.id];
|
|
121
|
+
const seriesProgress = Array.isArray(progression?.series)
|
|
122
|
+
? progression.series
|
|
123
|
+
: [];
|
|
124
|
+
const seriesById = new Map(
|
|
125
|
+
seriesProgress.map((s) => [s.seriesId, s]),
|
|
126
|
+
);
|
|
127
|
+
const series = c.series?.map((s) => ({
|
|
128
|
+
...s,
|
|
129
|
+
progression: seriesById.get(s.id),
|
|
130
|
+
}));
|
|
131
|
+
return {
|
|
132
|
+
...c,
|
|
133
|
+
progression,
|
|
134
|
+
series,
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}, [progressByChallengeId, rawChallenges]);
|
|
138
|
+
|
|
139
|
+
const getChallengeById = useCallback(
|
|
140
|
+
(id: string) => challenges.find((c) => c.id === id),
|
|
141
|
+
[challenges],
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const value = useMemo<UseChallengesResult>(
|
|
145
|
+
() => ({
|
|
146
|
+
cityId: selectedCityId,
|
|
147
|
+
challenges,
|
|
148
|
+
userProgress,
|
|
149
|
+
progressByChallengeId,
|
|
150
|
+
getProgressByChallengeId,
|
|
151
|
+
acquiredBadges,
|
|
152
|
+
isLoading,
|
|
153
|
+
error,
|
|
154
|
+
refetch: fetchChallenges,
|
|
155
|
+
getChallengeById,
|
|
156
|
+
}),
|
|
157
|
+
[
|
|
158
|
+
acquiredBadges,
|
|
159
|
+
challenges,
|
|
160
|
+
error,
|
|
161
|
+
fetchChallenges,
|
|
162
|
+
getChallengeById,
|
|
163
|
+
getProgressByChallengeId,
|
|
164
|
+
isLoading,
|
|
165
|
+
progressByChallengeId,
|
|
166
|
+
selectedCityId,
|
|
167
|
+
userProgress,
|
|
168
|
+
],
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<ChallengesContext.Provider value={value}>{children}</ChallengesContext.Provider>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function useChallengesContext(): UseChallengesResult {
|
|
177
|
+
const context = useContext(ChallengesContext);
|
|
178
|
+
if (!context) {
|
|
179
|
+
throw new Error("useChallenges must be used within a ChallengesProvider.");
|
|
180
|
+
}
|
|
181
|
+
return context;
|
|
182
|
+
}
|