Compare commits
8 Commits
5c6180b6b0
...
f4faa58d83
| Author | SHA1 | Date |
|---|---|---|
|
|
f4faa58d83 | |
|
|
7f457f4a80 | |
|
|
8f7ab00df2 | |
|
|
a1383ce840 | |
|
|
ba7d730112 | |
|
|
db460fecca | |
|
|
09f0fae67d | |
|
|
40d9feb869 |
|
|
@ -1,8 +1,13 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ScrollView } from "react-native";
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||||
import { asString } from "../helpers/value";
|
|
||||||
import { Hero } from "../shared/Hero";
|
/** Renders Back-Shu category details using the shared Overview and expandable Points accordion layout. */
|
||||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
export function BackShuDetailRenderer(props: DetailRendererProps) {
|
||||||
export function BackShuDetailRenderer({content,data,definitions,presentationAttributes}:DetailRendererProps){ return <ScrollView contentContainerStyle={{paddingHorizontal:18,paddingTop:16,paddingBottom:40,gap:14}}><Hero title={asString(data.title)||asString(data.name)||content.title}/><Images data={data}/><PointCodes data={data}/><ObjectArrayTable title="Back-Shu Points" value={data.points}/><ObjectCard title="Functions" value={data.functions}/><ObjectCard title="Clinical Application" value={data.clinical_application}/><ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/></ScrollView>; }
|
return (
|
||||||
|
<YuanSourceDetailRenderer
|
||||||
|
{...props}
|
||||||
|
fallbackTitle="Back-Shu Points"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ScrollView } from "react-native";
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||||
import { asString } from "../helpers/value";
|
|
||||||
import { Hero } from "../shared/Hero";
|
/** Renders Front-Mu category details using the shared Overview and expandable Points accordion layout. */
|
||||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
export function FrontMuDetailRenderer(props: DetailRendererProps) {
|
||||||
export function FrontMuDetailRenderer({content,data,definitions,presentationAttributes}:DetailRendererProps){ return <ScrollView contentContainerStyle={{paddingHorizontal:18,paddingTop:16,paddingBottom:40,gap:14}}><Hero title={asString(data.title)||asString(data.name)||content.title}/><Images data={data}/><PointCodes data={data}/><ObjectArrayTable title="Front-Mu Points" value={data.front_mu_points}/><Strings title="Description" value={data.description}/><ObjectCard title="Clinical Application" value={data.clinical_application}/><ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/></ScrollView>; }
|
return (
|
||||||
|
<YuanSourceDetailRenderer
|
||||||
|
{...props}
|
||||||
|
fallbackTitle="Front-Mu Points"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import React from "react";
|
||||||
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
|
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||||
|
|
||||||
|
/** Renders Influential Points (Ba Hui Xue) category details using the shared accordion layout. */
|
||||||
|
export function InfluentialPointsDetailRenderer(props: DetailRendererProps) {
|
||||||
|
return (
|
||||||
|
<YuanSourceDetailRenderer
|
||||||
|
{...props}
|
||||||
|
fallbackTitle="Influential Points"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ScrollView } from "react-native";
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||||
import { asString } from "../helpers/value";
|
|
||||||
import { Hero } from "../shared/Hero";
|
/** Renders Luo-Connecting category details using the shared Overview and expandable Points accordion layout. */
|
||||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
export function LuoConnectingDetailRenderer(props: DetailRendererProps) {
|
||||||
export function LuoConnectingDetailRenderer({content,data,definitions,presentationAttributes}:DetailRendererProps){ return <ScrollView contentContainerStyle={{paddingHorizontal:18,paddingTop:16,paddingBottom:40,gap:14}}><Hero title={asString(data.title)||asString(data.name)||content.title}/><Images data={data}/><PointCodes data={data}/><ObjectArrayCards title="Major Luo Point of the Spleen" value={data.major_luo_point_of_the_spleen}/><ObjectArrayCards title="Major Luo Point of the Stomach" value={data.major_luo_point_of_the_stomach}/><ObjectArrayTable title="Interior-Exterior Related Disorders" value={data.treating_disorders_of_their_interiorly_exteriorly_related_channel_or_zangfu}/><ObjectArrayTable title="Regional Disorders" value={data.treating_disorders_in_regions_reached_b_the_luo_connecting_channel}/><ObjectArrayTable title="Psycho-emotional Disorders" value={data.treating_psycho_emotional_disorders}/><ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/></ScrollView>; }
|
return (
|
||||||
|
<YuanSourceDetailRenderer
|
||||||
|
{...props}
|
||||||
|
fallbackTitle="Luo-Connecting Points"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -1,80 +1,63 @@
|
||||||
import React, { useMemo, useState } from "react";
|
import React, { useMemo } from "react";
|
||||||
import {
|
import { ScrollView, Text, View } from "react-native";
|
||||||
LayoutAnimation,
|
|
||||||
Platform,
|
|
||||||
Pressable,
|
|
||||||
ScrollView,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
UIManager,
|
|
||||||
View,
|
|
||||||
} from "react-native";
|
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
|
||||||
import { useRouter } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
||||||
|
|
||||||
import { Colors, Radius } from "@/theme";
|
|
||||||
import { useSettingsStore } from "@/store/settings.store";
|
import { useSettingsStore } from "@/store/settings.store";
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { useModuleTemplateContentDetailsQuery } from "../../hooks/use-content-queries";
|
import { asRecordArray, asString, asStringArray } from "../helpers/value";
|
||||||
import {
|
|
||||||
buildContentReferenceRoute,
|
|
||||||
parseNavigableContentReference,
|
|
||||||
} from "../../utils/content-reference";
|
|
||||||
import {
|
|
||||||
asRecord,
|
|
||||||
asRecordArray,
|
|
||||||
asString,
|
|
||||||
asStringArray,
|
|
||||||
} from "../helpers/value";
|
|
||||||
import { BulletList } from "../shared/BulletList";
|
import { BulletList } from "../shared/BulletList";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { OverviewCard } from "../shared/OverviewCard";
|
import { OverviewCard } from "../shared/OverviewCard";
|
||||||
import { Images } from "./categoryParts";
|
import { Images } from "./categoryParts";
|
||||||
|
import {
|
||||||
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
|
buildCategoryOverviewParagraphs,
|
||||||
UIManager.setLayoutAnimationEnabledExperimental(true);
|
extractPointRefLabel,
|
||||||
}
|
navigateToPointRef,
|
||||||
|
PointCategoryAccordionCard,
|
||||||
|
pointCategoryStyles,
|
||||||
|
PointLinkChip,
|
||||||
|
type PointsCatalogMap,
|
||||||
|
usePointsCatalogMap,
|
||||||
|
} from "./pointCategoryShared";
|
||||||
|
|
||||||
interface PointItemProps {
|
interface PointItemProps {
|
||||||
key?: React.Key;
|
key?: React.Key;
|
||||||
item: Record<string, unknown>;
|
item: Record<string, unknown>;
|
||||||
defaultExpanded: boolean;
|
defaultExpanded: boolean;
|
||||||
moduleCode: string;
|
moduleCode: string;
|
||||||
pointsCatalogMap?: Map<string, { contentId: string; title: string }>;
|
pointsCatalogMap?: PointsCatalogMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatPointHeading(
|
function formatPointHeading(
|
||||||
meridian: string,
|
primaryLabel: string,
|
||||||
chineseName: string,
|
pointName: string,
|
||||||
pointCode?: string,
|
pointCode?: string,
|
||||||
): string {
|
): string {
|
||||||
const cleanChinese = chineseName.replace(/^\((.*)\)$/, "$1").trim();
|
const cleanName = pointName.replace(/^\((.*)\)$/, "$1").trim();
|
||||||
const cleanCode = (pointCode || "").trim();
|
const cleanCode = (pointCode || "").trim();
|
||||||
|
|
||||||
// Strip meridian abbreviation codes or point codes in parentheses,
|
// Strip meridian abbreviation codes or point codes in parentheses.
|
||||||
// e.g. (ST), (LU-9), (LI), (LV), (LR), (PC), (GB), (HT), etc.
|
const cleanedPrimary = primaryLabel
|
||||||
const cleanedMeridian = meridian
|
|
||||||
.replace(/\s*\(\s*[A-Z]{1,4}(?:[\s\-_]*\d+)?\s*\)\s*/g, " ")
|
.replace(/\s*\(\s*[A-Z]{1,4}(?:[\s\-_]*\d+)?\s*\)\s*/g, " ")
|
||||||
.replace(/\s+/g, " ")
|
.replace(/\s+/g, " ")
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
if (cleanedMeridian) {
|
if (cleanedPrimary) {
|
||||||
parts.push(cleanedMeridian);
|
parts.push(cleanedPrimary);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
cleanCode &&
|
cleanCode &&
|
||||||
!cleanedMeridian.toLowerCase().includes(cleanCode.toLowerCase())
|
!cleanedPrimary.toLowerCase().includes(cleanCode.toLowerCase())
|
||||||
) {
|
) {
|
||||||
parts.push(cleanCode);
|
parts.push(cleanCode);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
cleanChinese &&
|
cleanName &&
|
||||||
!cleanedMeridian.toLowerCase().includes(cleanChinese.toLowerCase())
|
!cleanedPrimary.toLowerCase().includes(cleanName.toLowerCase())
|
||||||
) {
|
) {
|
||||||
parts.push(`(${cleanChinese})`);
|
parts.push(`(${cleanName})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts.join(" ") || "Point";
|
return parts.join(" ") || "Point";
|
||||||
|
|
@ -87,200 +70,88 @@ function PointAccordionCard({
|
||||||
pointsCatalogMap,
|
pointsCatalogMap,
|
||||||
}: PointItemProps) {
|
}: PointItemProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
||||||
|
|
||||||
const meridian = asString(item.meridian).trim();
|
const primaryLabel =
|
||||||
const chineseName = asString(item.chinese_name).trim();
|
asString(item.meridian).trim() ||
|
||||||
|
asString(item.organ).trim() ||
|
||||||
|
asString(item.category).trim();
|
||||||
|
const pointName =
|
||||||
|
asString(item.chinese_name).trim() || asString(item.pinyin_name).trim();
|
||||||
const element = asString(item.element).trim();
|
const element = asString(item.element).trim();
|
||||||
const yinYang = asString(item.yin_yang).trim();
|
const yinYang = asString(item.yin_yang).trim();
|
||||||
|
const connection = asString(item.connection).trim();
|
||||||
const caution = asString(item.caution).trim();
|
const caution = asString(item.caution).trim();
|
||||||
const cautionList = asStringArray(item.caution);
|
const cautionList = asStringArray(item.caution);
|
||||||
|
|
||||||
const actions = asStringArray(item.actions);
|
const actions = asStringArray(item.actions);
|
||||||
const indications = asStringArray(item.indications);
|
const indications = asStringArray(item.indications);
|
||||||
|
|
||||||
// Resolve point reference for linkable button and heading label
|
const pointLabel = extractPointRefLabel(item.point);
|
||||||
const rawPoint = asRecord(item.point);
|
|
||||||
const directRef = parseNavigableContentReference(item.point);
|
|
||||||
|
|
||||||
// Extract candidate point codes/labels: e.g. "LU 9", "LU-9"
|
const title = useMemo(
|
||||||
const pointLabel =
|
() => formatPointHeading(primaryLabel, pointName, pointLabel),
|
||||||
directRef?.label?.trim() ||
|
[primaryLabel, pointName, pointLabel],
|
||||||
asString(rawPoint.label).trim() ||
|
);
|
||||||
(rawPoint.target && typeof rawPoint.target === "object"
|
|
||||||
? asString((rawPoint.target as Record<string, unknown>).source_code).trim()
|
|
||||||
: "") ||
|
|
||||||
"";
|
|
||||||
|
|
||||||
// Format header title: e.g. "Lung LU 9 (Taiyuan)"
|
|
||||||
const title = useMemo(() => {
|
|
||||||
return formatPointHeading(meridian, chineseName, pointLabel);
|
|
||||||
}, [meridian, chineseName, pointLabel]);
|
|
||||||
|
|
||||||
// Construct button display label: e.g. "LU-9 (Taiyuan)" or "LU 9 (Taiyuan)"
|
|
||||||
const pointButtonLabel = useMemo(() => {
|
const pointButtonLabel = useMemo(() => {
|
||||||
const baseCode = pointLabel || "Point Details";
|
const baseCode = pointLabel || "Point Details";
|
||||||
if (chineseName && !baseCode.toLowerCase().includes(chineseName.toLowerCase())) {
|
if (pointName && !baseCode.toLowerCase().includes(pointName.toLowerCase())) {
|
||||||
return `${baseCode} (${chineseName})`;
|
return `${baseCode} (${pointName})`;
|
||||||
}
|
}
|
||||||
return baseCode;
|
return baseCode;
|
||||||
}, [pointLabel, chineseName]);
|
}, [pointLabel, pointName]);
|
||||||
|
|
||||||
// Resolve navigation destination
|
const badges = [element, yinYang, connection].filter(Boolean);
|
||||||
const navigateToPoint = () => {
|
|
||||||
if (directRef) {
|
|
||||||
router.push(buildContentReferenceRoute(directRef) as never);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rawPoint.target && typeof rawPoint.target === "object") {
|
|
||||||
const target = rawPoint.target as Record<string, unknown>;
|
|
||||||
const targetModule = asString(target.module_code).trim() || moduleCode || "m0001";
|
|
||||||
const targetTemplate = asString(target.template_code).trim() || "m0001_ct0003";
|
|
||||||
const contentId = asString(target.content_id).trim();
|
|
||||||
const sourceCode = asString(target.source_code).trim();
|
|
||||||
|
|
||||||
if (contentId) {
|
|
||||||
router.push(
|
|
||||||
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(contentId)}` as never,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: match by catalog map (from m0001_ct0003) using sourceCode or label
|
|
||||||
if (pointsCatalogMap && sourceCode) {
|
|
||||||
const found =
|
|
||||||
pointsCatalogMap.get(sourceCode.toLowerCase()) ||
|
|
||||||
pointsCatalogMap.get(sourceCode.replace(/[- ]/g, "").toLowerCase());
|
|
||||||
if (found) {
|
|
||||||
router.push(
|
|
||||||
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(found.contentId)}` as never,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Secondary fallback matching by pointLabel in catalog
|
|
||||||
if (pointsCatalogMap && pointLabel) {
|
|
||||||
const found =
|
|
||||||
pointsCatalogMap.get(pointLabel.toLowerCase()) ||
|
|
||||||
pointsCatalogMap.get(pointLabel.replace(/[- ]/g, "").toLowerCase());
|
|
||||||
if (found) {
|
|
||||||
router.push(
|
|
||||||
`/modules/${encodeURIComponent(moduleCode || "m0001")}/m0001_ct0003/${encodeURIComponent(found.contentId)}` as never,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggle = () => {
|
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
|
||||||
setExpanded((prev) => !prev);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.card}>
|
<PointCategoryAccordionCard
|
||||||
{/* Accordion Header */}
|
title={title}
|
||||||
<Pressable
|
badges={badges}
|
||||||
accessibilityRole="button"
|
defaultExpanded={defaultExpanded}
|
||||||
accessibilityState={{ expanded }}
|
|
||||||
accessibilityLabel={`${expanded ? "Collapse" : "Expand"} ${title}`}
|
|
||||||
onPress={toggle}
|
|
||||||
style={({ pressed }) => [
|
|
||||||
styles.cardHeader,
|
|
||||||
expanded && styles.cardHeaderExpanded,
|
|
||||||
pressed && styles.pressed,
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
<View style={styles.headerLeft}>
|
|
||||||
<View style={styles.headerAccent} />
|
|
||||||
<Text style={styles.headerTitle} numberOfLines={2}>
|
|
||||||
{title}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={styles.headerRight}>
|
|
||||||
{element ? (
|
|
||||||
<View style={styles.elementBadge}>
|
|
||||||
<Text style={styles.elementBadgeText}>{element}</Text>
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
{yinYang ? (
|
|
||||||
<View style={styles.elementBadge}>
|
|
||||||
<Text style={styles.elementBadgeText}>{yinYang}</Text>
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
<View style={styles.chevron}>
|
|
||||||
<Ionicons
|
|
||||||
name={expanded ? "chevron-up" : "chevron-down"}
|
|
||||||
size={moderateScale(16)}
|
|
||||||
color={Colors.primary}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</Pressable>
|
|
||||||
|
|
||||||
{/* Accordion Body (Expanded State) */}
|
|
||||||
{expanded ? (
|
|
||||||
<View style={styles.cardBody}>
|
|
||||||
{/* Actions */}
|
|
||||||
{actions.length > 0 ? (
|
{actions.length > 0 ? (
|
||||||
<View style={styles.sectionRow}>
|
<View style={pointCategoryStyles.sectionRow}>
|
||||||
<Text style={styles.sectionLabel}>ACTIONS</Text>
|
<Text style={pointCategoryStyles.sectionLabel}>ACTIONS</Text>
|
||||||
{actions.length === 1 ? (
|
{actions.length === 1 ? (
|
||||||
<Text style={styles.sectionValue}>{actions[0]}</Text>
|
<Text style={pointCategoryStyles.sectionValue}>{actions[0]}</Text>
|
||||||
) : (
|
) : (
|
||||||
<BulletList items={actions} />
|
<BulletList items={actions} />
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Indications */}
|
|
||||||
{indications.length > 0 ? (
|
{indications.length > 0 ? (
|
||||||
<View style={styles.sectionRow}>
|
<View style={pointCategoryStyles.sectionRow}>
|
||||||
<Text style={styles.sectionLabel}>INDICATIONS</Text>
|
<Text style={pointCategoryStyles.sectionLabel}>INDICATIONS</Text>
|
||||||
<BulletList items={indications} />
|
<BulletList items={indications} />
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Caution (same UI as Actions and Indications) */}
|
|
||||||
{caution ? (
|
{caution ? (
|
||||||
<View style={styles.sectionRow}>
|
<View style={pointCategoryStyles.sectionRow}>
|
||||||
<Text style={styles.sectionLabel}>CAUTION</Text>
|
<Text style={pointCategoryStyles.sectionLabel}>CAUTION</Text>
|
||||||
{cautionList.length > 1 ? (
|
{cautionList.length > 1 ? (
|
||||||
<BulletList items={cautionList} />
|
<BulletList items={cautionList} />
|
||||||
) : (
|
) : (
|
||||||
<Text style={styles.sectionValue}>{caution}</Text>
|
<Text style={pointCategoryStyles.sectionValue}>{caution}</Text>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Linkable Point Button (matching standard ReferenceChipList styling) */}
|
|
||||||
{pointLabel ? (
|
{pointLabel ? (
|
||||||
<Pressable
|
<View style={pointCategoryStyles.pointLinksRow}>
|
||||||
accessibilityRole="link"
|
<PointLinkChip
|
||||||
accessibilityLabel={`View point ${pointButtonLabel}`}
|
label={pointButtonLabel}
|
||||||
onPress={navigateToPoint}
|
onPress={() =>
|
||||||
style={({ pressed }) => [
|
navigateToPointRef(router, item.point, moduleCode, pointsCatalogMap)
|
||||||
styles.pointLinkButton,
|
}
|
||||||
pressed && styles.pressed,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Text style={styles.pointLinkLabel}>{pointButtonLabel}</Text>
|
|
||||||
<Ionicons
|
|
||||||
name="chevron-forward"
|
|
||||||
size={moderateScale(14)}
|
|
||||||
color={Colors.primaryDark}
|
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
|
||||||
) : null}
|
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
</View>
|
</PointCategoryAccordionCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Shared category detail renderer supporting Yuan-Source, Xi-Cleft, Luo, Back-Shu, Front-Mu, and Influential points. */
|
||||||
export function YuanSourceDetailRenderer({
|
export function YuanSourceDetailRenderer({
|
||||||
moduleCode = "m0001",
|
moduleCode = "m0001",
|
||||||
content,
|
content,
|
||||||
|
|
@ -292,65 +163,40 @@ export function YuanSourceDetailRenderer({
|
||||||
const accordionDefaultExpanded = useSettingsStore(
|
const accordionDefaultExpanded = useSettingsStore(
|
||||||
(state) => state.accordionDefaultExpanded,
|
(state) => state.accordionDefaultExpanded,
|
||||||
);
|
);
|
||||||
|
const pointsCatalogMap = usePointsCatalogMap(moduleCode);
|
||||||
// Fetch points from m0001_ct0003 for robust ID navigation fallback
|
|
||||||
const { data: pointsCatalog } = useModuleTemplateContentDetailsQuery({
|
|
||||||
module_code: moduleCode || "m0001",
|
|
||||||
template_code: "m0001_ct0003",
|
|
||||||
});
|
|
||||||
|
|
||||||
const pointsCatalogMap = useMemo(() => {
|
|
||||||
const map = new Map<string, { contentId: string; title: string }>();
|
|
||||||
if (pointsCatalog?.items) {
|
|
||||||
for (const item of pointsCatalog.items) {
|
|
||||||
const id = item.content.id;
|
|
||||||
const title = item.content.title;
|
|
||||||
const code = asString(item.data.code).trim().toLowerCase();
|
|
||||||
const name = asString(item.data.name).trim().toLowerCase();
|
|
||||||
if (code) {
|
|
||||||
map.set(code, { contentId: id, title });
|
|
||||||
map.set(code.replace(/[- ]/g, ""), { contentId: id, title });
|
|
||||||
}
|
|
||||||
if (name) {
|
|
||||||
map.set(name, { contentId: id, title });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}, [pointsCatalog]);
|
|
||||||
|
|
||||||
const rawTitle =
|
const rawTitle =
|
||||||
asString(data.title) || asString(data.name) || content.title || fallbackTitle;
|
asString(data.title) || asString(data.name) || content.title || fallbackTitle;
|
||||||
const altNames = asStringArray(data.alt_name);
|
const altNames = asStringArray(data.alt_name);
|
||||||
const descriptionParagraphs = asStringArray(data.description);
|
const alias = asString(data.alias).trim();
|
||||||
|
const subtitle =
|
||||||
|
altNames.length > 0 ? altNames.join(" · ") : alias || undefined;
|
||||||
|
|
||||||
|
const overviewParagraphs = useMemo(
|
||||||
|
() => buildCategoryOverviewParagraphs(data),
|
||||||
|
[data],
|
||||||
|
);
|
||||||
const points = asRecordArray(data.points);
|
const points = asRecordArray(data.points);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<ScrollView
|
||||||
contentContainerStyle={styles.container}
|
contentContainerStyle={pointCategoryStyles.container}
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
>
|
>
|
||||||
{/* Screen Title & Subtitle */}
|
<Hero title={rawTitle} subtitle={subtitle} />
|
||||||
<Hero
|
|
||||||
title={rawTitle}
|
|
||||||
subtitle={altNames.length > 0 ? altNames.join(" · ") : undefined}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Visual images (if any assigned) */}
|
|
||||||
<Images data={data} />
|
<Images data={data} />
|
||||||
|
|
||||||
{/* Overview Section */}
|
{overviewParagraphs.length > 0 ? (
|
||||||
{descriptionParagraphs.length > 0 ? (
|
|
||||||
<OverviewCard
|
<OverviewCard
|
||||||
title="Overview"
|
title="Overview"
|
||||||
variant="bullets"
|
variant="bullets"
|
||||||
paragraphs={descriptionParagraphs}
|
paragraphs={overviewParagraphs}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Points Accordion List */}
|
|
||||||
{points.length > 0 ? (
|
{points.length > 0 ? (
|
||||||
<View style={styles.pointsList}>
|
<View style={pointCategoryStyles.cardsList}>
|
||||||
{points.map((pointItem, index) => (
|
{points.map((pointItem, index) => (
|
||||||
<PointAccordionCard
|
<PointAccordionCard
|
||||||
key={index}
|
key={index}
|
||||||
|
|
@ -363,143 +209,12 @@ export function YuanSourceDetailRenderer({
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* Generic content link attributes (excluding points already rendered above) */}
|
|
||||||
<ContentLinkAttributeSections
|
<ContentLinkAttributeSections
|
||||||
data={data}
|
data={data}
|
||||||
definitions={definitions}
|
definitions={definitions}
|
||||||
presentationAttributes={presentationAttributes}
|
presentationAttributes={presentationAttributes}
|
||||||
excludeAttributeKeys={["points", "m0001_ct0009.points", "m0001_ct0011.points"]}
|
excludeAttributeKeys={["points", "pairings"]}
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
paddingHorizontal: moderateScale(16),
|
|
||||||
paddingTop: verticalScale(14),
|
|
||||||
paddingBottom: verticalScale(40),
|
|
||||||
gap: verticalScale(14),
|
|
||||||
},
|
|
||||||
pointsList: {
|
|
||||||
gap: verticalScale(12),
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
borderRadius: moderateScale(16),
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#E2E8F0",
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
cardHeader: {
|
|
||||||
minHeight: verticalScale(54),
|
|
||||||
paddingHorizontal: moderateScale(14),
|
|
||||||
paddingVertical: verticalScale(12),
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
gap: moderateScale(10),
|
|
||||||
},
|
|
||||||
cardHeaderExpanded: {
|
|
||||||
backgroundColor: "#F0F7F3",
|
|
||||||
borderBottomWidth: 1,
|
|
||||||
borderBottomColor: "#E2E8F0",
|
|
||||||
},
|
|
||||||
pressed: {
|
|
||||||
opacity: 0.75,
|
|
||||||
},
|
|
||||||
headerLeft: {
|
|
||||||
flex: 1,
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: moderateScale(10),
|
|
||||||
},
|
|
||||||
headerAccent: {
|
|
||||||
width: moderateScale(4),
|
|
||||||
height: verticalScale(22),
|
|
||||||
borderRadius: moderateScale(2),
|
|
||||||
backgroundColor: Colors.primary,
|
|
||||||
},
|
|
||||||
headerTitle: {
|
|
||||||
flex: 1,
|
|
||||||
fontSize: moderateScale(15),
|
|
||||||
lineHeight: moderateScale(21),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: "#1E293B",
|
|
||||||
},
|
|
||||||
headerRight: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: moderateScale(8),
|
|
||||||
},
|
|
||||||
elementBadge: {
|
|
||||||
paddingHorizontal: moderateScale(9),
|
|
||||||
paddingVertical: verticalScale(3),
|
|
||||||
borderRadius: moderateScale(10),
|
|
||||||
backgroundColor: "#E8F5E9",
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#C6E4CE",
|
|
||||||
},
|
|
||||||
elementBadgeText: {
|
|
||||||
fontSize: 11,
|
|
||||||
lineHeight: 16,
|
|
||||||
fontWeight: "600",
|
|
||||||
color: "#285A44",
|
|
||||||
},
|
|
||||||
chevron: {
|
|
||||||
width: moderateScale(28),
|
|
||||||
height: moderateScale(28),
|
|
||||||
borderRadius: moderateScale(14),
|
|
||||||
backgroundColor: "#FFFFFFB8",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#E2E8F0",
|
|
||||||
},
|
|
||||||
cardBody: {
|
|
||||||
paddingHorizontal: moderateScale(16),
|
|
||||||
paddingTop: verticalScale(14),
|
|
||||||
paddingBottom: verticalScale(16),
|
|
||||||
gap: verticalScale(12),
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
},
|
|
||||||
sectionRow: {
|
|
||||||
gap: verticalScale(6),
|
|
||||||
paddingBottom: verticalScale(10),
|
|
||||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
||||||
borderBottomColor: "#E8ECEF",
|
|
||||||
},
|
|
||||||
sectionLabel: {
|
|
||||||
fontSize: 12,
|
|
||||||
lineHeight: 17,
|
|
||||||
fontWeight: "700",
|
|
||||||
color: "#597064",
|
|
||||||
letterSpacing: 0.15,
|
|
||||||
},
|
|
||||||
sectionValue: {
|
|
||||||
fontSize: 16,
|
|
||||||
lineHeight: 25,
|
|
||||||
color: "#334155",
|
|
||||||
},
|
|
||||||
pointLinkButton: {
|
|
||||||
alignSelf: "flex-start",
|
|
||||||
minHeight: verticalScale(34),
|
|
||||||
paddingHorizontal: moderateScale(12),
|
|
||||||
paddingVertical: verticalScale(6),
|
|
||||||
borderRadius: Radius.full,
|
|
||||||
backgroundColor: "#E8F5E9",
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#CDE5D0",
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: moderateScale(6),
|
|
||||||
marginTop: verticalScale(6),
|
|
||||||
},
|
|
||||||
pointLinkLabel: {
|
|
||||||
fontSize: moderateScale(13),
|
|
||||||
lineHeight: moderateScale(18),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: Colors.primaryDark,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,422 @@
|
||||||
|
import React, { useMemo, useState } from "react";
|
||||||
|
import {
|
||||||
|
LayoutAnimation,
|
||||||
|
Platform,
|
||||||
|
Pressable,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
UIManager,
|
||||||
|
View,
|
||||||
|
} from "react-native";
|
||||||
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
import { useRouter } from "expo-router";
|
||||||
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
|
|
||||||
|
import { Colors, Radius } from "@/theme";
|
||||||
|
import { useModuleTemplateContentDetailsQuery } from "../../hooks/use-content-queries";
|
||||||
|
import {
|
||||||
|
buildContentReferenceRoute,
|
||||||
|
parseNavigableContentReference,
|
||||||
|
} from "../../utils/content-reference";
|
||||||
|
import { asRecord, asString, asStringArray } from "../helpers/value";
|
||||||
|
|
||||||
|
if (
|
||||||
|
Platform.OS === "android" &&
|
||||||
|
UIManager.setLayoutAnimationEnabledExperimental
|
||||||
|
) {
|
||||||
|
UIManager.setLayoutAnimationEnabledExperimental(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PointsCatalogMap = Map<
|
||||||
|
string,
|
||||||
|
{ contentId: string; title: string }
|
||||||
|
>;
|
||||||
|
|
||||||
|
/** Loads m0001_ct0003 points catalog for fallback navigation by point code or name. */
|
||||||
|
export function usePointsCatalogMap(moduleCode = "m0001"): PointsCatalogMap {
|
||||||
|
const { data: pointsCatalog } = useModuleTemplateContentDetailsQuery({
|
||||||
|
module_code: moduleCode || "m0001",
|
||||||
|
template_code: "m0001_ct0003",
|
||||||
|
});
|
||||||
|
|
||||||
|
return useMemo(() => {
|
||||||
|
const map = new Map<string, { contentId: string; title: string }>();
|
||||||
|
if (pointsCatalog?.items) {
|
||||||
|
for (const item of pointsCatalog.items) {
|
||||||
|
const id = item.content.id;
|
||||||
|
const title = item.content.title;
|
||||||
|
const code = asString(item.data.code).trim().toLowerCase();
|
||||||
|
const name = asString(item.data.name).trim().toLowerCase();
|
||||||
|
if (code) {
|
||||||
|
map.set(code, { contentId: id, title });
|
||||||
|
map.set(code.replace(/[- ]/g, ""), { contentId: id, title });
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
map.set(name, { contentId: id, title });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [pointsCatalog]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extracts display label from a point content_ref or raw target payload. */
|
||||||
|
export function extractPointRefLabel(rawValue: unknown): string {
|
||||||
|
const directRef = parseNavigableContentReference(rawValue);
|
||||||
|
if (directRef?.label?.trim()) {
|
||||||
|
return directRef.label.trim();
|
||||||
|
}
|
||||||
|
const rawPoint = asRecord(rawValue);
|
||||||
|
const label = asString(rawPoint.label).trim();
|
||||||
|
if (label) return label;
|
||||||
|
if (rawPoint.target && typeof rawPoint.target === "object") {
|
||||||
|
return asString((rawPoint.target as Record<string, unknown>).source_code).trim();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Navigates to the canonical acupuncture point detail route from a content_ref payload. */
|
||||||
|
export function navigateToPointRef(
|
||||||
|
router: ReturnType<typeof useRouter>,
|
||||||
|
rawValue: unknown,
|
||||||
|
moduleCode: string,
|
||||||
|
pointsCatalogMap?: PointsCatalogMap,
|
||||||
|
): void {
|
||||||
|
const directRef = parseNavigableContentReference(rawValue);
|
||||||
|
if (directRef) {
|
||||||
|
router.push(buildContentReferenceRoute(directRef) as never);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawPoint = asRecord(rawValue);
|
||||||
|
const pointLabel = extractPointRefLabel(rawValue);
|
||||||
|
|
||||||
|
if (rawPoint.target && typeof rawPoint.target === "object") {
|
||||||
|
const target = rawPoint.target as Record<string, unknown>;
|
||||||
|
const targetModule =
|
||||||
|
asString(target.module_code).trim() || moduleCode || "m0001";
|
||||||
|
const targetTemplate =
|
||||||
|
asString(target.template_code).trim() || "m0001_ct0003";
|
||||||
|
const contentId = asString(target.content_id).trim();
|
||||||
|
const sourceCode = asString(target.source_code).trim();
|
||||||
|
|
||||||
|
if (contentId) {
|
||||||
|
router.push(
|
||||||
|
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(contentId)}` as never,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pointsCatalogMap && sourceCode) {
|
||||||
|
const found =
|
||||||
|
pointsCatalogMap.get(sourceCode.toLowerCase()) ||
|
||||||
|
pointsCatalogMap.get(sourceCode.replace(/[- ]/g, "").toLowerCase());
|
||||||
|
if (found) {
|
||||||
|
router.push(
|
||||||
|
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(found.contentId)}` as never,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pointsCatalogMap && pointLabel) {
|
||||||
|
const found =
|
||||||
|
pointsCatalogMap.get(pointLabel.toLowerCase()) ||
|
||||||
|
pointsCatalogMap.get(pointLabel.replace(/[- ]/g, "").toLowerCase());
|
||||||
|
if (found) {
|
||||||
|
router.push(
|
||||||
|
`/modules/${encodeURIComponent(moduleCode || "m0001")}/m0001_ct0003/${encodeURIComponent(found.contentId)}` as never,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatGeneralInfoKey(key: string): string {
|
||||||
|
const trimmed = key.trim();
|
||||||
|
if (trimmed === "Yin_vs_Yang") return "Yin vs. Yang";
|
||||||
|
if (trimmed === "Yuan_vs_Luo") return "Yuan vs. Luo";
|
||||||
|
return trimmed.replace(/_/g, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatGeneralInfoSubLines(
|
||||||
|
value: unknown,
|
||||||
|
indent = "",
|
||||||
|
lines: string[] = [],
|
||||||
|
): string[] {
|
||||||
|
if (typeof value === "string") {
|
||||||
|
const text = value.trim();
|
||||||
|
if (text) lines.push(text);
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
const obj = asRecord(value);
|
||||||
|
const entries = Object.entries(obj);
|
||||||
|
entries.forEach(([k, v], idx) => {
|
||||||
|
const label = formatGeneralInfoKey(k);
|
||||||
|
if (typeof v === "string") {
|
||||||
|
const text = v.trim();
|
||||||
|
if (text) {
|
||||||
|
lines.push(`${indent}${idx + 1}. ${label}: ${text}`);
|
||||||
|
}
|
||||||
|
} else if (v && typeof v === "object") {
|
||||||
|
lines.push(`${indent}${label}:`);
|
||||||
|
formatGeneralInfoSubLines(v, `${indent} `, lines);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Merges description strings and structured general_information into Overview bullet items. */
|
||||||
|
export function buildCategoryOverviewParagraphs(
|
||||||
|
data: Record<string, unknown>,
|
||||||
|
): string[] {
|
||||||
|
const paragraphs = [...asStringArray(data.description)];
|
||||||
|
const generalInfo = asRecord(data.general_information);
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(generalInfo)) {
|
||||||
|
const label = formatGeneralInfoKey(key);
|
||||||
|
if (typeof value === "string") {
|
||||||
|
const text = value.trim();
|
||||||
|
if (text) {
|
||||||
|
paragraphs.push(`${label}: ${text}`);
|
||||||
|
}
|
||||||
|
} else if (value && typeof value === "object") {
|
||||||
|
const subLines = formatGeneralInfoSubLines(value);
|
||||||
|
if (subLines.length > 0) {
|
||||||
|
paragraphs.push(`${label}:\n${subLines.join("\n")}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paragraphs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renders a pill-style navigable chip linking to an acupuncture point detail screen. */
|
||||||
|
export function PointLinkChip({
|
||||||
|
label,
|
||||||
|
accessibilityLabel,
|
||||||
|
onPress,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
accessibilityLabel?: string;
|
||||||
|
onPress: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="link"
|
||||||
|
accessibilityLabel={accessibilityLabel || `View point ${label}`}
|
||||||
|
onPress={onPress}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
pointCategoryStyles.pointLinkButton,
|
||||||
|
pressed && pointCategoryStyles.pressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Text style={pointCategoryStyles.pointLinkLabel}>{label}</Text>
|
||||||
|
<Ionicons
|
||||||
|
name="chevron-forward"
|
||||||
|
size={moderateScale(14)}
|
||||||
|
color={Colors.primaryDark}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reusable expandable accordion card wrapper matching category detail styling. */
|
||||||
|
export function PointCategoryAccordionCard({
|
||||||
|
title,
|
||||||
|
badges = [],
|
||||||
|
defaultExpanded,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
badges?: string[];
|
||||||
|
defaultExpanded: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const [expanded, setExpanded] = useState(defaultExpanded);
|
||||||
|
|
||||||
|
const toggle = () => {
|
||||||
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
||||||
|
setExpanded((prev) => !prev);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={pointCategoryStyles.card}>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityState={{ expanded }}
|
||||||
|
accessibilityLabel={`${expanded ? "Collapse" : "Expand"} ${title}`}
|
||||||
|
onPress={toggle}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
pointCategoryStyles.cardHeader,
|
||||||
|
expanded && pointCategoryStyles.cardHeaderExpanded,
|
||||||
|
pressed && pointCategoryStyles.pressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<View style={pointCategoryStyles.headerLeft}>
|
||||||
|
<View style={pointCategoryStyles.headerAccent} />
|
||||||
|
<Text style={pointCategoryStyles.headerTitle} numberOfLines={2}>
|
||||||
|
{title}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={pointCategoryStyles.headerRight}>
|
||||||
|
{badges
|
||||||
|
.filter((b) => b.trim().length > 0)
|
||||||
|
.map((badge, index) => (
|
||||||
|
<View key={`${badge}-${index}`} style={pointCategoryStyles.badge}>
|
||||||
|
<Text style={pointCategoryStyles.badgeText}>{badge}</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
<View style={pointCategoryStyles.chevron}>
|
||||||
|
<Ionicons
|
||||||
|
name={expanded ? "chevron-up" : "chevron-down"}
|
||||||
|
size={moderateScale(16)}
|
||||||
|
color={Colors.primary}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
{expanded ? (
|
||||||
|
<View style={pointCategoryStyles.cardBody}>{children}</View>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const pointCategoryStyles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
paddingHorizontal: moderateScale(16),
|
||||||
|
paddingTop: verticalScale(14),
|
||||||
|
paddingBottom: verticalScale(40),
|
||||||
|
gap: verticalScale(14),
|
||||||
|
},
|
||||||
|
cardsList: {
|
||||||
|
gap: verticalScale(12),
|
||||||
|
},
|
||||||
|
card: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2E8F0",
|
||||||
|
overflow: "hidden",
|
||||||
|
},
|
||||||
|
cardHeader: {
|
||||||
|
minHeight: verticalScale(54),
|
||||||
|
paddingHorizontal: moderateScale(14),
|
||||||
|
paddingVertical: verticalScale(12),
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
gap: moderateScale(10),
|
||||||
|
},
|
||||||
|
cardHeaderExpanded: {
|
||||||
|
backgroundColor: "#F0F7F3",
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: "#E2E8F0",
|
||||||
|
},
|
||||||
|
pressed: {
|
||||||
|
opacity: 0.75,
|
||||||
|
},
|
||||||
|
headerLeft: {
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: moderateScale(10),
|
||||||
|
},
|
||||||
|
headerAccent: {
|
||||||
|
width: moderateScale(4),
|
||||||
|
height: verticalScale(22),
|
||||||
|
borderRadius: moderateScale(2),
|
||||||
|
backgroundColor: Colors.primary,
|
||||||
|
},
|
||||||
|
headerTitle: {
|
||||||
|
flex: 1,
|
||||||
|
fontSize: moderateScale(15),
|
||||||
|
lineHeight: moderateScale(21),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#1E293B",
|
||||||
|
},
|
||||||
|
headerRight: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
badge: {
|
||||||
|
paddingHorizontal: moderateScale(9),
|
||||||
|
paddingVertical: verticalScale(3),
|
||||||
|
borderRadius: moderateScale(10),
|
||||||
|
backgroundColor: "#E8F5E9",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#C6E4CE",
|
||||||
|
},
|
||||||
|
badgeText: {
|
||||||
|
fontSize: 11,
|
||||||
|
lineHeight: 16,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: "#285A44",
|
||||||
|
},
|
||||||
|
chevron: {
|
||||||
|
width: moderateScale(28),
|
||||||
|
height: moderateScale(28),
|
||||||
|
borderRadius: moderateScale(14),
|
||||||
|
backgroundColor: "#FFFFFFB8",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2E8F0",
|
||||||
|
},
|
||||||
|
cardBody: {
|
||||||
|
paddingHorizontal: moderateScale(16),
|
||||||
|
paddingTop: verticalScale(14),
|
||||||
|
paddingBottom: verticalScale(16),
|
||||||
|
gap: verticalScale(12),
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
},
|
||||||
|
sectionRow: {
|
||||||
|
gap: verticalScale(6),
|
||||||
|
paddingBottom: verticalScale(10),
|
||||||
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
|
borderBottomColor: "#E8ECEF",
|
||||||
|
},
|
||||||
|
sectionLabel: {
|
||||||
|
fontSize: 12,
|
||||||
|
lineHeight: 17,
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#597064",
|
||||||
|
letterSpacing: 0.15,
|
||||||
|
},
|
||||||
|
sectionValue: {
|
||||||
|
fontSize: 16,
|
||||||
|
lineHeight: 25,
|
||||||
|
color: "#334155",
|
||||||
|
},
|
||||||
|
pointLinksRow: {
|
||||||
|
flexDirection: "row",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
gap: moderateScale(8),
|
||||||
|
marginTop: verticalScale(4),
|
||||||
|
},
|
||||||
|
pointLinkButton: {
|
||||||
|
alignSelf: "flex-start",
|
||||||
|
minHeight: verticalScale(34),
|
||||||
|
paddingHorizontal: moderateScale(12),
|
||||||
|
paddingVertical: verticalScale(6),
|
||||||
|
borderRadius: Radius.full,
|
||||||
|
backgroundColor: "#E8F5E9",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#CDE5D0",
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: moderateScale(6),
|
||||||
|
},
|
||||||
|
pointLinkLabel: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: moderateScale(18),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.primaryDark,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -32,6 +32,8 @@ import { FourSeasDetailRenderer } from "./details/FourSeasDetailRenderer";
|
||||||
import { GhostPointsDetailRenderer } from "./details/GhostPointsDetailRenderer";
|
import { GhostPointsDetailRenderer } from "./details/GhostPointsDetailRenderer";
|
||||||
import { EntryExitPointsDetailRenderer } from "./details/EntryExitPointsDetailRenderer";
|
import { EntryExitPointsDetailRenderer } from "./details/EntryExitPointsDetailRenderer";
|
||||||
import { ReturningYangDetailRenderer } from "./details/ReturningYangDetailRenderer";
|
import { ReturningYangDetailRenderer } from "./details/ReturningYangDetailRenderer";
|
||||||
|
import { YuanLuoDetailRenderer } from "./details/YuanLuoDetailRenderer";
|
||||||
|
import { InfluentialPointsDetailRenderer } from "./details/InfluentialPointsDetailRenderer";
|
||||||
import { EarAcupunctureCatalogCollectionRenderer, EarAcupunctureCatalogCardRenderer, EarAcupunctureCollectionRenderer, EarAcupunctureCardRenderer } from "./collections/EarAcupunctureRenderers";
|
import { EarAcupunctureCatalogCollectionRenderer, EarAcupunctureCatalogCardRenderer, EarAcupunctureCollectionRenderer, EarAcupunctureCardRenderer } from "./collections/EarAcupunctureRenderers";
|
||||||
import { EarAcupunctureCatalogDetailRenderer } from "./details/EarAcupunctureCatalogDetailRenderer";
|
import { EarAcupunctureCatalogDetailRenderer } from "./details/EarAcupunctureCatalogDetailRenderer";
|
||||||
import { EarAcupunctureDetailRenderer } from "./details/EarAcupunctureDetailRenderer";
|
import { EarAcupunctureDetailRenderer } from "./details/EarAcupunctureDetailRenderer";
|
||||||
|
|
@ -146,6 +148,8 @@ export const detailRenderers: Readonly<Record<string, DetailRendererComponent>>
|
||||||
ghost_points_detail: GhostPointsDetailRenderer,
|
ghost_points_detail: GhostPointsDetailRenderer,
|
||||||
entry_exit_points_detail: EntryExitPointsDetailRenderer,
|
entry_exit_points_detail: EntryExitPointsDetailRenderer,
|
||||||
returning_yang_detail: ReturningYangDetailRenderer,
|
returning_yang_detail: ReturningYangDetailRenderer,
|
||||||
|
yuan_luo_detail: YuanLuoDetailRenderer,
|
||||||
|
influential_points_detail: InfluentialPointsDetailRenderer,
|
||||||
ear_acupuncture_catalog_detail: EarAcupunctureCatalogDetailRenderer,
|
ear_acupuncture_catalog_detail: EarAcupunctureCatalogDetailRenderer,
|
||||||
ear_acupuncture_detail: EarAcupunctureDetailRenderer,
|
ear_acupuncture_detail: EarAcupunctureDetailRenderer,
|
||||||
four_levels_detail: FourLevelsDetailRenderer,
|
four_levels_detail: FourLevelsDetailRenderer,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue