109 lines
3.1 KiB
TypeScript
109 lines
3.1 KiB
TypeScript
import React from "react";
|
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
|
|
import { Colors } from "@/theme";
|
|
import { asNumber, asString, humanizeKey } from "../helpers/value";
|
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
|
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
|
import type {
|
|
CollectionItemRendererProps,
|
|
CollectionRendererProps,
|
|
} from "../../types/renderer.types";
|
|
|
|
export function ModuleCatalogCollectionRenderer(props: CollectionRendererProps) {
|
|
return <CollectionScaffold {...props} />;
|
|
}
|
|
|
|
export function ModuleCatalogCardRenderer({
|
|
item,
|
|
onPress,
|
|
}: CollectionItemRendererProps) {
|
|
const attributes = item.attributes;
|
|
const rawTitle = asString(attributes.name) || item.title;
|
|
const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/);
|
|
const title = parenMatch
|
|
? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim()
|
|
: rawTitle;
|
|
const parenSubtitle = parenMatch ? parenMatch[2].trim() : null;
|
|
|
|
const rawLabel =
|
|
parenSubtitle ||
|
|
asString(attributes.sub_title) ||
|
|
asString(attributes.pattern_category) ||
|
|
asString(attributes.category) ||
|
|
asString(attributes.classification) ||
|
|
(asString(attributes.title) && asString(attributes.title) !== title
|
|
? asString(attributes.title)
|
|
: null) ||
|
|
asString(attributes.description) ||
|
|
item.summary ||
|
|
null;
|
|
|
|
const cleanTitle = humanizeKey(title);
|
|
const label = rawLabel ? humanizeKey(rawLabel) : null;
|
|
|
|
return (
|
|
<Pressable
|
|
accessibilityRole="button"
|
|
onPress={onPress}
|
|
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
|
|
>
|
|
<View style={styles.iconWrapper}>
|
|
<Ionicons name="book-outline" size={22} color={Colors.primary} />
|
|
</View>
|
|
|
|
<View style={styles.textContainer}>
|
|
<Text style={styles.title}>{cleanTitle}</Text>
|
|
{label ? (
|
|
<Text style={styles.description} numberOfLines={1}>
|
|
{label}
|
|
</Text>
|
|
) : null}
|
|
</View>
|
|
|
|
<ContentCountBadge
|
|
count={asNumber(attributes.content_count)}
|
|
label={asString(attributes.content_label)}
|
|
/>
|
|
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
|
|
</Pressable>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
row: {
|
|
minHeight: moderateScale(68),
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
padding: moderateScale(14),
|
|
},
|
|
pressed: {
|
|
opacity: 0.72,
|
|
},
|
|
iconWrapper: {
|
|
width: moderateScale(40),
|
|
height: moderateScale(40),
|
|
borderRadius: moderateScale(20),
|
|
justifyContent: "center",
|
|
alignItems: "center",
|
|
backgroundColor: "#E8F5E9",
|
|
},
|
|
textContainer: {
|
|
flex: 1,
|
|
marginLeft: moderateScale(12),
|
|
marginRight: moderateScale(10),
|
|
},
|
|
title: {
|
|
fontSize: moderateScale(15),
|
|
fontWeight: "600",
|
|
color: Colors.textPrimary,
|
|
marginBottom: verticalScale(2),
|
|
},
|
|
description: {
|
|
fontSize: moderateScale(12),
|
|
color: Colors.textSecondary,
|
|
},
|
|
});
|