feat(m0001): add YuanLuoDetailRenderer for host-guest pairings
This commit is contained in:
parent
a1383ce840
commit
8f7ab00df2
|
|
@ -0,0 +1,248 @@
|
||||||
|
import React, { useMemo } from "react";
|
||||||
|
import { ScrollView, StyleSheet, Text, View } from "react-native";
|
||||||
|
import { useRouter } from "expo-router";
|
||||||
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
|
|
||||||
|
import { Colors } from "@/theme";
|
||||||
|
import { useSettingsStore } from "@/store/settings.store";
|
||||||
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
|
import {
|
||||||
|
asNumber,
|
||||||
|
asRecordArray,
|
||||||
|
asString,
|
||||||
|
asStringArray,
|
||||||
|
} from "../helpers/value";
|
||||||
|
import { BulletList } from "../shared/BulletList";
|
||||||
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
|
import { Hero } from "../shared/Hero";
|
||||||
|
import { OverviewCard } from "../shared/OverviewCard";
|
||||||
|
import { Images } from "./categoryParts";
|
||||||
|
import {
|
||||||
|
buildCategoryOverviewParagraphs,
|
||||||
|
extractPointRefLabel,
|
||||||
|
navigateToPointRef,
|
||||||
|
PointCategoryAccordionCard,
|
||||||
|
pointCategoryStyles,
|
||||||
|
PointLinkChip,
|
||||||
|
type PointsCatalogMap,
|
||||||
|
usePointsCatalogMap,
|
||||||
|
} from "./pointCategoryShared";
|
||||||
|
|
||||||
|
interface PairingItemProps {
|
||||||
|
key?: React.Key;
|
||||||
|
pairing: Record<string, unknown>;
|
||||||
|
index: number;
|
||||||
|
defaultExpanded: boolean;
|
||||||
|
moduleCode: string;
|
||||||
|
pointsCatalogMap: PointsCatalogMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
function PairingAccordionCard({
|
||||||
|
pairing,
|
||||||
|
index,
|
||||||
|
defaultExpanded,
|
||||||
|
moduleCode,
|
||||||
|
pointsCatalogMap,
|
||||||
|
}: PairingItemProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const num = asNumber(pairing.number) ?? index + 1;
|
||||||
|
const meridianPair = asString(pairing.meridian_pair).trim();
|
||||||
|
const hostLabel = extractPointRefLabel(pairing.host);
|
||||||
|
const guestLabel = extractPointRefLabel(pairing.guest);
|
||||||
|
const patterns = asRecordArray(pairing.patterns);
|
||||||
|
|
||||||
|
const title = meridianPair
|
||||||
|
? `${num}. ${meridianPair}`
|
||||||
|
: `Pairing ${num}`;
|
||||||
|
const pairBadge =
|
||||||
|
hostLabel && guestLabel
|
||||||
|
? `${hostLabel} + ${guestLabel}`
|
||||||
|
: hostLabel || guestLabel;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PointCategoryAccordionCard
|
||||||
|
title={title}
|
||||||
|
badges={pairBadge ? [pairBadge] : []}
|
||||||
|
defaultExpanded={defaultExpanded}
|
||||||
|
>
|
||||||
|
{patterns.map((pattern, patternIdx) => {
|
||||||
|
const patternCode = asString(pattern.pattern_code).trim();
|
||||||
|
const patternName = asString(pattern.pattern_name).trim();
|
||||||
|
const needleTechnique = asString(pattern.needle_technique).trim();
|
||||||
|
const actions = asStringArray(pattern.actions);
|
||||||
|
const indications = asStringArray(pattern.indications);
|
||||||
|
|
||||||
|
const heading = patternCode && patternName
|
||||||
|
? `${patternCode}. ${patternName}`
|
||||||
|
: patternName || `Pattern ${patternIdx + 1}`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
key={`${patternCode}-${patternIdx}`}
|
||||||
|
style={[
|
||||||
|
styles.patternBlock,
|
||||||
|
patternIdx > 0 && styles.patternDivider,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Text style={styles.patternTitle}>{heading}</Text>
|
||||||
|
|
||||||
|
{needleTechnique ? (
|
||||||
|
<View style={styles.techniqueBox}>
|
||||||
|
<Text style={pointCategoryStyles.sectionLabel}>
|
||||||
|
NEEDLE TECHNIQUE
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.techniqueText}>{needleTechnique}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{actions.length > 0 ? (
|
||||||
|
<View style={styles.listGroup}>
|
||||||
|
<Text style={pointCategoryStyles.sectionLabel}>ACTIONS</Text>
|
||||||
|
<BulletList items={actions} />
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{indications.length > 0 ? (
|
||||||
|
<View style={styles.listGroup}>
|
||||||
|
<Text style={pointCategoryStyles.sectionLabel}>INDICATIONS</Text>
|
||||||
|
<BulletList items={indications} />
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{hostLabel || guestLabel ? (
|
||||||
|
<View style={pointCategoryStyles.pointLinksRow}>
|
||||||
|
{hostLabel ? (
|
||||||
|
<PointLinkChip
|
||||||
|
label={`Host: ${hostLabel}`}
|
||||||
|
onPress={() =>
|
||||||
|
navigateToPointRef(
|
||||||
|
router,
|
||||||
|
pairing.host,
|
||||||
|
moduleCode,
|
||||||
|
pointsCatalogMap,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
{guestLabel ? (
|
||||||
|
<PointLinkChip
|
||||||
|
label={`Guest: ${guestLabel}`}
|
||||||
|
onPress={() =>
|
||||||
|
navigateToPointRef(
|
||||||
|
router,
|
||||||
|
pairing.guest,
|
||||||
|
moduleCode,
|
||||||
|
pointsCatalogMap,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</PointCategoryAccordionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renders Yuan–Luo (Host–Guest) category overview and meridian pairing pattern accordions. */
|
||||||
|
export function YuanLuoDetailRenderer({
|
||||||
|
moduleCode = "m0001",
|
||||||
|
content,
|
||||||
|
data,
|
||||||
|
definitions,
|
||||||
|
presentationAttributes,
|
||||||
|
}: DetailRendererProps) {
|
||||||
|
const accordionDefaultExpanded = useSettingsStore(
|
||||||
|
(state) => state.accordionDefaultExpanded,
|
||||||
|
);
|
||||||
|
const pointsCatalogMap = usePointsCatalogMap(moduleCode);
|
||||||
|
|
||||||
|
const rawTitle =
|
||||||
|
asString(data.title) || asString(data.name) || content.title || "Yuan–Luo Points";
|
||||||
|
const alias = asString(data.alias).trim() || undefined;
|
||||||
|
const overviewParagraphs = useMemo(
|
||||||
|
() => buildCategoryOverviewParagraphs(data),
|
||||||
|
[data],
|
||||||
|
);
|
||||||
|
const pairings = asRecordArray(data.pairings);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
contentContainerStyle={pointCategoryStyles.container}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
>
|
||||||
|
<Hero title={rawTitle} subtitle={alias} />
|
||||||
|
|
||||||
|
<Images data={data} />
|
||||||
|
|
||||||
|
{overviewParagraphs.length > 0 ? (
|
||||||
|
<OverviewCard
|
||||||
|
title="Overview"
|
||||||
|
variant="bullets"
|
||||||
|
paragraphs={overviewParagraphs}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{pairings.length > 0 ? (
|
||||||
|
<View style={pointCategoryStyles.cardsList}>
|
||||||
|
{pairings.map((pairing, index) => (
|
||||||
|
<PairingAccordionCard
|
||||||
|
key={index}
|
||||||
|
pairing={pairing}
|
||||||
|
index={index}
|
||||||
|
defaultExpanded={accordionDefaultExpanded}
|
||||||
|
moduleCode={moduleCode}
|
||||||
|
pointsCatalogMap={pointsCatalogMap}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<ContentLinkAttributeSections
|
||||||
|
data={data}
|
||||||
|
definitions={definitions}
|
||||||
|
presentationAttributes={presentationAttributes}
|
||||||
|
excludeAttributeKeys={["points", "pairings"]}
|
||||||
|
/>
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
patternBlock: {
|
||||||
|
gap: verticalScale(10),
|
||||||
|
},
|
||||||
|
patternDivider: {
|
||||||
|
paddingTop: verticalScale(12),
|
||||||
|
borderTopWidth: 1,
|
||||||
|
borderTopColor: "#E2E8F0",
|
||||||
|
},
|
||||||
|
patternTitle: {
|
||||||
|
fontSize: moderateScale(15),
|
||||||
|
lineHeight: moderateScale(21),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.primaryDark,
|
||||||
|
},
|
||||||
|
techniqueBox: {
|
||||||
|
backgroundColor: "#F8FAFC",
|
||||||
|
borderRadius: moderateScale(10),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2E8F0",
|
||||||
|
paddingHorizontal: moderateScale(12),
|
||||||
|
paddingVertical: verticalScale(8),
|
||||||
|
gap: verticalScale(3),
|
||||||
|
},
|
||||||
|
techniqueText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
lineHeight: moderateScale(20),
|
||||||
|
fontWeight: "600",
|
||||||
|
color: "#1E293B",
|
||||||
|
},
|
||||||
|
listGroup: {
|
||||||
|
gap: verticalScale(6),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
Reference in New Issue