@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wasto/cms-components",
3
- "version": "1.5.10",
3
+ "version": "1.5.11",
4
4
  "description": "Wast'O CMS React Native components",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -77,7 +77,7 @@
77
77
  "react-native-reanimated": "~4.1.1",
78
78
  "tsup": "^8.5.1",
79
79
  "typescript": "^6.0.2",
80
- "@wasto/sdk": "1.0.3"
80
+ "@wasto/sdk": "1.0.4"
81
81
  },
82
82
  "keywords": [],
83
83
  "author": "",
@@ -1,183 +1,183 @@
1
- import type { ReactNode } from "react";
2
- import { Modal, Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
3
- import { X } from "lucide-react-native";
4
- import { useAnnouncements } from "../../contexts/AnnouncementsContext";
5
- import { useTheme } from "../../contexts/ThemeContext";
6
- import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
7
- import { resolveTheme } from "../../helpers/themeStyles";
8
- import { getContrastColor } from "../../helpers/getContrastColor";
9
- import { Button } from "../button/Button";
10
- import { hapticLight } from "../../helpers/haptics";
11
- import { SPACE } from "../../helpers/layout";
12
-
13
- /** Oversized circle (relative to sheet width) → gentle convex arc. */
14
- const CIRCLE_WIDTH_PCT = "500%";
15
- const CIRCLE_LEFT_PCT = "-200%";
16
- /** White sheet overlaps the green header just below the title. */
17
- const CIRCLE_OVERLAP = 28;
18
-
19
- export function AnnouncementModal(): ReactNode {
20
- const { announcement, forceVisible, dismiss } = useAnnouncements();
21
- const { theme } = useTheme();
22
- const t = resolveTheme(theme);
23
- const topInset = useSafeAreaPadding(["top"]);
24
- const bottomInset = useSafeAreaPadding(["bottom"]);
25
-
26
- const visible = forceVisible && !!announcement;
27
- const contrast = getContrastColor(theme.colors.primary);
28
- const sheetColor = theme.colors.surface;
29
-
30
- const handleDismiss = async () => {
31
- await hapticLight();
32
- await dismiss();
33
- };
34
-
35
- return (
36
- <Modal visible={visible} animationType="slide" onRequestClose={handleDismiss}>
37
- <View style={[styles.root, { backgroundColor: theme.colors.primary }]}>
38
- <View
39
- style={[
40
- styles.header,
41
- {
42
- paddingTop:
43
- (typeof topInset.paddingTop === "number"
44
- ? topInset.paddingTop
45
- : 0) + SPACE.sectionY,
46
- },
47
- ]}
48
- >
49
- <View style={styles.headerTop}>
50
- <Text style={[styles.eyebrow, { color: contrast }]}>Annonce</Text>
51
- <Pressable
52
- onPress={handleDismiss}
53
- style={[styles.closeBtn, { backgroundColor: sheetColor }]}
54
- hitSlop={12}
55
- accessibilityRole="button"
56
- accessibilityLabel="Fermer"
57
- >
58
- <X size={18} color={theme.colors.primary} />
59
- </Pressable>
60
- </View>
61
- <Text style={[styles.title, { color: contrast }]}>
62
- {announcement?.title}
63
- </Text>
64
- </View>
65
-
66
- <View style={styles.sheet}>
67
- <View
68
- pointerEvents="none"
69
- style={[
70
- styles.circle,
71
- {
72
- backgroundColor: sheetColor,
73
- top: -CIRCLE_OVERLAP,
74
- },
75
- ]}
76
- />
77
- <View
78
- style={[
79
- styles.body,
80
- {
81
- paddingBottom: Math.max(
82
- SPACE.sectionY,
83
- typeof bottomInset.paddingBottom === "number"
84
- ? bottomInset.paddingBottom + SPACE.pageX
85
- : SPACE.sectionY,
86
- ),
87
- },
88
- ]}
89
- >
90
- <ScrollView
91
- style={styles.bodyScroll}
92
- contentContainerStyle={styles.bodyScrollContent}
93
- bounces={false}
94
- showsVerticalScrollIndicator={false}
95
- >
96
- <Text style={[styles.bodyText, { color: t.colors.muted }]}>
97
- {announcement?.body}
98
- </Text>
99
- </ScrollView>
100
- <Button
101
- onPress={handleDismiss}
102
- style={[styles.cta, { borderRadius: t.radii.pill }]}
103
- >
104
- C'est compris !
105
- </Button>
106
- </View>
107
- </View>
108
- </View>
109
- </Modal>
110
- );
111
- }
112
-
113
- const styles = StyleSheet.create({
114
- root: {
115
- flex: 1,
116
- height: "100%",
117
- overflow: "hidden",
118
- },
119
- header: {
120
- paddingHorizontal: SPACE.pageX + 16,
121
- paddingBottom: SPACE.sectionY,
122
- gap: SPACE.stack,
123
- },
124
- headerTop: {
125
- flexDirection: "row",
126
- alignItems: "center",
127
- justifyContent: "space-between",
128
- paddingVertical: 4,
129
- },
130
- eyebrow: {
131
- fontSize: 16,
132
- fontWeight: "700",
133
- paddingVertical: 4,
134
- },
135
- closeBtn: {
136
- width: SPACE.iconHit,
137
- height: SPACE.iconHit,
138
- borderRadius: SPACE.iconHit / 2,
139
- alignItems: "center",
140
- justifyContent: "center",
141
- },
142
- title: {
143
- fontSize: 28,
144
- fontWeight: "800",
145
- lineHeight: 34,
146
- paddingRight: SPACE.iconHit + SPACE.stack,
147
- paddingBottom: SPACE.stack,
148
- },
149
- sheet: {
150
- flex: 1,
151
- position: "relative",
152
- },
153
- circle: {
154
- position: "absolute",
155
- left: CIRCLE_LEFT_PCT,
156
- width: CIRCLE_WIDTH_PCT,
157
- aspectRatio: 1,
158
- borderRadius: 9999,
159
- },
160
- body: {
161
- flex: 1,
162
- paddingHorizontal: SPACE.pageX + 16,
163
- paddingTop: CIRCLE_OVERLAP + SPACE.sectionY,
164
- justifyContent: "space-between",
165
- gap: 24,
166
- zIndex: 1,
167
- },
168
- bodyScroll: {
169
- flexGrow: 0,
170
- flexShrink: 1,
171
- },
172
- bodyScrollContent: {
173
- paddingBottom: 8,
174
- },
175
- bodyText: {
176
- fontSize: 16,
177
- lineHeight: 24,
178
- },
179
- cta: {
180
- height: 52,
181
- alignSelf: "stretch",
182
- },
183
- });
1
+ import type { ReactNode } from "react";
2
+ import { Modal, Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
3
+ import { X } from "lucide-react-native";
4
+ import { useAnnouncements } from "../../contexts/AnnouncementsContext";
5
+ import { useTheme } from "../../contexts/ThemeContext";
6
+ import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
7
+ import { resolveTheme } from "../../helpers/themeStyles";
8
+ import { getContrastColor } from "../../helpers/getContrastColor";
9
+ import { Button } from "../button/Button";
10
+ import { hapticLight } from "../../helpers/haptics";
11
+ import { SPACE } from "../../helpers/layout";
12
+
13
+ /** Oversized circle (relative to sheet width) → gentle convex arc. */
14
+ const CIRCLE_WIDTH_PCT = "500%";
15
+ const CIRCLE_LEFT_PCT = "-200%";
16
+ /** White sheet overlaps the green header just below the title. */
17
+ const CIRCLE_OVERLAP = 28;
18
+
19
+ export function AnnouncementModal(): ReactNode {
20
+ const { announcement, forceVisible, dismiss } = useAnnouncements();
21
+ const { theme } = useTheme();
22
+ const t = resolveTheme(theme);
23
+ const topInset = useSafeAreaPadding(["top"]);
24
+ const bottomInset = useSafeAreaPadding(["bottom"]);
25
+
26
+ const visible = forceVisible && !!announcement;
27
+ const contrast = getContrastColor(theme.colors.primary);
28
+ const sheetColor = theme.colors.surface;
29
+
30
+ const handleDismiss = async () => {
31
+ await hapticLight();
32
+ await dismiss();
33
+ };
34
+
35
+ return (
36
+ <Modal visible={visible} animationType="slide" onRequestClose={handleDismiss}>
37
+ <View style={[styles.root, { backgroundColor: theme.colors.primary }]}>
38
+ <View
39
+ style={[
40
+ styles.header,
41
+ {
42
+ paddingTop:
43
+ (typeof topInset.paddingTop === "number"
44
+ ? topInset.paddingTop
45
+ : 0) + SPACE.sectionY,
46
+ },
47
+ ]}
48
+ >
49
+ <View style={styles.headerTop}>
50
+ <Text style={[styles.eyebrow, { color: contrast }]}>Annonce</Text>
51
+ <Pressable
52
+ onPress={handleDismiss}
53
+ style={[styles.closeBtn, { backgroundColor: sheetColor }]}
54
+ hitSlop={12}
55
+ accessibilityRole="button"
56
+ accessibilityLabel="Fermer"
57
+ >
58
+ <X size={18} color={theme.colors.primary} />
59
+ </Pressable>
60
+ </View>
61
+ <Text style={[styles.title, { color: contrast }]}>
62
+ {announcement?.title}
63
+ </Text>
64
+ </View>
65
+
66
+ <View style={styles.sheet}>
67
+ <View
68
+ pointerEvents="none"
69
+ style={[
70
+ styles.circle,
71
+ {
72
+ backgroundColor: sheetColor,
73
+ top: -CIRCLE_OVERLAP,
74
+ },
75
+ ]}
76
+ />
77
+ <View
78
+ style={[
79
+ styles.body,
80
+ {
81
+ paddingBottom: Math.max(
82
+ SPACE.sectionY,
83
+ typeof bottomInset.paddingBottom === "number"
84
+ ? bottomInset.paddingBottom + SPACE.pageX
85
+ : SPACE.sectionY,
86
+ ),
87
+ },
88
+ ]}
89
+ >
90
+ <ScrollView
91
+ style={styles.bodyScroll}
92
+ contentContainerStyle={styles.bodyScrollContent}
93
+ bounces={false}
94
+ showsVerticalScrollIndicator={false}
95
+ >
96
+ <Text style={[styles.bodyText, { color: t.colors.muted }]}>
97
+ {announcement?.body}
98
+ </Text>
99
+ </ScrollView>
100
+ <Button
101
+ onPress={handleDismiss}
102
+ style={[styles.cta, { borderRadius: t.radii.pill }]}
103
+ >
104
+ C'est compris !
105
+ </Button>
106
+ </View>
107
+ </View>
108
+ </View>
109
+ </Modal>
110
+ );
111
+ }
112
+
113
+ const styles = StyleSheet.create({
114
+ root: {
115
+ flex: 1,
116
+ height: "100%",
117
+ overflow: "hidden",
118
+ },
119
+ header: {
120
+ paddingHorizontal: SPACE.pageX + 16,
121
+ paddingBottom: SPACE.sectionY,
122
+ gap: SPACE.stack,
123
+ },
124
+ headerTop: {
125
+ flexDirection: "row",
126
+ alignItems: "center",
127
+ justifyContent: "space-between",
128
+ paddingVertical: 4,
129
+ },
130
+ eyebrow: {
131
+ fontSize: 16,
132
+ fontWeight: "700",
133
+ paddingVertical: 4,
134
+ },
135
+ closeBtn: {
136
+ width: SPACE.iconHit,
137
+ height: SPACE.iconHit,
138
+ borderRadius: SPACE.iconHit / 2,
139
+ alignItems: "center",
140
+ justifyContent: "center",
141
+ },
142
+ title: {
143
+ fontSize: 28,
144
+ fontWeight: "800",
145
+ lineHeight: 34,
146
+ paddingRight: SPACE.iconHit + SPACE.stack,
147
+ paddingBottom: SPACE.stack,
148
+ },
149
+ sheet: {
150
+ flex: 1,
151
+ position: "relative",
152
+ },
153
+ circle: {
154
+ position: "absolute",
155
+ left: CIRCLE_LEFT_PCT,
156
+ width: CIRCLE_WIDTH_PCT,
157
+ aspectRatio: 1,
158
+ borderRadius: 9999,
159
+ },
160
+ body: {
161
+ flex: 1,
162
+ paddingHorizontal: SPACE.pageX + 16,
163
+ paddingTop: CIRCLE_OVERLAP + SPACE.sectionY,
164
+ justifyContent: "space-between",
165
+ gap: 24,
166
+ zIndex: 1,
167
+ },
168
+ bodyScroll: {
169
+ flexGrow: 0,
170
+ flexShrink: 1,
171
+ },
172
+ bodyScrollContent: {
173
+ paddingBottom: 8,
174
+ },
175
+ bodyText: {
176
+ fontSize: 16,
177
+ lineHeight: 24,
178
+ },
179
+ cta: {
180
+ height: 52,
181
+ alignSelf: "stretch",
182
+ },
183
+ });
@@ -1,22 +1,22 @@
1
- import type { ReactNode } from "react";
2
- import { ArticleExcerpts, ArticlePropsExcerpts } from "./ArticleExcerpts";
3
- import { ArticleList, ArticlePropsList } from "./ArticleList";
4
- import { ArticlePropsSingle, ArticleSingle } from "./ArticleSingle";
5
-
6
- export type ArticleDisplayMode = "single" | "list" | "excerpts";
7
-
8
- export type ArticleProps =
9
- | ArticlePropsSingle
10
- | ArticlePropsList
11
- | ArticlePropsExcerpts
12
-
13
- export function Article(props: ArticleProps): ReactNode {
14
- switch(props.displayMode) {
15
- case "single":
16
- return <ArticleSingle {...props}/>
17
- case "list":
18
- return <ArticleList {...props}/>
19
- case "excerpts":
20
- return <ArticleExcerpts {...props}/>
21
- }
1
+ import type { ReactNode } from "react";
2
+ import { ArticleExcerpts, ArticlePropsExcerpts } from "./ArticleExcerpts";
3
+ import { ArticleList, ArticlePropsList } from "./ArticleList";
4
+ import { ArticlePropsSingle, ArticleSingle } from "./ArticleSingle";
5
+
6
+ export type ArticleDisplayMode = "single" | "list" | "excerpts";
7
+
8
+ export type ArticleProps =
9
+ | ArticlePropsSingle
10
+ | ArticlePropsList
11
+ | ArticlePropsExcerpts
12
+
13
+ export function Article(props: ArticleProps): ReactNode {
14
+ switch(props.displayMode) {
15
+ case "single":
16
+ return <ArticleSingle {...props}/>
17
+ case "list":
18
+ return <ArticleList {...props}/>
19
+ case "excerpts":
20
+ return <ArticleExcerpts {...props}/>
21
+ }
22
22
  }
@@ -1,81 +1,81 @@
1
- import type { ReactNode } from "react";
2
- import { StyleSheet, Text, View } from "react-native";
3
- import { Image } from "expo-image";
4
- import { useTheme } from "../../contexts/ThemeContext";
5
- import { Theme } from "../../types/Theme";
6
- import { Title } from "../title/Title";
7
- import { Button } from "../button/Button";
8
- import { formatArticleDate, stripToExcerpt, type BlogPost } from "../../helpers/blogPost";
9
- import { publicMediaUrl } from "../../helpers/publicMediaUrl";
10
- import { useWasto } from "../../contexts/WastoContext";
11
- import { cardStyle } from "../../helpers/themeStyles";
12
-
13
- export type ArticleCardProps = {
14
- post: BlogPost;
15
- excerptLength?: number;
16
- onRead: () => void;
17
- };
18
-
19
- export function ArticleCard({
20
- post,
21
- excerptLength = 140,
22
- onRead,
23
- }: ArticleCardProps): ReactNode {
24
- const { theme } = useTheme();
25
- const { apiUrl } = useWasto();
26
- const themedStyles = createThemedStyles(theme);
27
- const cover = publicMediaUrl(apiUrl, post.coverMediaId);
28
- const date = formatArticleDate(post.publishedAt || post.createdAt);
29
- const excerpt = stripToExcerpt(post.content, excerptLength);
30
-
31
- return (
32
- <View style={[styles.card, cardStyle(theme)]}>
33
- {cover ? (
34
- <Image source={cover} style={styles.cover} contentFit="cover" />
35
- ) : (
36
- <View style={[styles.accentBar, { backgroundColor: theme.colors.primary }]} />
37
- )}
38
- <View style={styles.body}>
39
- <Title text={post.title} level="3" />
40
- {date ? <Text style={themedStyles.meta}>{date}</Text> : null}
41
- {excerpt ? <Text style={themedStyles.excerpt}>{excerpt}</Text> : null}
42
- <Button variant="outline" onPress={onRead}>
43
- Lire l'article
44
- </Button>
45
- </View>
46
- </View>
47
- );
48
- }
49
-
50
- const createThemedStyles = (theme: Theme) =>
51
- StyleSheet.create({
52
- meta: {
53
- color: theme.colors.muted ?? theme.colors.onSurface,
54
- fontSize: 12,
55
- fontWeight: "500",
56
- },
57
- excerpt: {
58
- color: theme.colors.onSurface,
59
- opacity: 0.85,
60
- fontSize: 13,
61
- lineHeight: 18,
62
- },
63
- });
64
-
65
- const styles = StyleSheet.create({
66
- card: {
67
- overflow: "hidden",
68
- },
69
- accentBar: {
70
- height: 5,
71
- width: "100%",
72
- },
73
- cover: {
74
- width: "100%",
75
- height: 160,
76
- },
77
- body: {
78
- padding: 16,
79
- gap: 10,
80
- },
81
- });
1
+ import type { ReactNode } from "react";
2
+ import { StyleSheet, Text, View } from "react-native";
3
+ import { Image } from "expo-image";
4
+ import { useTheme } from "../../contexts/ThemeContext";
5
+ import { Theme } from "../../types/Theme";
6
+ import { Title } from "../title/Title";
7
+ import { Button } from "../button/Button";
8
+ import { formatArticleDate, stripToExcerpt, type BlogPost } from "../../helpers/blogPost";
9
+ import { publicMediaUrl } from "../../helpers/publicMediaUrl";
10
+ import { useWasto } from "../../contexts/WastoContext";
11
+ import { cardStyle } from "../../helpers/themeStyles";
12
+
13
+ export type ArticleCardProps = {
14
+ post: BlogPost;
15
+ excerptLength?: number;
16
+ onRead: () => void;
17
+ };
18
+
19
+ export function ArticleCard({
20
+ post,
21
+ excerptLength = 140,
22
+ onRead,
23
+ }: ArticleCardProps): ReactNode {
24
+ const { theme } = useTheme();
25
+ const { apiUrl } = useWasto();
26
+ const themedStyles = createThemedStyles(theme);
27
+ const cover = publicMediaUrl(apiUrl, post.coverMediaId);
28
+ const date = formatArticleDate(post.publishedAt || post.createdAt);
29
+ const excerpt = stripToExcerpt(post.content, excerptLength);
30
+
31
+ return (
32
+ <View style={[styles.card, cardStyle(theme)]}>
33
+ {cover ? (
34
+ <Image source={cover} style={styles.cover} contentFit="cover" />
35
+ ) : (
36
+ <View style={[styles.accentBar, { backgroundColor: theme.colors.primary }]} />
37
+ )}
38
+ <View style={styles.body}>
39
+ <Title text={post.title} level="3" />
40
+ {date ? <Text style={themedStyles.meta}>{date}</Text> : null}
41
+ {excerpt ? <Text style={themedStyles.excerpt}>{excerpt}</Text> : null}
42
+ <Button variant="outline" onPress={onRead}>
43
+ Lire l'article
44
+ </Button>
45
+ </View>
46
+ </View>
47
+ );
48
+ }
49
+
50
+ const createThemedStyles = (theme: Theme) =>
51
+ StyleSheet.create({
52
+ meta: {
53
+ color: theme.colors.muted ?? theme.colors.onSurface,
54
+ fontSize: 12,
55
+ fontWeight: "500",
56
+ },
57
+ excerpt: {
58
+ color: theme.colors.onSurface,
59
+ opacity: 0.85,
60
+ fontSize: 13,
61
+ lineHeight: 18,
62
+ },
63
+ });
64
+
65
+ const styles = StyleSheet.create({
66
+ card: {
67
+ overflow: "hidden",
68
+ },
69
+ accentBar: {
70
+ height: 5,
71
+ width: "100%",
72
+ },
73
+ cover: {
74
+ width: "100%",
75
+ height: 160,
76
+ },
77
+ body: {
78
+ padding: 16,
79
+ gap: 10,
80
+ },
81
+ });