@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,243 +1,243 @@
1
- import { Dimensions, Modal, Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
2
- import { ChallengeWithProgress } from "../../hooks/useChallenges";
3
- import { Theme } from "../../types/Theme";
4
- import { useTheme } from "../../contexts/ThemeContext";
5
- import { Title } from "../title/Title";
6
- import { NavButton } from "../nav-button/NavButton";
7
- import { Play, Trophy, XIcon } from "lucide-react-native";
8
- import { useEffect, useState, type ReactNode } from "react";
9
- import { ChallengeModal } from "./ChallengeModal";
10
- import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
11
- import { resolveTheme } from "../../helpers/themeStyles";
12
- import { SPACE } from "../../helpers/layout";
13
-
14
- export type ChallengesModalProps = {
15
- visible: boolean;
16
- challenges: ChallengeWithProgress[];
17
- onClose: () => void;
18
- };
19
-
20
- function isChallengeComplete(c: ChallengeWithProgress) {
21
- return !!c.progression?.badge;
22
- }
23
-
24
- function progressLabel(c: ChallengeWithProgress) {
25
- const series = c.series ?? [];
26
- if (series.length === 0) return isChallengeComplete(c) ? "1/1" : "0/1";
27
- const done = series.filter((s) => s.progression).length;
28
- return `${done}/${series.length}`;
29
- }
30
-
31
- function progressRatio(c: ChallengeWithProgress) {
32
- const series = c.series ?? [];
33
- if (series.length === 0) return isChallengeComplete(c) ? 1 : 0;
34
- return series.filter((s) => s.progression).length / series.length;
35
- }
36
-
37
- export function ChallengesModal({
38
- visible,
39
- challenges,
40
- onClose,
41
- }: ChallengesModalProps): ReactNode {
42
- const { theme } = useTheme();
43
- const t = resolveTheme(theme);
44
- const themedStyles = createThemedStyles(theme);
45
- const topInset = useSafeAreaPadding(["top"]);
46
- const bottomInset = useSafeAreaPadding(["bottom"]);
47
- const [selectedChallengeId, setSelectedChallengeId] = useState<string | null>(null);
48
-
49
- const selectedChallenge =
50
- selectedChallengeId != null
51
- ? (challenges.find((c) => c.id === selectedChallengeId) ?? null)
52
- : null;
53
-
54
- useEffect(() => {
55
- if (!visible) setSelectedChallengeId(null);
56
- }, [visible]);
57
-
58
- const handleSelectChallenge = (challenge: ChallengeWithProgress) => () => {
59
- setSelectedChallengeId(challenge.id);
60
- };
61
-
62
- return <>
63
- <Modal
64
- visible={visible}
65
- animationType="slide"
66
- onRequestClose={onClose}
67
- >
68
- {!selectedChallenge ? (
69
-
70
- <View style={[styles.modal, themedStyles.modal]}>
71
- <View style={topInset}>
72
- <View style={styles.header}>
73
- <Title
74
- text="Challenges"
75
- level="2"
76
- />
77
- <NavButton
78
- icon={XIcon}
79
- onPress={onClose}
80
- />
81
- </View>
82
- </View>
83
- <View style={[styles.listWrap, bottomInset]}>
84
- <ScrollView bounces={false} contentContainerStyle={styles.body}>
85
- {challenges.map((challenge) => {
86
- const done = isChallengeComplete(challenge);
87
- const ratio = progressRatio(challenge);
88
- return (
89
- <Pressable
90
- key={challenge.id}
91
- style={themedStyles.challenge}
92
- onPress={handleSelectChallenge(challenge)}
93
- >
94
- <View style={styles.challengeRow}>
95
- <View style={styles.challengeMain}>
96
- <Title text={challenge.name} level="3" />
97
- {challenge.description ? (
98
- <Text numberOfLines={1}>
99
- {challenge.description}
100
- </Text>
101
- ) : null}
102
- <View
103
- style={[
104
- styles.track,
105
- {
106
- backgroundColor: theme.colors.border,
107
- borderRadius: t.radii.pill,
108
- },
109
- ]}
110
- >
111
- <View
112
- style={[
113
- styles.fill,
114
- {
115
- width: `${Math.round(ratio * 100)}%`,
116
- backgroundColor: done
117
- ? theme.colors.success
118
- : theme.colors.primary,
119
- borderRadius: t.radii.pill,
120
- },
121
- ]}
122
- >
123
- <Text
124
- style={[
125
- styles.fillLabel,
126
- {
127
- color: done
128
- ? theme.colors.onSuccess
129
- : theme.colors.onPrimary,
130
- },
131
- ]}
132
- >
133
- {progressLabel(challenge)}
134
- </Text>
135
- </View>
136
- </View>
137
- </View>
138
- <View
139
- style={[
140
- styles.actionBtn,
141
- {
142
- backgroundColor: done
143
- ? theme.colors.success
144
- : theme.colors.primary,
145
- borderRadius: t.radii.pill,
146
- },
147
- ]}
148
- >
149
- {done ? (
150
- <Trophy
151
- size={18}
152
- color={theme.colors.onSuccess}
153
- />
154
- ) : (
155
- <Play
156
- size={18}
157
- color={theme.colors.onPrimary}
158
- fill={theme.colors.onPrimary}
159
- />
160
- )}
161
- </View>
162
- </View>
163
- </Pressable>
164
- );
165
- })}
166
- </ScrollView>
167
- </View>
168
- </View>
169
- ) : (
170
- <ChallengeModal
171
- challenge={selectedChallenge!}
172
- onClose={() => setSelectedChallengeId(null)}
173
- />
174
- )}
175
- </Modal>
176
- </>
177
- }
178
-
179
- const createThemedStyles = (theme: Theme) => StyleSheet.create({
180
- modal: {
181
- backgroundColor: theme.colors.background,
182
- },
183
- challenge: {
184
- backgroundColor: theme.colors.surface,
185
- borderRadius: theme.radii?.lg ?? theme.radius,
186
- ...(theme.shadow?.soft ?? {}),
187
- paddingHorizontal: SPACE.cardPad,
188
- },
189
- });
190
-
191
- const styles = StyleSheet.create({
192
- modal: {
193
- height: Dimensions.get("screen").height,
194
- },
195
- header: {
196
- paddingHorizontal: 16,
197
- paddingVertical: 16,
198
- width: "100%",
199
- flexDirection: "row",
200
- justifyContent: "space-between",
201
- alignItems: "center",
202
- },
203
- listWrap: {
204
- flex: 1,
205
- },
206
- body: {
207
- padding: 16,
208
- gap: 12,
209
- flexGrow: 1,
210
- },
211
- challengeRow: {
212
- flexDirection: "row",
213
- alignItems: "center",
214
- gap: 16,
215
- paddingVertical: 14,
216
- },
217
- challengeMain: {
218
- flex: 1,
219
- gap: 12,
220
- },
221
- track: {
222
- height: 16,
223
- overflow: "hidden",
224
- justifyContent: "center",
225
- },
226
- fill: {
227
- height: "100%",
228
- minWidth: 40,
229
- justifyContent: "center",
230
- paddingHorizontal: 8,
231
- },
232
- fillLabel: {
233
- fontSize: 11,
234
- fontWeight: "700",
235
- textAlign: "center",
236
- },
237
- actionBtn: {
238
- width: SPACE.iconHit,
239
- height: SPACE.iconHit,
240
- alignItems: "center",
241
- justifyContent: "center",
242
- },
243
- });
1
+ import { Dimensions, Modal, Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
2
+ import { ChallengeWithProgress } from "../../hooks/useChallenges";
3
+ import { Theme } from "../../types/Theme";
4
+ import { useTheme } from "../../contexts/ThemeContext";
5
+ import { Title } from "../title/Title";
6
+ import { NavButton } from "../nav-button/NavButton";
7
+ import { Play, Trophy, XIcon } from "lucide-react-native";
8
+ import { useEffect, useState, type ReactNode } from "react";
9
+ import { ChallengeModal } from "./ChallengeModal";
10
+ import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
11
+ import { resolveTheme } from "../../helpers/themeStyles";
12
+ import { SPACE } from "../../helpers/layout";
13
+
14
+ export type ChallengesModalProps = {
15
+ visible: boolean;
16
+ challenges: ChallengeWithProgress[];
17
+ onClose: () => void;
18
+ };
19
+
20
+ function isChallengeComplete(c: ChallengeWithProgress) {
21
+ return !!c.progression?.badge;
22
+ }
23
+
24
+ function progressLabel(c: ChallengeWithProgress) {
25
+ const series = c.series ?? [];
26
+ if (series.length === 0) return isChallengeComplete(c) ? "1/1" : "0/1";
27
+ const done = series.filter((s) => s.progression).length;
28
+ return `${done}/${series.length}`;
29
+ }
30
+
31
+ function progressRatio(c: ChallengeWithProgress) {
32
+ const series = c.series ?? [];
33
+ if (series.length === 0) return isChallengeComplete(c) ? 1 : 0;
34
+ return series.filter((s) => s.progression).length / series.length;
35
+ }
36
+
37
+ export function ChallengesModal({
38
+ visible,
39
+ challenges,
40
+ onClose,
41
+ }: ChallengesModalProps): ReactNode {
42
+ const { theme } = useTheme();
43
+ const t = resolveTheme(theme);
44
+ const themedStyles = createThemedStyles(theme);
45
+ const topInset = useSafeAreaPadding(["top"]);
46
+ const bottomInset = useSafeAreaPadding(["bottom"]);
47
+ const [selectedChallengeId, setSelectedChallengeId] = useState<string | null>(null);
48
+
49
+ const selectedChallenge =
50
+ selectedChallengeId != null
51
+ ? (challenges.find((c) => c.id === selectedChallengeId) ?? null)
52
+ : null;
53
+
54
+ useEffect(() => {
55
+ if (!visible) setSelectedChallengeId(null);
56
+ }, [visible]);
57
+
58
+ const handleSelectChallenge = (challenge: ChallengeWithProgress) => () => {
59
+ setSelectedChallengeId(challenge.id);
60
+ };
61
+
62
+ return <>
63
+ <Modal
64
+ visible={visible}
65
+ animationType="slide"
66
+ onRequestClose={onClose}
67
+ >
68
+ {!selectedChallenge ? (
69
+
70
+ <View style={[styles.modal, themedStyles.modal]}>
71
+ <View style={topInset}>
72
+ <View style={styles.header}>
73
+ <Title
74
+ text="Challenges"
75
+ level="2"
76
+ />
77
+ <NavButton
78
+ icon={XIcon}
79
+ onPress={onClose}
80
+ />
81
+ </View>
82
+ </View>
83
+ <View style={[styles.listWrap, bottomInset]}>
84
+ <ScrollView bounces={false} contentContainerStyle={styles.body}>
85
+ {challenges.map((challenge) => {
86
+ const done = isChallengeComplete(challenge);
87
+ const ratio = progressRatio(challenge);
88
+ return (
89
+ <Pressable
90
+ key={challenge.id}
91
+ style={themedStyles.challenge}
92
+ onPress={handleSelectChallenge(challenge)}
93
+ >
94
+ <View style={styles.challengeRow}>
95
+ <View style={styles.challengeMain}>
96
+ <Title text={challenge.name} level="3" />
97
+ {challenge.description ? (
98
+ <Text numberOfLines={1}>
99
+ {challenge.description}
100
+ </Text>
101
+ ) : null}
102
+ <View
103
+ style={[
104
+ styles.track,
105
+ {
106
+ backgroundColor: theme.colors.border,
107
+ borderRadius: t.radii.pill,
108
+ },
109
+ ]}
110
+ >
111
+ <View
112
+ style={[
113
+ styles.fill,
114
+ {
115
+ width: `${Math.round(ratio * 100)}%`,
116
+ backgroundColor: done
117
+ ? theme.colors.success
118
+ : theme.colors.primary,
119
+ borderRadius: t.radii.pill,
120
+ },
121
+ ]}
122
+ >
123
+ <Text
124
+ style={[
125
+ styles.fillLabel,
126
+ {
127
+ color: done
128
+ ? theme.colors.onSuccess
129
+ : theme.colors.onPrimary,
130
+ },
131
+ ]}
132
+ >
133
+ {progressLabel(challenge)}
134
+ </Text>
135
+ </View>
136
+ </View>
137
+ </View>
138
+ <View
139
+ style={[
140
+ styles.actionBtn,
141
+ {
142
+ backgroundColor: done
143
+ ? theme.colors.success
144
+ : theme.colors.primary,
145
+ borderRadius: t.radii.pill,
146
+ },
147
+ ]}
148
+ >
149
+ {done ? (
150
+ <Trophy
151
+ size={18}
152
+ color={theme.colors.onSuccess}
153
+ />
154
+ ) : (
155
+ <Play
156
+ size={18}
157
+ color={theme.colors.onPrimary}
158
+ fill={theme.colors.onPrimary}
159
+ />
160
+ )}
161
+ </View>
162
+ </View>
163
+ </Pressable>
164
+ );
165
+ })}
166
+ </ScrollView>
167
+ </View>
168
+ </View>
169
+ ) : (
170
+ <ChallengeModal
171
+ challenge={selectedChallenge!}
172
+ onClose={() => setSelectedChallengeId(null)}
173
+ />
174
+ )}
175
+ </Modal>
176
+ </>
177
+ }
178
+
179
+ const createThemedStyles = (theme: Theme) => StyleSheet.create({
180
+ modal: {
181
+ backgroundColor: theme.colors.background,
182
+ },
183
+ challenge: {
184
+ backgroundColor: theme.colors.surface,
185
+ borderRadius: theme.radii?.lg ?? theme.radius,
186
+ ...(theme.shadow?.soft ?? {}),
187
+ paddingHorizontal: SPACE.cardPad,
188
+ },
189
+ });
190
+
191
+ const styles = StyleSheet.create({
192
+ modal: {
193
+ height: Dimensions.get("screen").height,
194
+ },
195
+ header: {
196
+ paddingHorizontal: 16,
197
+ paddingVertical: 16,
198
+ width: "100%",
199
+ flexDirection: "row",
200
+ justifyContent: "space-between",
201
+ alignItems: "center",
202
+ },
203
+ listWrap: {
204
+ flex: 1,
205
+ },
206
+ body: {
207
+ padding: 16,
208
+ gap: 12,
209
+ flexGrow: 1,
210
+ },
211
+ challengeRow: {
212
+ flexDirection: "row",
213
+ alignItems: "center",
214
+ gap: 16,
215
+ paddingVertical: 14,
216
+ },
217
+ challengeMain: {
218
+ flex: 1,
219
+ gap: 12,
220
+ },
221
+ track: {
222
+ height: 16,
223
+ overflow: "hidden",
224
+ justifyContent: "center",
225
+ },
226
+ fill: {
227
+ height: "100%",
228
+ minWidth: 40,
229
+ justifyContent: "center",
230
+ paddingHorizontal: 8,
231
+ },
232
+ fillLabel: {
233
+ fontSize: 11,
234
+ fontWeight: "700",
235
+ textAlign: "center",
236
+ },
237
+ actionBtn: {
238
+ width: SPACE.iconHit,
239
+ height: SPACE.iconHit,
240
+ alignItems: "center",
241
+ justifyContent: "center",
242
+ },
243
+ });