Merge pull request 'feat(renderers): add eight principles collection and detail renderers' (#6) from eight-principles into main

Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-mobile-ui/pulls/6
This commit is contained in:
Amit Salunke 2026-09-25 04:51:03 +00:00
commit 94050ebfc4
2 changed files with 508 additions and 0 deletions

View File

@ -0,0 +1,189 @@
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 type {
CollectionItemRendererProps,
CollectionRendererProps,
} from "../../types/renderer.types";
export function EightPrinciplesCollectionRenderer(
props: CollectionRendererProps,
) {
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]);
const header = (
<View style={styles.overviewContainer}>
<View style={styles.overviewCard}>
<View style={styles.overviewHeader}>
<Ionicons name="information-circle" size={20} color={Colors.primary} />
<Text style={styles.overviewTitle}>Overview</Text>
</View>
<Text style={styles.overviewText}>
The eight principles include exterior, interior, cold, heat, deficiency, excess, yin and yang. Syndrome differentiation (pattern identification) of the eight principles is an essential paradigm in the Chinese medicine system.
</Text>
<Text style={styles.overviewParagraph}>
Pattern identification of the eight principles aims to tell about the disease location, the pathogenic nature and the strength between antipathogenic qi and pathogenic factors, thus generalizing the condition into eight categories.
</Text>
<Text style={styles.overviewParagraph}>
The eight principles can be divided into four pairs: interior/exterior for the depth of pathogens; cold/heat for the disease nature; deficiency/excess for the strength between antipathogenic qi and pathogenic factors; and yin/yang for the preponderance of yin and yang. However, yin and yang can also generalize the other six principles: exterior, heat and excess are ascribed to yang, and interior, cold and deficiency to yin.
</Text>
<Text style={styles.overviewParagraph}>
Two or more principles may occur concurrently, such as an exterior cold syndrome and an interior deficiency cold syndrome. A combined deficiency and excess may also be present. The principles may transform into each other as well, such as cold transforming into heat, or the exterior entering the interior. Additionally, a true cold may sometimes manifest as a false heat or vice versa.
</Text>
</View>
<Text style={styles.sectionHeading}>Eight Principles</Text>
</View>
);
return <CollectionScaffold {...props} items={sortedItems} header={header} />;
}
export function EightPrinciplesCardRenderer({
item,
onPress,
}: CollectionItemRendererProps) {
const a = item.attributes;
const title =
asString(a.name) ||
asString(a.title) ||
item.title;
const description =
asString(a.description) ||
asString(a.overview) ||
asString(a.classification) ||
item.summary;
const sortOrder = asNumber(a.sort_order);
const principleNumber =
typeof sortOrder === "number" && sortOrder > 0
? sortOrder
: typeof sortOrder === "number"
? sortOrder + 1
: undefined;
return (
<Pressable
accessibilityRole="button"
accessibilityLabel={title}
onPress={onPress}
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
>
<View style={styles.iconBox}>
{principleNumber !== undefined ? (
<Text style={styles.principleNumber}>{principleNumber}</Text>
) : (
<Ionicons name="git-network-outline" size={20} color={Colors.primaryDark} />
)}
</View>
<View style={styles.content}>
<Text numberOfLines={2} style={styles.title}>
{title}
</Text>
{description ? (
<Text numberOfLines={3} style={styles.subtitle}>
{description}
</Text>
) : null}
</View>
<Ionicons name="chevron-forward" size={19} color="#94A3B8" />
</Pressable>
);
}
const styles = StyleSheet.create({
overviewContainer: {
marginBottom: verticalScale(14),
},
overviewCard: {
backgroundColor: "#FFFFFF",
borderRadius: moderateScale(16),
borderWidth: 1,
borderColor: "#E2EAE5",
padding: moderateScale(16),
marginBottom: verticalScale(14),
},
overviewHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: verticalScale(8),
gap: moderateScale(8),
},
overviewTitle: {
fontSize: moderateScale(16),
fontWeight: "700",
color: Colors.textPrimary,
},
overviewText: {
fontSize: moderateScale(13),
lineHeight: verticalScale(19),
color: Colors.textSecondary,
},
overviewParagraph: {
fontSize: moderateScale(13),
lineHeight: verticalScale(19),
color: Colors.textSecondary,
marginTop: verticalScale(10),
},
sectionHeading: {
fontSize: moderateScale(15),
fontWeight: "700",
color: Colors.textPrimary,
marginBottom: verticalScale(4),
marginLeft: moderateScale(4),
},
row: {
minHeight: verticalScale(72),
flexDirection: "row",
alignItems: "center",
paddingHorizontal: moderateScale(14),
paddingVertical: verticalScale(13),
gap: moderateScale(11),
},
pressed: {
opacity: 0.72,
},
iconBox: {
width: moderateScale(40),
height: moderateScale(40),
borderRadius: moderateScale(20),
alignItems: "center",
justifyContent: "center",
backgroundColor: "#E8F5E9",
},
principleNumber: {
fontSize: moderateScale(16),
fontWeight: "800",
color: Colors.primaryDark,
},
content: {
flex: 1,
gap: verticalScale(3),
},
title: {
fontSize: moderateScale(16),
lineHeight: moderateScale(22),
fontWeight: "700",
color: Colors.textPrimary,
},
subtitle: {
fontSize: moderateScale(12.5),
lineHeight: moderateScale(18),
color: Colors.textSecondary,
},
});

View File

@ -0,0 +1,319 @@
import React from "react";
import { ScrollView, StyleSheet } from "react-native";
import type { DetailRendererProps } from "../../types/renderer.types";
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
import { ContentValue } from "../shared/ContentValue";
import { Hero } from "../shared/Hero";
import { SectionCard } from "../shared/SectionCard";
import { ObjectSections } from "../shared/ObjectSections";
import { Paragraphs } from "../shared/Paragraphs";
import { asString, humanizeKey } from "../helpers/value";
function objectValue(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
}
function isPresent(value: unknown): boolean {
if (value === null || value === undefined || value === "") return false;
if (Array.isArray(value)) return value.length > 0 && value.some(isPresent);
if (typeof value === "object") {
return Object.values(value as Record<string, unknown>).some(isPresent);
}
return true;
}
function TextSection({ title, value }: { title: string; value: unknown }) {
const text = asString(value);
if (!text) return null;
return (
<SectionCard title={title}>
<Paragraphs items={[text]} />
</SectionCard>
);
}
function ObjectSection({ title, value }: { title: string; value: unknown }) {
const object = objectValue(value);
if (Object.keys(object).length === 0) return null;
return (
<SectionCard title={title}>
<ObjectSections value={object} />
</SectionCard>
);
}
const HANDLED_KEYS = new Set([
"code",
"name",
"title",
"link",
"content",
"content_count",
"content_label",
"sort_order",
"description",
"classification",
"overview",
"analysis",
"clinical_manifestations",
"exterior-interior",
"exterior_syndrome",
"interior_syndrome",
"half-exterior_half-interior_syndrome",
"half_exterior_half_interior_syndrome",
"inward_penetration_of_exterior_pathogens_to_the_interior",
"outward_penetration_of_interior_pathogens_to_the_exterior",
"concurrent_exterior_and_interior_syndrome",
"cold_heat",
"cold_syndrome",
"heat_syndrome",
"combined_cold_and_heat_syndrome",
"upper_heat_with_lower_cold",
"upper_cold_with_lower_heat",
"exterior_cold_with_interior_heat",
"exterior_heat_with_interior_cold",
"mutual_transformation_of_cold_and_heat_syndromes",
"cold_transforming_into_heat",
"heat_transforming_into_cold",
"true_cold_with_false_heat_or_true_heat_with_false_cold",
"true_cold_with_false_heat",
"true_heat_with_false_cold",
"deficiency_excess",
"deficiency_syndrome",
"yang_deficiency",
"yin_deficiency",
"excess_syndrome",
"combined_deficiency_and_excess_syndrome",
"excess_syndrome_mixed_with_deficiency",
"deficiency_syndrome_mixed_with_excess",
"concurrent_deficiency_and_excess_syndrome",
"mutual_transformation_of_deficiency_and_excess_syndromes",
"true_deficiency_with_false_excess_or_true_excess_with_false_deficiency",
"true_deficiency_with_false_excess",
"true_excess_with_false_deficiency",
"summary",
"description_details",
"yin_yang",
"yin_syndrome",
"yang_syndrome",
"yin_syndromes",
"yang_syndromes",
"inspection",
"auscultation",
"inquiry",
"pulse_taking",
"deficiency_of_Genuine_Yin",
"deficiency_of_Genuine_Yang",
"yin_depletion",
"yang_depletion",
"note",
]);
export function EightPrinciplesDetailRenderer({
content,
data,
definitions,
presentationAttributes,
}: DetailRendererProps) {
const title = asString(data.title) || asString(data.name) || content.title;
const hasCombinedColdHeat = isPresent(data.combined_cold_and_heat_syndrome);
const hasMutualColdHeat = isPresent(data.mutual_transformation_of_cold_and_heat_syndromes);
const hasTrueColdHeat = isPresent(data.true_cold_with_false_heat_or_true_heat_with_false_cold);
const hasCombinedDefExcess = isPresent(data.combined_deficiency_and_excess_syndrome);
const hasTrueDefExcess = isPresent(
data.true_deficiency_with_false_excess_or_true_excess_with_false_deficiency,
);
const remainingEntries = Object.entries(data).filter(
([key, value]) => !HANDLED_KEYS.has(key) && isPresent(value),
);
return (
<ScrollView
contentContainerStyle={styles.content}
showsVerticalScrollIndicator={false}
>
<Hero title={title} />
{/* 1. Common Overview / Description */}
<TextSection title="Description" value={data.description} />
<TextSection title="Classification" value={data.classification} />
<TextSection title="Overview" value={data.overview} />
<TextSection title="Analysis" value={data.analysis} />
<TextSection title="Clinical Manifestations" value={data.clinical_manifestations} />
{/* 2. Exterior-Interior (m0011_ct0002) */}
<ObjectSection title="Exterior-Interior" value={data["exterior-interior"]} />
<ObjectSection title="Exterior Syndrome" value={data.exterior_syndrome} />
<ObjectSection title="Interior Syndrome" value={data.interior_syndrome} />
<TextSection
title="Half-Exterior Half-Interior Syndrome"
value={
data["half-exterior_half-interior_syndrome"] ??
data.half_exterior_half_interior_syndrome
}
/>
<TextSection
title="Inward Penetration of Exterior Pathogens to the Interior"
value={data.inward_penetration_of_exterior_pathogens_to_the_interior}
/>
<TextSection
title="Outward Penetration of Interior Pathogens to the Exterior"
value={data.outward_penetration_of_interior_pathogens_to_the_exterior}
/>
<TextSection
title="Concurrent Exterior and Interior Syndrome"
value={data.concurrent_exterior_and_interior_syndrome}
/>
{/* 3. Cold-Heat (m0011_ct0001) */}
<ObjectSection title="Cold-Heat" value={data.cold_heat} />
<ObjectSection title="Cold Syndrome" value={data.cold_syndrome} />
<ObjectSection title="Heat Syndrome" value={data.heat_syndrome} />
<ObjectSection
title="Combined Cold and Heat Syndrome"
value={data.combined_cold_and_heat_syndrome}
/>
{!hasCombinedColdHeat && (
<>
<TextSection title="Upper Heat with Lower Cold" value={data.upper_heat_with_lower_cold} />
<TextSection title="Upper Cold with Lower Heat" value={data.upper_cold_with_lower_heat} />
<TextSection
title="Exterior Cold with Interior Heat"
value={data.exterior_cold_with_interior_heat}
/>
<TextSection
title="Exterior Heat with Interior Cold"
value={data.exterior_heat_with_interior_cold}
/>
</>
)}
<ObjectSection
title="Mutual Transformation of Cold and Heat Syndromes"
value={data.mutual_transformation_of_cold_and_heat_syndromes}
/>
{!hasMutualColdHeat && (
<>
<TextSection
title="Cold Transforming into Heat"
value={data.cold_transforming_into_heat}
/>
<TextSection
title="Heat Transforming into Cold"
value={data.heat_transforming_into_cold}
/>
</>
)}
<ObjectSection
title="True Cold with False Heat or True Heat with False Cold"
value={data.true_cold_with_false_heat_or_true_heat_with_false_cold}
/>
{!hasTrueColdHeat && (
<>
<TextSection title="True Cold with False Heat" value={data.true_cold_with_false_heat} />
<TextSection title="True Heat with False Cold" value={data.true_heat_with_false_cold} />
</>
)}
{/* 4. Deficiency-Excess (m0011_ct0003) */}
<ObjectSection title="Deficiency-Excess" value={data.deficiency_excess} />
<ObjectSection title="Deficiency Syndrome" value={data.deficiency_syndrome} />
<ObjectSection title="Yang Deficiency" value={data.yang_deficiency} />
<ObjectSection title="Yin Deficiency" value={data.yin_deficiency} />
<ObjectSection title="Excess Syndrome" value={data.excess_syndrome} />
<ObjectSection
title="Combined Deficiency and Excess Syndrome"
value={data.combined_deficiency_and_excess_syndrome}
/>
{!hasCombinedDefExcess && (
<>
<TextSection
title="Excess Syndrome Mixed with Deficiency"
value={data.excess_syndrome_mixed_with_deficiency}
/>
<TextSection
title="Deficiency Syndrome Mixed with Excess"
value={data.deficiency_syndrome_mixed_with_excess}
/>
<TextSection
title="Concurrent Deficiency and Excess Syndrome"
value={data.concurrent_deficiency_and_excess_syndrome}
/>
</>
)}
<TextSection
title="Mutual Transformation of Deficiency and Excess Syndromes"
value={data.mutual_transformation_of_deficiency_and_excess_syndromes}
/>
<ObjectSection
title="True Deficiency with False Excess or True Excess with False Deficiency"
value={data.true_deficiency_with_false_excess_or_true_excess_with_false_deficiency}
/>
{!hasTrueDefExcess && (
<>
<TextSection
title="True Deficiency with False Excess"
value={data.true_deficiency_with_false_excess}
/>
<TextSection
title="True Excess with False Deficiency"
value={data.true_excess_with_false_deficiency}
/>
<TextSection title="Summary" value={data.summary} />
</>
)}
<ObjectSection title="Description Details" value={data.description_details} />
{/* 5. Yin-Yang (m0011_ct0004) */}
<ObjectSection title="Yin-Yang" value={data.yin_yang} />
<TextSection title="Yin Syndrome" value={data.yin_syndrome} />
<TextSection title="Yang Syndrome" value={data.yang_syndrome} />
<ObjectSection title="Yin Syndromes" value={data.yin_syndromes} />
<ObjectSection title="Yang Syndromes" value={data.yang_syndromes} />
<ObjectSection title="Inspection" value={data.inspection} />
<ObjectSection title="Auscultation" value={data.auscultation} />
<ObjectSection title="Inquiry" value={data.inquiry} />
<ObjectSection title="Pulse Taking" value={data.pulse_taking} />
<ObjectSection
title="Deficiency of Genuine Yin"
value={data.deficiency_of_Genuine_Yin}
/>
<ObjectSection
title="Deficiency of Genuine Yang"
value={data.deficiency_of_Genuine_Yang}
/>
<ObjectSection title="Yin Depletion" value={data.yin_depletion} />
<ObjectSection title="Yang Depletion" value={data.yang_depletion} />
{/* 6. Note */}
<TextSection title="Note" value={data.note} />
{/* 7. Any remaining unhandled fields fallback */}
{remainingEntries.map(([key, value]) => (
<SectionCard key={key} title={humanizeKey(key)}>
<ContentValue value={value} />
</SectionCard>
))}
<ContentLinkAttributeSections
data={data}
definitions={definitions}
presentationAttributes={presentationAttributes}
/>
</ScrollView>
);
}
const styles = StyleSheet.create({
content: {
paddingHorizontal: 18,
paddingTop: 16,
paddingBottom: 40,
gap: 14,
},
});