136 lines
4.3 KiB
TypeScript
136 lines
4.3 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 } from "../helpers/value";
|
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
|
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
|
import { OverviewCard } from "../shared/OverviewCard";
|
|
import type {
|
|
CollectionItemRendererProps,
|
|
CollectionRendererProps,
|
|
} from "../../types/renderer.types";
|
|
|
|
export function FiveElementsCollectionRenderer(props: CollectionRendererProps) {
|
|
const header = (
|
|
<View style={styles.overviewContainer}>
|
|
<OverviewCard
|
|
style={styles.overviewCard}
|
|
paragraphs={[
|
|
"The identification of patterns according to the Five Elements is based on the pathological changes occurring in dysfunctions of the Generating, Overacting and Insulting sequences of the Five Elements.",
|
|
"These patterns describe clinical conditions which are often expressed by the Internal Organ patterns, but in certain cases, Five-Element patterns describe conditions falling outside their scope (such as Deficient Qi of Wood manifesting with timidity and indecision).",
|
|
"The sequences below detail the Generating, Overacting, and Insulting relationships and their specific clinical presentations.",
|
|
]}
|
|
/>
|
|
<Text style={styles.sectionHeading}>Sequences</Text>
|
|
</View>
|
|
);
|
|
|
|
const sortedItems = React.useMemo(() => {
|
|
return [...props.items].sort((a, b) => {
|
|
const orderA = asNumber(a.attributes.sort_order) ?? 999;
|
|
const orderB = asNumber(b.attributes.sort_order) ?? 999;
|
|
return orderA - orderB;
|
|
});
|
|
}, [props.items]);
|
|
|
|
return <CollectionScaffold {...props} items={sortedItems} header={header} />;
|
|
}
|
|
|
|
export function FiveElementsCardRenderer({
|
|
item,
|
|
onPress,
|
|
}: CollectionItemRendererProps) {
|
|
const attributes = item.attributes;
|
|
const title = asString(attributes.title) || asString(attributes.name) || item.title;
|
|
const subtitle =
|
|
asString(attributes.sub_title) ||
|
|
asString(attributes.description) ||
|
|
(item.summary && item.summary !== "Open sequence" ? item.summary : null);
|
|
|
|
const sortOrder = asNumber(attributes.sort_order);
|
|
const sequenceNumber = typeof sortOrder === "number" ? sortOrder + 1 : undefined;
|
|
|
|
return (
|
|
<Pressable
|
|
accessibilityRole="button"
|
|
onPress={onPress}
|
|
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
|
|
>
|
|
<View style={styles.iconWrapper}>
|
|
<Text style={styles.sequenceNumber}>{sequenceNumber !== undefined ? sequenceNumber : "•"}</Text>
|
|
</View>
|
|
|
|
<View style={styles.textContainer}>
|
|
<Text style={styles.title}>{title}</Text>
|
|
{subtitle ? (
|
|
<Text style={styles.description} numberOfLines={1}>
|
|
{subtitle}
|
|
</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({
|
|
overviewContainer: {
|
|
marginBottom: verticalScale(14),
|
|
},
|
|
overviewCard: {
|
|
marginBottom: verticalScale(14),
|
|
},
|
|
sectionHeading: {
|
|
fontSize: moderateScale(15),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
marginBottom: verticalScale(4),
|
|
marginLeft: moderateScale(4),
|
|
},
|
|
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",
|
|
},
|
|
sequenceNumber: {
|
|
fontSize: moderateScale(16),
|
|
fontWeight: "800",
|
|
color: Colors.primaryDark,
|
|
},
|
|
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,
|
|
},
|
|
});
|