@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,320 +1,320 @@
|
|
|
1
|
-
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
2
|
-
import { Pressable, StyleSheet, Text, TextInput, View } from "react-native";
|
|
3
|
-
import { ChevronRight, Search as SearchIcon } from "lucide-react-native";
|
|
4
|
-
import { useTheme } from "../../contexts/ThemeContext";
|
|
5
|
-
import { Theme } from "../../types/Theme";
|
|
6
|
-
import { useRecyclingInfo } from "../../hooks/useRecyclingInfo";
|
|
7
|
-
import { useBlogPosts } from "../../hooks/useBlogPosts";
|
|
8
|
-
import { useLocations, LOCATION_CATEGORY_META } from "../../hooks/useLocations";
|
|
9
|
-
import { ConsignesModal } from "../consignes-modal/ConsignesModal";
|
|
10
|
-
import { ArticleReaderModal } from "../article/ArticleReaderModal";
|
|
11
|
-
import type { BlogPost } from "../../helpers/blogPost";
|
|
12
|
-
import { groupedSectionStyle, resolveTheme } from "../../helpers/themeStyles";
|
|
13
|
-
|
|
14
|
-
export type SearchType = "all" | "waste-type" | "collection-points" | "articles";
|
|
15
|
-
|
|
16
|
-
export type SearchProps = {
|
|
17
|
-
searchType: SearchType;
|
|
18
|
-
placeholder?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function matchesQuery(haystack: string | undefined, query: string): boolean {
|
|
22
|
-
if (!haystack) return false;
|
|
23
|
-
return haystack.toLowerCase().includes(query);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type ResultRowProps = {
|
|
27
|
-
title: string;
|
|
28
|
-
meta?: string;
|
|
29
|
-
accent: string;
|
|
30
|
-
onPress?: () => void;
|
|
31
|
-
showDivider: boolean;
|
|
32
|
-
dividerInset: number;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function ResultRow({
|
|
36
|
-
title,
|
|
37
|
-
meta,
|
|
38
|
-
accent,
|
|
39
|
-
onPress,
|
|
40
|
-
showDivider,
|
|
41
|
-
dividerInset,
|
|
42
|
-
}: ResultRowProps) {
|
|
43
|
-
const { theme } = useTheme();
|
|
44
|
-
const t = resolveTheme(theme);
|
|
45
|
-
const content = (
|
|
46
|
-
<>
|
|
47
|
-
<View style={styles.rowInner}>
|
|
48
|
-
<View style={[styles.dot, { backgroundColor: accent }]} />
|
|
49
|
-
<View style={styles.rowText}>
|
|
50
|
-
<Text style={[styles.rowTitle, { color: theme.colors.onSurface }]}>
|
|
51
|
-
{title}
|
|
52
|
-
</Text>
|
|
53
|
-
{meta ? (
|
|
54
|
-
<Text style={[styles.rowMeta, { color: t.colors.muted }]} numberOfLines={2}>
|
|
55
|
-
{meta}
|
|
56
|
-
</Text>
|
|
57
|
-
) : null}
|
|
58
|
-
</View>
|
|
59
|
-
{onPress ? (
|
|
60
|
-
<ChevronRight size={18} color={t.colors.muted} />
|
|
61
|
-
) : null}
|
|
62
|
-
</View>
|
|
63
|
-
{showDivider ? (
|
|
64
|
-
<View
|
|
65
|
-
style={[
|
|
66
|
-
styles.rowDivider,
|
|
67
|
-
{
|
|
68
|
-
backgroundColor: theme.colors.border,
|
|
69
|
-
marginLeft: dividerInset,
|
|
70
|
-
},
|
|
71
|
-
]}
|
|
72
|
-
/>
|
|
73
|
-
) : null}
|
|
74
|
-
</>
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
if (onPress) {
|
|
78
|
-
return (
|
|
79
|
-
<Pressable onPress={onPress} style={({ pressed }) => pressed && styles.pressed}>
|
|
80
|
-
{content}
|
|
81
|
-
</Pressable>
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return <View>{content}</View>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function ResultSection({
|
|
88
|
-
label,
|
|
89
|
-
children,
|
|
90
|
-
}: {
|
|
91
|
-
label?: string;
|
|
92
|
-
children: ReactNode;
|
|
93
|
-
}) {
|
|
94
|
-
const { theme } = useTheme();
|
|
95
|
-
const t = resolveTheme(theme);
|
|
96
|
-
return (
|
|
97
|
-
<View style={styles.section}>
|
|
98
|
-
{label ? (
|
|
99
|
-
<Text style={[styles.sectionLabel, { color: t.colors.muted }]}>{label}</Text>
|
|
100
|
-
) : null}
|
|
101
|
-
<View style={groupedSectionStyle(theme)}>{children}</View>
|
|
102
|
-
</View>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function Search({
|
|
107
|
-
searchType,
|
|
108
|
-
placeholder,
|
|
109
|
-
}: SearchProps): ReactNode {
|
|
110
|
-
const { theme } = useTheme();
|
|
111
|
-
const t = resolveTheme(theme);
|
|
112
|
-
const themedStyles = createThemedStyles(theme);
|
|
113
|
-
const { recyclingInfos } = useRecyclingInfo();
|
|
114
|
-
const { posts } = useBlogPosts();
|
|
115
|
-
const { locations } = useLocations();
|
|
116
|
-
|
|
117
|
-
const [draft, setDraft] = useState("");
|
|
118
|
-
const [query, setQuery] = useState("");
|
|
119
|
-
const [wasteTypeId, setWasteTypeId] = useState<string | null>(null);
|
|
120
|
-
const [article, setArticle] = useState<BlogPost | null>(null);
|
|
121
|
-
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
const handle = setTimeout(() => setQuery(draft.trim().toLowerCase()), 250);
|
|
124
|
-
return () => clearTimeout(handle);
|
|
125
|
-
}, [draft]);
|
|
126
|
-
|
|
127
|
-
const wasteResults = useMemo(() => {
|
|
128
|
-
if (!query || (searchType !== "all" && searchType !== "waste-type")) return [];
|
|
129
|
-
return recyclingInfos.filter(
|
|
130
|
-
(info) => matchesQuery(info.name, query) || matchesQuery(info.description, query)
|
|
131
|
-
);
|
|
132
|
-
}, [query, recyclingInfos, searchType]);
|
|
133
|
-
|
|
134
|
-
const locationResults = useMemo(() => {
|
|
135
|
-
if (!query || (searchType !== "all" && searchType !== "collection-points")) return [];
|
|
136
|
-
return locations.filter(
|
|
137
|
-
(loc) => matchesQuery(loc.name, query) || matchesQuery(loc.address, query)
|
|
138
|
-
);
|
|
139
|
-
}, [locations, query, searchType]);
|
|
140
|
-
|
|
141
|
-
const articleResults = useMemo(() => {
|
|
142
|
-
if (!query || (searchType !== "all" && searchType !== "articles")) return [];
|
|
143
|
-
return posts.filter(
|
|
144
|
-
(post) => matchesQuery(post.title, query) || matchesQuery(post.content, query)
|
|
145
|
-
);
|
|
146
|
-
}, [posts, query, searchType]);
|
|
147
|
-
|
|
148
|
-
const hasQuery = query.length > 0;
|
|
149
|
-
const empty =
|
|
150
|
-
hasQuery &&
|
|
151
|
-
wasteResults.length === 0 &&
|
|
152
|
-
locationResults.length === 0 &&
|
|
153
|
-
articleResults.length === 0;
|
|
154
|
-
|
|
155
|
-
const dividerInset = 14 + 10 + 12; // padding + dot + gap
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<View style={styles.wrap}>
|
|
159
|
-
<View
|
|
160
|
-
style={[
|
|
161
|
-
styles.inputRow,
|
|
162
|
-
{
|
|
163
|
-
backgroundColor: theme.colors.surface,
|
|
164
|
-
borderRadius: t.radii.md,
|
|
165
|
-
borderWidth: 1,
|
|
166
|
-
borderColor: theme.colors.border,
|
|
167
|
-
},
|
|
168
|
-
]}
|
|
169
|
-
>
|
|
170
|
-
<SearchIcon size={18} color={t.colors.muted} />
|
|
171
|
-
<TextInput
|
|
172
|
-
value={draft}
|
|
173
|
-
onChangeText={setDraft}
|
|
174
|
-
placeholder={placeholder || "Rechercher…"}
|
|
175
|
-
placeholderTextColor={t.colors.muted}
|
|
176
|
-
style={[styles.input, themedStyles.input]}
|
|
177
|
-
autoCorrect={false}
|
|
178
|
-
autoCapitalize="none"
|
|
179
|
-
/>
|
|
180
|
-
</View>
|
|
181
|
-
|
|
182
|
-
{empty ? (
|
|
183
|
-
<Text style={[styles.empty, { color: t.colors.muted }]}>Aucun résultat</Text>
|
|
184
|
-
) : null}
|
|
185
|
-
|
|
186
|
-
{wasteResults.length > 0 ? (
|
|
187
|
-
<ResultSection label={searchType === "all" ? "Consignes" : undefined}>
|
|
188
|
-
{wasteResults.map((info, index) => (
|
|
189
|
-
<ResultRow
|
|
190
|
-
key={info.id}
|
|
191
|
-
title={info.name}
|
|
192
|
-
meta={info.description}
|
|
193
|
-
accent={info.color ?? theme.colors.primary}
|
|
194
|
-
onPress={() => setWasteTypeId(info.wasteTypeId)}
|
|
195
|
-
showDivider={index < wasteResults.length - 1}
|
|
196
|
-
dividerInset={dividerInset}
|
|
197
|
-
/>
|
|
198
|
-
))}
|
|
199
|
-
</ResultSection>
|
|
200
|
-
) : null}
|
|
201
|
-
|
|
202
|
-
{locationResults.length > 0 ? (
|
|
203
|
-
<ResultSection label={searchType === "all" ? "Points de collecte" : undefined}>
|
|
204
|
-
{locationResults.map((loc, index) => (
|
|
205
|
-
<ResultRow
|
|
206
|
-
key={loc.id}
|
|
207
|
-
title={loc.name}
|
|
208
|
-
meta={[
|
|
209
|
-
LOCATION_CATEGORY_META[loc.category].label,
|
|
210
|
-
loc.address,
|
|
211
|
-
]
|
|
212
|
-
.filter(Boolean)
|
|
213
|
-
.join(" · ")}
|
|
214
|
-
accent={LOCATION_CATEGORY_META[loc.category].color}
|
|
215
|
-
showDivider={index < locationResults.length - 1}
|
|
216
|
-
dividerInset={dividerInset}
|
|
217
|
-
/>
|
|
218
|
-
))}
|
|
219
|
-
</ResultSection>
|
|
220
|
-
) : null}
|
|
221
|
-
|
|
222
|
-
{articleResults.length > 0 ? (
|
|
223
|
-
<ResultSection label={searchType === "all" ? "Articles" : undefined}>
|
|
224
|
-
{articleResults.map((post, index) => (
|
|
225
|
-
<ResultRow
|
|
226
|
-
key={post.id}
|
|
227
|
-
title={post.title}
|
|
228
|
-
accent={theme.colors.primary}
|
|
229
|
-
onPress={() => setArticle(post)}
|
|
230
|
-
showDivider={index < articleResults.length - 1}
|
|
231
|
-
dividerInset={dividerInset}
|
|
232
|
-
/>
|
|
233
|
-
))}
|
|
234
|
-
</ResultSection>
|
|
235
|
-
) : null}
|
|
236
|
-
|
|
237
|
-
<ConsignesModal
|
|
238
|
-
visible={!!wasteTypeId}
|
|
239
|
-
wasteTypeId={wasteTypeId ?? ""}
|
|
240
|
-
onClose={() => setWasteTypeId(null)}
|
|
241
|
-
/>
|
|
242
|
-
<ArticleReaderModal
|
|
243
|
-
visible={!!article}
|
|
244
|
-
post={article}
|
|
245
|
-
onClose={() => setArticle(null)}
|
|
246
|
-
/>
|
|
247
|
-
</View>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const createThemedStyles = (theme: Theme) =>
|
|
252
|
-
StyleSheet.create({
|
|
253
|
-
input: {
|
|
254
|
-
color: theme.colors.onSurface,
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
const styles = StyleSheet.create({
|
|
259
|
-
wrap: {
|
|
260
|
-
gap: 16,
|
|
261
|
-
},
|
|
262
|
-
inputRow: {
|
|
263
|
-
flexDirection: "row",
|
|
264
|
-
alignItems: "center",
|
|
265
|
-
gap: 10,
|
|
266
|
-
paddingHorizontal: 12,
|
|
267
|
-
paddingVertical: 10,
|
|
268
|
-
overflow: "hidden",
|
|
269
|
-
},
|
|
270
|
-
input: {
|
|
271
|
-
flex: 1,
|
|
272
|
-
fontSize: 16,
|
|
273
|
-
paddingVertical: 4,
|
|
274
|
-
},
|
|
275
|
-
empty: {
|
|
276
|
-
fontSize: 14,
|
|
277
|
-
textAlign: "center",
|
|
278
|
-
paddingVertical: 8,
|
|
279
|
-
},
|
|
280
|
-
section: {
|
|
281
|
-
gap: 8,
|
|
282
|
-
},
|
|
283
|
-
sectionLabel: {
|
|
284
|
-
fontSize: 12,
|
|
285
|
-
fontWeight: "600",
|
|
286
|
-
textTransform: "uppercase",
|
|
287
|
-
letterSpacing: 0.6,
|
|
288
|
-
paddingHorizontal: 4,
|
|
289
|
-
},
|
|
290
|
-
rowInner: {
|
|
291
|
-
flexDirection: "row",
|
|
292
|
-
alignItems: "center",
|
|
293
|
-
gap: 12,
|
|
294
|
-
paddingHorizontal: 14,
|
|
295
|
-
paddingVertical: 12,
|
|
296
|
-
},
|
|
297
|
-
dot: {
|
|
298
|
-
width: 10,
|
|
299
|
-
height: 10,
|
|
300
|
-
borderRadius: 5,
|
|
301
|
-
},
|
|
302
|
-
rowText: {
|
|
303
|
-
flex: 1,
|
|
304
|
-
gap: 2,
|
|
305
|
-
},
|
|
306
|
-
rowTitle: {
|
|
307
|
-
fontSize: 15,
|
|
308
|
-
fontWeight: "600",
|
|
309
|
-
},
|
|
310
|
-
rowMeta: {
|
|
311
|
-
fontSize: 13,
|
|
312
|
-
lineHeight: 18,
|
|
313
|
-
},
|
|
314
|
-
rowDivider: {
|
|
315
|
-
height: StyleSheet.hairlineWidth,
|
|
316
|
-
},
|
|
317
|
-
pressed: {
|
|
318
|
-
opacity: 0.85,
|
|
319
|
-
},
|
|
320
|
-
});
|
|
1
|
+
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
2
|
+
import { Pressable, StyleSheet, Text, TextInput, View } from "react-native";
|
|
3
|
+
import { ChevronRight, Search as SearchIcon } from "lucide-react-native";
|
|
4
|
+
import { useTheme } from "../../contexts/ThemeContext";
|
|
5
|
+
import { Theme } from "../../types/Theme";
|
|
6
|
+
import { useRecyclingInfo } from "../../hooks/useRecyclingInfo";
|
|
7
|
+
import { useBlogPosts } from "../../hooks/useBlogPosts";
|
|
8
|
+
import { useLocations, LOCATION_CATEGORY_META } from "../../hooks/useLocations";
|
|
9
|
+
import { ConsignesModal } from "../consignes-modal/ConsignesModal";
|
|
10
|
+
import { ArticleReaderModal } from "../article/ArticleReaderModal";
|
|
11
|
+
import type { BlogPost } from "../../helpers/blogPost";
|
|
12
|
+
import { groupedSectionStyle, resolveTheme } from "../../helpers/themeStyles";
|
|
13
|
+
|
|
14
|
+
export type SearchType = "all" | "waste-type" | "collection-points" | "articles";
|
|
15
|
+
|
|
16
|
+
export type SearchProps = {
|
|
17
|
+
searchType: SearchType;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function matchesQuery(haystack: string | undefined, query: string): boolean {
|
|
22
|
+
if (!haystack) return false;
|
|
23
|
+
return haystack.toLowerCase().includes(query);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type ResultRowProps = {
|
|
27
|
+
title: string;
|
|
28
|
+
meta?: string;
|
|
29
|
+
accent: string;
|
|
30
|
+
onPress?: () => void;
|
|
31
|
+
showDivider: boolean;
|
|
32
|
+
dividerInset: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function ResultRow({
|
|
36
|
+
title,
|
|
37
|
+
meta,
|
|
38
|
+
accent,
|
|
39
|
+
onPress,
|
|
40
|
+
showDivider,
|
|
41
|
+
dividerInset,
|
|
42
|
+
}: ResultRowProps) {
|
|
43
|
+
const { theme } = useTheme();
|
|
44
|
+
const t = resolveTheme(theme);
|
|
45
|
+
const content = (
|
|
46
|
+
<>
|
|
47
|
+
<View style={styles.rowInner}>
|
|
48
|
+
<View style={[styles.dot, { backgroundColor: accent }]} />
|
|
49
|
+
<View style={styles.rowText}>
|
|
50
|
+
<Text style={[styles.rowTitle, { color: theme.colors.onSurface }]}>
|
|
51
|
+
{title}
|
|
52
|
+
</Text>
|
|
53
|
+
{meta ? (
|
|
54
|
+
<Text style={[styles.rowMeta, { color: t.colors.muted }]} numberOfLines={2}>
|
|
55
|
+
{meta}
|
|
56
|
+
</Text>
|
|
57
|
+
) : null}
|
|
58
|
+
</View>
|
|
59
|
+
{onPress ? (
|
|
60
|
+
<ChevronRight size={18} color={t.colors.muted} />
|
|
61
|
+
) : null}
|
|
62
|
+
</View>
|
|
63
|
+
{showDivider ? (
|
|
64
|
+
<View
|
|
65
|
+
style={[
|
|
66
|
+
styles.rowDivider,
|
|
67
|
+
{
|
|
68
|
+
backgroundColor: theme.colors.border,
|
|
69
|
+
marginLeft: dividerInset,
|
|
70
|
+
},
|
|
71
|
+
]}
|
|
72
|
+
/>
|
|
73
|
+
) : null}
|
|
74
|
+
</>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (onPress) {
|
|
78
|
+
return (
|
|
79
|
+
<Pressable onPress={onPress} style={({ pressed }) => pressed && styles.pressed}>
|
|
80
|
+
{content}
|
|
81
|
+
</Pressable>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return <View>{content}</View>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function ResultSection({
|
|
88
|
+
label,
|
|
89
|
+
children,
|
|
90
|
+
}: {
|
|
91
|
+
label?: string;
|
|
92
|
+
children: ReactNode;
|
|
93
|
+
}) {
|
|
94
|
+
const { theme } = useTheme();
|
|
95
|
+
const t = resolveTheme(theme);
|
|
96
|
+
return (
|
|
97
|
+
<View style={styles.section}>
|
|
98
|
+
{label ? (
|
|
99
|
+
<Text style={[styles.sectionLabel, { color: t.colors.muted }]}>{label}</Text>
|
|
100
|
+
) : null}
|
|
101
|
+
<View style={groupedSectionStyle(theme)}>{children}</View>
|
|
102
|
+
</View>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function Search({
|
|
107
|
+
searchType,
|
|
108
|
+
placeholder,
|
|
109
|
+
}: SearchProps): ReactNode {
|
|
110
|
+
const { theme } = useTheme();
|
|
111
|
+
const t = resolveTheme(theme);
|
|
112
|
+
const themedStyles = createThemedStyles(theme);
|
|
113
|
+
const { recyclingInfos } = useRecyclingInfo();
|
|
114
|
+
const { posts } = useBlogPosts();
|
|
115
|
+
const { locations } = useLocations();
|
|
116
|
+
|
|
117
|
+
const [draft, setDraft] = useState("");
|
|
118
|
+
const [query, setQuery] = useState("");
|
|
119
|
+
const [wasteTypeId, setWasteTypeId] = useState<string | null>(null);
|
|
120
|
+
const [article, setArticle] = useState<BlogPost | null>(null);
|
|
121
|
+
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const handle = setTimeout(() => setQuery(draft.trim().toLowerCase()), 250);
|
|
124
|
+
return () => clearTimeout(handle);
|
|
125
|
+
}, [draft]);
|
|
126
|
+
|
|
127
|
+
const wasteResults = useMemo(() => {
|
|
128
|
+
if (!query || (searchType !== "all" && searchType !== "waste-type")) return [];
|
|
129
|
+
return recyclingInfos.filter(
|
|
130
|
+
(info) => matchesQuery(info.name, query) || matchesQuery(info.description, query)
|
|
131
|
+
);
|
|
132
|
+
}, [query, recyclingInfos, searchType]);
|
|
133
|
+
|
|
134
|
+
const locationResults = useMemo(() => {
|
|
135
|
+
if (!query || (searchType !== "all" && searchType !== "collection-points")) return [];
|
|
136
|
+
return locations.filter(
|
|
137
|
+
(loc) => matchesQuery(loc.name, query) || matchesQuery(loc.address, query)
|
|
138
|
+
);
|
|
139
|
+
}, [locations, query, searchType]);
|
|
140
|
+
|
|
141
|
+
const articleResults = useMemo(() => {
|
|
142
|
+
if (!query || (searchType !== "all" && searchType !== "articles")) return [];
|
|
143
|
+
return posts.filter(
|
|
144
|
+
(post) => matchesQuery(post.title, query) || matchesQuery(post.content, query)
|
|
145
|
+
);
|
|
146
|
+
}, [posts, query, searchType]);
|
|
147
|
+
|
|
148
|
+
const hasQuery = query.length > 0;
|
|
149
|
+
const empty =
|
|
150
|
+
hasQuery &&
|
|
151
|
+
wasteResults.length === 0 &&
|
|
152
|
+
locationResults.length === 0 &&
|
|
153
|
+
articleResults.length === 0;
|
|
154
|
+
|
|
155
|
+
const dividerInset = 14 + 10 + 12; // padding + dot + gap
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<View style={styles.wrap}>
|
|
159
|
+
<View
|
|
160
|
+
style={[
|
|
161
|
+
styles.inputRow,
|
|
162
|
+
{
|
|
163
|
+
backgroundColor: theme.colors.surface,
|
|
164
|
+
borderRadius: t.radii.md,
|
|
165
|
+
borderWidth: 1,
|
|
166
|
+
borderColor: theme.colors.border,
|
|
167
|
+
},
|
|
168
|
+
]}
|
|
169
|
+
>
|
|
170
|
+
<SearchIcon size={18} color={t.colors.muted} />
|
|
171
|
+
<TextInput
|
|
172
|
+
value={draft}
|
|
173
|
+
onChangeText={setDraft}
|
|
174
|
+
placeholder={placeholder || "Rechercher…"}
|
|
175
|
+
placeholderTextColor={t.colors.muted}
|
|
176
|
+
style={[styles.input, themedStyles.input]}
|
|
177
|
+
autoCorrect={false}
|
|
178
|
+
autoCapitalize="none"
|
|
179
|
+
/>
|
|
180
|
+
</View>
|
|
181
|
+
|
|
182
|
+
{empty ? (
|
|
183
|
+
<Text style={[styles.empty, { color: t.colors.muted }]}>Aucun résultat</Text>
|
|
184
|
+
) : null}
|
|
185
|
+
|
|
186
|
+
{wasteResults.length > 0 ? (
|
|
187
|
+
<ResultSection label={searchType === "all" ? "Consignes" : undefined}>
|
|
188
|
+
{wasteResults.map((info, index) => (
|
|
189
|
+
<ResultRow
|
|
190
|
+
key={info.id}
|
|
191
|
+
title={info.name}
|
|
192
|
+
meta={info.description}
|
|
193
|
+
accent={info.color ?? theme.colors.primary}
|
|
194
|
+
onPress={() => setWasteTypeId(info.wasteTypeId)}
|
|
195
|
+
showDivider={index < wasteResults.length - 1}
|
|
196
|
+
dividerInset={dividerInset}
|
|
197
|
+
/>
|
|
198
|
+
))}
|
|
199
|
+
</ResultSection>
|
|
200
|
+
) : null}
|
|
201
|
+
|
|
202
|
+
{locationResults.length > 0 ? (
|
|
203
|
+
<ResultSection label={searchType === "all" ? "Points de collecte" : undefined}>
|
|
204
|
+
{locationResults.map((loc, index) => (
|
|
205
|
+
<ResultRow
|
|
206
|
+
key={loc.id}
|
|
207
|
+
title={loc.name}
|
|
208
|
+
meta={[
|
|
209
|
+
LOCATION_CATEGORY_META[loc.category].label,
|
|
210
|
+
loc.address,
|
|
211
|
+
]
|
|
212
|
+
.filter(Boolean)
|
|
213
|
+
.join(" · ")}
|
|
214
|
+
accent={LOCATION_CATEGORY_META[loc.category].color}
|
|
215
|
+
showDivider={index < locationResults.length - 1}
|
|
216
|
+
dividerInset={dividerInset}
|
|
217
|
+
/>
|
|
218
|
+
))}
|
|
219
|
+
</ResultSection>
|
|
220
|
+
) : null}
|
|
221
|
+
|
|
222
|
+
{articleResults.length > 0 ? (
|
|
223
|
+
<ResultSection label={searchType === "all" ? "Articles" : undefined}>
|
|
224
|
+
{articleResults.map((post, index) => (
|
|
225
|
+
<ResultRow
|
|
226
|
+
key={post.id}
|
|
227
|
+
title={post.title}
|
|
228
|
+
accent={theme.colors.primary}
|
|
229
|
+
onPress={() => setArticle(post)}
|
|
230
|
+
showDivider={index < articleResults.length - 1}
|
|
231
|
+
dividerInset={dividerInset}
|
|
232
|
+
/>
|
|
233
|
+
))}
|
|
234
|
+
</ResultSection>
|
|
235
|
+
) : null}
|
|
236
|
+
|
|
237
|
+
<ConsignesModal
|
|
238
|
+
visible={!!wasteTypeId}
|
|
239
|
+
wasteTypeId={wasteTypeId ?? ""}
|
|
240
|
+
onClose={() => setWasteTypeId(null)}
|
|
241
|
+
/>
|
|
242
|
+
<ArticleReaderModal
|
|
243
|
+
visible={!!article}
|
|
244
|
+
post={article}
|
|
245
|
+
onClose={() => setArticle(null)}
|
|
246
|
+
/>
|
|
247
|
+
</View>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const createThemedStyles = (theme: Theme) =>
|
|
252
|
+
StyleSheet.create({
|
|
253
|
+
input: {
|
|
254
|
+
color: theme.colors.onSurface,
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const styles = StyleSheet.create({
|
|
259
|
+
wrap: {
|
|
260
|
+
gap: 16,
|
|
261
|
+
},
|
|
262
|
+
inputRow: {
|
|
263
|
+
flexDirection: "row",
|
|
264
|
+
alignItems: "center",
|
|
265
|
+
gap: 10,
|
|
266
|
+
paddingHorizontal: 12,
|
|
267
|
+
paddingVertical: 10,
|
|
268
|
+
overflow: "hidden",
|
|
269
|
+
},
|
|
270
|
+
input: {
|
|
271
|
+
flex: 1,
|
|
272
|
+
fontSize: 16,
|
|
273
|
+
paddingVertical: 4,
|
|
274
|
+
},
|
|
275
|
+
empty: {
|
|
276
|
+
fontSize: 14,
|
|
277
|
+
textAlign: "center",
|
|
278
|
+
paddingVertical: 8,
|
|
279
|
+
},
|
|
280
|
+
section: {
|
|
281
|
+
gap: 8,
|
|
282
|
+
},
|
|
283
|
+
sectionLabel: {
|
|
284
|
+
fontSize: 12,
|
|
285
|
+
fontWeight: "600",
|
|
286
|
+
textTransform: "uppercase",
|
|
287
|
+
letterSpacing: 0.6,
|
|
288
|
+
paddingHorizontal: 4,
|
|
289
|
+
},
|
|
290
|
+
rowInner: {
|
|
291
|
+
flexDirection: "row",
|
|
292
|
+
alignItems: "center",
|
|
293
|
+
gap: 12,
|
|
294
|
+
paddingHorizontal: 14,
|
|
295
|
+
paddingVertical: 12,
|
|
296
|
+
},
|
|
297
|
+
dot: {
|
|
298
|
+
width: 10,
|
|
299
|
+
height: 10,
|
|
300
|
+
borderRadius: 5,
|
|
301
|
+
},
|
|
302
|
+
rowText: {
|
|
303
|
+
flex: 1,
|
|
304
|
+
gap: 2,
|
|
305
|
+
},
|
|
306
|
+
rowTitle: {
|
|
307
|
+
fontSize: 15,
|
|
308
|
+
fontWeight: "600",
|
|
309
|
+
},
|
|
310
|
+
rowMeta: {
|
|
311
|
+
fontSize: 13,
|
|
312
|
+
lineHeight: 18,
|
|
313
|
+
},
|
|
314
|
+
rowDivider: {
|
|
315
|
+
height: StyleSheet.hairlineWidth,
|
|
316
|
+
},
|
|
317
|
+
pressed: {
|
|
318
|
+
opacity: 0.85,
|
|
319
|
+
},
|
|
320
|
+
});
|