@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
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.12",
4
4
  "description": "Wast'O CMS React Native components",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -30,10 +30,12 @@
30
30
  "@react-navigation/bottom-tabs": "*",
31
31
  "@sentry/react-native": "*",
32
32
  "@wasto/sdk": "*",
33
+ "expo-constants": "*",
33
34
  "expo-haptics": "*",
34
35
  "expo-image": "*",
35
36
  "expo-image-picker": "*",
36
37
  "expo-linear-gradient": "*",
38
+ "expo-notifications": "*",
37
39
  "expo-router": "*",
38
40
  "lucide-react-native": "*",
39
41
  "maplibre-gl": "*",
@@ -51,12 +53,18 @@
51
53
  "@sentry/react-native": {
52
54
  "optional": true
53
55
  },
56
+ "expo-constants": {
57
+ "optional": true
58
+ },
54
59
  "expo-image-picker": {
55
60
  "optional": true
56
61
  },
57
62
  "expo-linear-gradient": {
58
63
  "optional": true
59
64
  },
65
+ "expo-notifications": {
66
+ "optional": true
67
+ },
60
68
  "expo-router": {
61
69
  "optional": true
62
70
  },
@@ -69,15 +77,17 @@
69
77
  "@react-navigation/bottom-tabs": "^7.4.0",
70
78
  "@sentry/react-native": "~6.22.0",
71
79
  "@types/react": "~19.2.2",
80
+ "expo-constants": "~18.0.9",
72
81
  "expo-haptics": "~15.0.7",
73
82
  "expo-linear-gradient": "~15.0.8",
83
+ "expo-notifications": "~0.32.17",
74
84
  "maplibre-gl": "^4.7.0",
75
85
  "react-native-gesture-handler": "~2.28.0",
76
86
  "react-native-markdown-display": "^7.0.2",
77
87
  "react-native-reanimated": "~4.1.1",
78
88
  "tsup": "^8.5.1",
79
89
  "typescript": "^6.0.2",
80
- "@wasto/sdk": "1.0.3"
90
+ "@wasto/sdk": "1.0.4"
81
91
  },
82
92
  "keywords": [],
83
93
  "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
+ });