@wasto/cms-components 1.5.10 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -47
- package/dist/index.d.mts +103 -2
- package/dist/index.d.ts +103 -2
- package/dist/index.js +2861 -2442
- package/dist/index.mjs +3651 -3227
- package/package.json +2 -2
- package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
- package/src/components/article/Article.tsx +21 -21
- package/src/components/article/ArticleCard.tsx +81 -81
- package/src/components/article/ArticleExcerpts.tsx +80 -80
- package/src/components/article/ArticleList.tsx +114 -114
- package/src/components/article/ArticleMarkdown.tsx +170 -170
- package/src/components/article/ArticleReaderModal.tsx +93 -93
- package/src/components/article/ArticleSingle.tsx +57 -57
- package/src/components/bottom-tab/BottomTab.tsx +392 -392
- package/src/components/button/Button.tsx +154 -154
- package/src/components/challenge/Badges.tsx +84 -84
- package/src/components/challenge/BadgesModal.tsx +166 -166
- package/src/components/challenge/Challenge.tsx +380 -380
- package/src/components/challenge/ChallengeModal.tsx +231 -231
- package/src/components/challenge/ChallengeVignette.tsx +249 -249
- package/src/components/challenge/ChallengesModal.tsx +243 -243
- package/src/components/challenge/QuizModal.tsx +381 -381
- package/src/components/challenge/ResultModal.tsx +144 -144
- package/src/components/chat/Chat.tsx +928 -928
- package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
- package/src/components/columns/Columns.tsx +33 -33
- package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
- package/src/components/content-inset/ContentInset.tsx +33 -33
- package/src/components/header/Header.tsx +391 -391
- package/src/components/image/Image.tsx +15 -15
- package/src/components/image/ImageFrame.tsx +102 -102
- package/src/components/image/ImageMedia.tsx +31 -31
- package/src/components/image/ImageUrl.tsx +30 -30
- package/src/components/locations-map/LocationSheet.tsx +417 -417
- package/src/components/locations-map/LocationsMap.native.tsx +260 -260
- package/src/components/locations-map/LocationsMap.tsx +13 -13
- package/src/components/locations-map/LocationsMap.web.tsx +10 -10
- package/src/components/locations-map/LocationsMapShell.tsx +527 -527
- package/src/components/locations-map/LocationsMapView.tsx +108 -108
- package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
- package/src/components/nav-button/NavButton.tsx +59 -59
- package/src/components/next-collection/NextCollection.tsx +636 -621
- package/src/components/notifications/NotificationsScreen.tsx +247 -247
- package/src/components/page/Page.tsx +102 -64
- package/src/components/parapraph/Paragraph.tsx +67 -67
- package/src/components/profile/ProfileScreen.tsx +236 -236
- package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
- package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
- package/src/components/search/Search.tsx +320 -320
- package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
- package/src/components/title/Title.tsx +100 -100
- package/src/components/vision/Vision.tsx +447 -447
- package/src/components/vision/VisionActionCard.tsx +117 -117
- package/src/components/vision/VisionCapture.tsx +30 -30
- package/src/components/vision/VisionTapOverlay.tsx +122 -122
- package/src/contexts/AnnouncementsContext.tsx +171 -171
- package/src/contexts/AppDataContext.tsx +458 -0
- package/src/contexts/ChallengesContext.tsx +182 -182
- package/src/contexts/LocalContext.tsx +227 -227
- package/src/contexts/ThemeContext.tsx +37 -37
- package/src/contexts/WastoContext.tsx +130 -127
- package/src/helpers/blogPost.ts +72 -72
- package/src/helpers/generateQuizQuestions.ts +247 -247
- package/src/helpers/getContrastColor.ts +18 -18
- package/src/helpers/haptics.ts +20 -20
- package/src/helpers/hoursSchedule.ts +230 -230
- package/src/helpers/htmlContentToMarkdown.ts +114 -114
- package/src/helpers/layout.ts +54 -54
- package/src/helpers/loadLinearGradient.ts +22 -22
- package/src/helpers/mapLocations.ts +170 -0
- package/src/helpers/maquetteTheme.ts +76 -76
- package/src/helpers/markdownUnderlinePlugin.ts +32 -32
- package/src/helpers/nextCollection.ts +122 -0
- package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
- package/src/helpers/publicMediaUrl.ts +8 -8
- package/src/helpers/resolveApiAssetUrl.ts +21 -21
- package/src/helpers/systemRoutes.ts +7 -7
- package/src/helpers/themeStyles.ts +114 -114
- package/src/helpers/ttlCache.ts +41 -0
- package/src/helpers/useSafeAreaPadding.ts +14 -14
- package/src/hooks/useBadges.ts +100 -100
- package/src/hooks/useBlogPosts.ts +109 -105
- package/src/hooks/useChallenges.ts +110 -110
- package/src/hooks/useCities.ts +56 -56
- package/src/hooks/useCityAnnouncements.ts +118 -118
- package/src/hooks/useCollectionCalendar.ts +421 -421
- package/src/hooks/useColumns.ts +19 -19
- package/src/hooks/useConsignes.ts +62 -62
- package/src/hooks/useLocations.ts +120 -248
- package/src/hooks/useNextCollection.ts +163 -238
- package/src/hooks/useRecyclingInfo.ts +90 -90
- package/src/hooks/useWastoClient.ts +16 -16
- package/src/index.ts +149 -142
- package/src/navigation/NavigationContext.tsx +56 -56
- package/src/sentry/initSentry.ts +120 -120
- package/src/types/Theme.ts +72 -72
- package/src/types/css-modules.d.ts +1 -1
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import { LucideIcon } from "lucide-react-native";
|
|
3
|
-
import {
|
|
4
|
-
ActivityIndicator,
|
|
5
|
-
Pressable,
|
|
6
|
-
PressableProps,
|
|
7
|
-
StyleProp,
|
|
8
|
-
StyleSheet,
|
|
9
|
-
Text,
|
|
10
|
-
TextStyle,
|
|
11
|
-
View,
|
|
12
|
-
ViewStyle,
|
|
13
|
-
} from "react-native";
|
|
14
|
-
import { Theme } from "../../types/Theme";
|
|
15
|
-
import { useTheme } from "../../contexts/ThemeContext";
|
|
16
|
-
import { resolveTheme } from "../../helpers/themeStyles";
|
|
17
|
-
import { SPACE } from "../../helpers/layout";
|
|
18
|
-
|
|
19
|
-
export type ButtonVariant = "primary" | "ghost" | "secondary" | "outline";
|
|
20
|
-
|
|
21
|
-
export type ButtonProps = Omit<PressableProps, "children" | "style"> & {
|
|
22
|
-
variant?: ButtonVariant;
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
loading?: boolean;
|
|
25
|
-
leftIcon?: LucideIcon;
|
|
26
|
-
rightIcon?: LucideIcon;
|
|
27
|
-
children: string;
|
|
28
|
-
style?: StyleProp<ViewStyle>;
|
|
29
|
-
textStyle?: StyleProp<TextStyle>;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export function Button({
|
|
33
|
-
variant = "primary",
|
|
34
|
-
disabled = false,
|
|
35
|
-
loading = false,
|
|
36
|
-
leftIcon: LeftIcon,
|
|
37
|
-
rightIcon: RightIcon,
|
|
38
|
-
children,
|
|
39
|
-
style,
|
|
40
|
-
textStyle,
|
|
41
|
-
...props
|
|
42
|
-
}: ButtonProps): ReactNode {
|
|
43
|
-
const { theme } = useTheme();
|
|
44
|
-
const resolved = resolveTheme(theme);
|
|
45
|
-
const variantStyles = createThemedVariantsStyles(theme)[variant];
|
|
46
|
-
const isDisabled = disabled || loading;
|
|
47
|
-
|
|
48
|
-
const iconColor =
|
|
49
|
-
(textStyle && typeof textStyle === "object" && !Array.isArray(textStyle) && "color" in textStyle
|
|
50
|
-
? (textStyle.color as string)
|
|
51
|
-
: undefined) ??
|
|
52
|
-
(variantStyles.text.color as string);
|
|
53
|
-
|
|
54
|
-
const content = loading ? (
|
|
55
|
-
<ActivityIndicator size="small" color={iconColor} />
|
|
56
|
-
) : (
|
|
57
|
-
<View style={styles.content}>
|
|
58
|
-
{LeftIcon ? <LeftIcon size={18} color={iconColor} /> : null}
|
|
59
|
-
<Text style={[styles.text, variantStyles.text, textStyle]}>
|
|
60
|
-
{children}
|
|
61
|
-
</Text>
|
|
62
|
-
{RightIcon ? <RightIcon size={18} color={iconColor} /> : null}
|
|
63
|
-
</View>
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<Pressable
|
|
68
|
-
{...props}
|
|
69
|
-
disabled={isDisabled}
|
|
70
|
-
style={({ pressed }) => [
|
|
71
|
-
styles.base,
|
|
72
|
-
{ borderRadius: resolved.radii.md },
|
|
73
|
-
variantStyles.base,
|
|
74
|
-
style,
|
|
75
|
-
isDisabled && styles.disabled,
|
|
76
|
-
pressed && !isDisabled && styles.pressed,
|
|
77
|
-
]}
|
|
78
|
-
>
|
|
79
|
-
{content}
|
|
80
|
-
</Pressable>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const createThemedVariantsStyles = (theme: Theme): Record<
|
|
85
|
-
ButtonVariant,
|
|
86
|
-
{ base: ViewStyle; text: TextStyle }
|
|
87
|
-
> => {
|
|
88
|
-
const t = resolveTheme(theme);
|
|
89
|
-
return {
|
|
90
|
-
primary: StyleSheet.create({
|
|
91
|
-
base: {
|
|
92
|
-
backgroundColor: t.colors.primary,
|
|
93
|
-
...t.shadow.soft,
|
|
94
|
-
},
|
|
95
|
-
text: {
|
|
96
|
-
color: t.colors.onPrimary,
|
|
97
|
-
},
|
|
98
|
-
}),
|
|
99
|
-
secondary: StyleSheet.create({
|
|
100
|
-
base: {
|
|
101
|
-
backgroundColor: t.colors.surface,
|
|
102
|
-
borderColor: t.colors.border,
|
|
103
|
-
borderWidth: 1,
|
|
104
|
-
},
|
|
105
|
-
text: {
|
|
106
|
-
color: t.colors.primary,
|
|
107
|
-
},
|
|
108
|
-
}),
|
|
109
|
-
outline: StyleSheet.create({
|
|
110
|
-
base: {
|
|
111
|
-
backgroundColor: "transparent",
|
|
112
|
-
borderWidth: 1,
|
|
113
|
-
borderColor: t.colors.border,
|
|
114
|
-
},
|
|
115
|
-
text: {
|
|
116
|
-
color: t.colors.onSurface,
|
|
117
|
-
},
|
|
118
|
-
}),
|
|
119
|
-
ghost: StyleSheet.create({
|
|
120
|
-
base: {
|
|
121
|
-
backgroundColor: "transparent",
|
|
122
|
-
},
|
|
123
|
-
text: {
|
|
124
|
-
color: t.colors.onBackground,
|
|
125
|
-
},
|
|
126
|
-
}),
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const styles = StyleSheet.create({
|
|
131
|
-
base: {
|
|
132
|
-
height: SPACE.buttonH,
|
|
133
|
-
justifyContent: "center",
|
|
134
|
-
alignItems: "center",
|
|
135
|
-
overflow: "hidden",
|
|
136
|
-
},
|
|
137
|
-
content: {
|
|
138
|
-
flexDirection: "row",
|
|
139
|
-
alignItems: "center",
|
|
140
|
-
justifyContent: "center",
|
|
141
|
-
gap: 8,
|
|
142
|
-
paddingHorizontal: SPACE.pageX,
|
|
143
|
-
},
|
|
144
|
-
disabled: {
|
|
145
|
-
opacity: 0.5,
|
|
146
|
-
},
|
|
147
|
-
pressed: {
|
|
148
|
-
opacity: 0.9,
|
|
149
|
-
},
|
|
150
|
-
text: {
|
|
151
|
-
fontSize: 17,
|
|
152
|
-
fontWeight: "600",
|
|
153
|
-
},
|
|
154
|
-
});
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { LucideIcon } from "lucide-react-native";
|
|
3
|
+
import {
|
|
4
|
+
ActivityIndicator,
|
|
5
|
+
Pressable,
|
|
6
|
+
PressableProps,
|
|
7
|
+
StyleProp,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
Text,
|
|
10
|
+
TextStyle,
|
|
11
|
+
View,
|
|
12
|
+
ViewStyle,
|
|
13
|
+
} from "react-native";
|
|
14
|
+
import { Theme } from "../../types/Theme";
|
|
15
|
+
import { useTheme } from "../../contexts/ThemeContext";
|
|
16
|
+
import { resolveTheme } from "../../helpers/themeStyles";
|
|
17
|
+
import { SPACE } from "../../helpers/layout";
|
|
18
|
+
|
|
19
|
+
export type ButtonVariant = "primary" | "ghost" | "secondary" | "outline";
|
|
20
|
+
|
|
21
|
+
export type ButtonProps = Omit<PressableProps, "children" | "style"> & {
|
|
22
|
+
variant?: ButtonVariant;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
leftIcon?: LucideIcon;
|
|
26
|
+
rightIcon?: LucideIcon;
|
|
27
|
+
children: string;
|
|
28
|
+
style?: StyleProp<ViewStyle>;
|
|
29
|
+
textStyle?: StyleProp<TextStyle>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function Button({
|
|
33
|
+
variant = "primary",
|
|
34
|
+
disabled = false,
|
|
35
|
+
loading = false,
|
|
36
|
+
leftIcon: LeftIcon,
|
|
37
|
+
rightIcon: RightIcon,
|
|
38
|
+
children,
|
|
39
|
+
style,
|
|
40
|
+
textStyle,
|
|
41
|
+
...props
|
|
42
|
+
}: ButtonProps): ReactNode {
|
|
43
|
+
const { theme } = useTheme();
|
|
44
|
+
const resolved = resolveTheme(theme);
|
|
45
|
+
const variantStyles = createThemedVariantsStyles(theme)[variant];
|
|
46
|
+
const isDisabled = disabled || loading;
|
|
47
|
+
|
|
48
|
+
const iconColor =
|
|
49
|
+
(textStyle && typeof textStyle === "object" && !Array.isArray(textStyle) && "color" in textStyle
|
|
50
|
+
? (textStyle.color as string)
|
|
51
|
+
: undefined) ??
|
|
52
|
+
(variantStyles.text.color as string);
|
|
53
|
+
|
|
54
|
+
const content = loading ? (
|
|
55
|
+
<ActivityIndicator size="small" color={iconColor} />
|
|
56
|
+
) : (
|
|
57
|
+
<View style={styles.content}>
|
|
58
|
+
{LeftIcon ? <LeftIcon size={18} color={iconColor} /> : null}
|
|
59
|
+
<Text style={[styles.text, variantStyles.text, textStyle]}>
|
|
60
|
+
{children}
|
|
61
|
+
</Text>
|
|
62
|
+
{RightIcon ? <RightIcon size={18} color={iconColor} /> : null}
|
|
63
|
+
</View>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Pressable
|
|
68
|
+
{...props}
|
|
69
|
+
disabled={isDisabled}
|
|
70
|
+
style={({ pressed }) => [
|
|
71
|
+
styles.base,
|
|
72
|
+
{ borderRadius: resolved.radii.md },
|
|
73
|
+
variantStyles.base,
|
|
74
|
+
style,
|
|
75
|
+
isDisabled && styles.disabled,
|
|
76
|
+
pressed && !isDisabled && styles.pressed,
|
|
77
|
+
]}
|
|
78
|
+
>
|
|
79
|
+
{content}
|
|
80
|
+
</Pressable>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const createThemedVariantsStyles = (theme: Theme): Record<
|
|
85
|
+
ButtonVariant,
|
|
86
|
+
{ base: ViewStyle; text: TextStyle }
|
|
87
|
+
> => {
|
|
88
|
+
const t = resolveTheme(theme);
|
|
89
|
+
return {
|
|
90
|
+
primary: StyleSheet.create({
|
|
91
|
+
base: {
|
|
92
|
+
backgroundColor: t.colors.primary,
|
|
93
|
+
...t.shadow.soft,
|
|
94
|
+
},
|
|
95
|
+
text: {
|
|
96
|
+
color: t.colors.onPrimary,
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
secondary: StyleSheet.create({
|
|
100
|
+
base: {
|
|
101
|
+
backgroundColor: t.colors.surface,
|
|
102
|
+
borderColor: t.colors.border,
|
|
103
|
+
borderWidth: 1,
|
|
104
|
+
},
|
|
105
|
+
text: {
|
|
106
|
+
color: t.colors.primary,
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
outline: StyleSheet.create({
|
|
110
|
+
base: {
|
|
111
|
+
backgroundColor: "transparent",
|
|
112
|
+
borderWidth: 1,
|
|
113
|
+
borderColor: t.colors.border,
|
|
114
|
+
},
|
|
115
|
+
text: {
|
|
116
|
+
color: t.colors.onSurface,
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
ghost: StyleSheet.create({
|
|
120
|
+
base: {
|
|
121
|
+
backgroundColor: "transparent",
|
|
122
|
+
},
|
|
123
|
+
text: {
|
|
124
|
+
color: t.colors.onBackground,
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const styles = StyleSheet.create({
|
|
131
|
+
base: {
|
|
132
|
+
height: SPACE.buttonH,
|
|
133
|
+
justifyContent: "center",
|
|
134
|
+
alignItems: "center",
|
|
135
|
+
overflow: "hidden",
|
|
136
|
+
},
|
|
137
|
+
content: {
|
|
138
|
+
flexDirection: "row",
|
|
139
|
+
alignItems: "center",
|
|
140
|
+
justifyContent: "center",
|
|
141
|
+
gap: 8,
|
|
142
|
+
paddingHorizontal: SPACE.pageX,
|
|
143
|
+
},
|
|
144
|
+
disabled: {
|
|
145
|
+
opacity: 0.5,
|
|
146
|
+
},
|
|
147
|
+
pressed: {
|
|
148
|
+
opacity: 0.9,
|
|
149
|
+
},
|
|
150
|
+
text: {
|
|
151
|
+
fontSize: 17,
|
|
152
|
+
fontWeight: "600",
|
|
153
|
+
},
|
|
154
|
+
});
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { StyleSheet, View } from "react-native";
|
|
2
|
-
import { Image } from "expo-image";
|
|
3
|
-
import { AcquiredBadge } from "../../hooks/useChallenges";
|
|
4
|
-
import { Theme } from "../../types/Theme";
|
|
5
|
-
import { useTheme } from "../../contexts/ThemeContext";
|
|
6
|
-
import { useMemo, useState, type ReactNode } from "react";
|
|
7
|
-
import { NavButton } from "../nav-button/NavButton";
|
|
8
|
-
import { PlusIcon } from "lucide-react-native";
|
|
9
|
-
import { BadgesModal } from "./BadgesModal";
|
|
10
|
-
|
|
11
|
-
export type BadgesProps = {
|
|
12
|
-
badges: AcquiredBadge[];
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export function Badges({
|
|
16
|
-
badges,
|
|
17
|
-
}: BadgesProps): ReactNode {
|
|
18
|
-
const { theme } = useTheme();
|
|
19
|
-
const themedStyles = createThemedStyles(theme);
|
|
20
|
-
const [displayAllBadges, setDisplayAllBadges] = useState(false);
|
|
21
|
-
|
|
22
|
-
const badgesDisplay = useMemo<(AcquiredBadge | null)[]>(() => {
|
|
23
|
-
const activeBadges = badges.slice(0, 5);
|
|
24
|
-
return Array.from({ length: 5 }, (_, i) => activeBadges[i] ?? null);
|
|
25
|
-
}, [badges]);
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<>
|
|
29
|
-
<View style={styles.badges}>
|
|
30
|
-
{badgesDisplay.map((badge, index) =>
|
|
31
|
-
badge ? (
|
|
32
|
-
<View
|
|
33
|
-
key={badge.badgeId}
|
|
34
|
-
style={[styles.badge, themedStyles.badge]}
|
|
35
|
-
>
|
|
36
|
-
{badge.badge?.imageUrl ? (
|
|
37
|
-
<Image
|
|
38
|
-
source={badge.badge.imageUrl}
|
|
39
|
-
style={styles.badgeImage}
|
|
40
|
-
contentFit="cover"
|
|
41
|
-
/>
|
|
42
|
-
) : null}
|
|
43
|
-
</View>
|
|
44
|
-
) : (
|
|
45
|
-
<View
|
|
46
|
-
key={index.toString()}
|
|
47
|
-
style={[styles.badge, themedStyles.badge]}
|
|
48
|
-
/>
|
|
49
|
-
)
|
|
50
|
-
)}
|
|
51
|
-
</View>
|
|
52
|
-
<BadgesModal
|
|
53
|
-
visible={displayAllBadges}
|
|
54
|
-
acquiredBadges={badges}
|
|
55
|
-
onClose={() => setDisplayAllBadges(false)}
|
|
56
|
-
/>
|
|
57
|
-
</>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const createThemedStyles = (theme: Theme) =>
|
|
62
|
-
StyleSheet.create({
|
|
63
|
-
badge: {
|
|
64
|
-
backgroundColor: theme.colors.surface,
|
|
65
|
-
borderRadius: theme.radius,
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const styles = StyleSheet.create({
|
|
70
|
-
badges: {
|
|
71
|
-
flexDirection: "row",
|
|
72
|
-
gap: 10,
|
|
73
|
-
alignItems: "center",
|
|
74
|
-
},
|
|
75
|
-
badge: {
|
|
76
|
-
flex: 1,
|
|
77
|
-
aspectRatio: 3 / 4,
|
|
78
|
-
overflow: "hidden",
|
|
79
|
-
},
|
|
80
|
-
badgeImage: {
|
|
81
|
-
width: "100%",
|
|
82
|
-
height: "100%",
|
|
83
|
-
},
|
|
84
|
-
});
|
|
1
|
+
import { StyleSheet, View } from "react-native";
|
|
2
|
+
import { Image } from "expo-image";
|
|
3
|
+
import { AcquiredBadge } from "../../hooks/useChallenges";
|
|
4
|
+
import { Theme } from "../../types/Theme";
|
|
5
|
+
import { useTheme } from "../../contexts/ThemeContext";
|
|
6
|
+
import { useMemo, useState, type ReactNode } from "react";
|
|
7
|
+
import { NavButton } from "../nav-button/NavButton";
|
|
8
|
+
import { PlusIcon } from "lucide-react-native";
|
|
9
|
+
import { BadgesModal } from "./BadgesModal";
|
|
10
|
+
|
|
11
|
+
export type BadgesProps = {
|
|
12
|
+
badges: AcquiredBadge[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function Badges({
|
|
16
|
+
badges,
|
|
17
|
+
}: BadgesProps): ReactNode {
|
|
18
|
+
const { theme } = useTheme();
|
|
19
|
+
const themedStyles = createThemedStyles(theme);
|
|
20
|
+
const [displayAllBadges, setDisplayAllBadges] = useState(false);
|
|
21
|
+
|
|
22
|
+
const badgesDisplay = useMemo<(AcquiredBadge | null)[]>(() => {
|
|
23
|
+
const activeBadges = badges.slice(0, 5);
|
|
24
|
+
return Array.from({ length: 5 }, (_, i) => activeBadges[i] ?? null);
|
|
25
|
+
}, [badges]);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
<View style={styles.badges}>
|
|
30
|
+
{badgesDisplay.map((badge, index) =>
|
|
31
|
+
badge ? (
|
|
32
|
+
<View
|
|
33
|
+
key={badge.badgeId}
|
|
34
|
+
style={[styles.badge, themedStyles.badge]}
|
|
35
|
+
>
|
|
36
|
+
{badge.badge?.imageUrl ? (
|
|
37
|
+
<Image
|
|
38
|
+
source={badge.badge.imageUrl}
|
|
39
|
+
style={styles.badgeImage}
|
|
40
|
+
contentFit="cover"
|
|
41
|
+
/>
|
|
42
|
+
) : null}
|
|
43
|
+
</View>
|
|
44
|
+
) : (
|
|
45
|
+
<View
|
|
46
|
+
key={index.toString()}
|
|
47
|
+
style={[styles.badge, themedStyles.badge]}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
)}
|
|
51
|
+
</View>
|
|
52
|
+
<BadgesModal
|
|
53
|
+
visible={displayAllBadges}
|
|
54
|
+
acquiredBadges={badges}
|
|
55
|
+
onClose={() => setDisplayAllBadges(false)}
|
|
56
|
+
/>
|
|
57
|
+
</>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const createThemedStyles = (theme: Theme) =>
|
|
62
|
+
StyleSheet.create({
|
|
63
|
+
badge: {
|
|
64
|
+
backgroundColor: theme.colors.surface,
|
|
65
|
+
borderRadius: theme.radius,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const styles = StyleSheet.create({
|
|
70
|
+
badges: {
|
|
71
|
+
flexDirection: "row",
|
|
72
|
+
gap: 10,
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
},
|
|
75
|
+
badge: {
|
|
76
|
+
flex: 1,
|
|
77
|
+
aspectRatio: 3 / 4,
|
|
78
|
+
overflow: "hidden",
|
|
79
|
+
},
|
|
80
|
+
badgeImage: {
|
|
81
|
+
width: "100%",
|
|
82
|
+
height: "100%",
|
|
83
|
+
},
|
|
84
|
+
});
|