Compare commits
No commits in common. "feat/xi-cleft-and-point-category-ui" and "main" have entirely different histories.
feat/xi-cl
...
main
|
|
@ -1,13 +1,8 @@
|
|||
import React from "react";
|
||||
import { ScrollView } from "react-native";
|
||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||
|
||||
/** Renders Back-Shu category details using the shared Overview and expandable Points accordion layout. */
|
||||
export function BackShuDetailRenderer(props: DetailRendererProps) {
|
||||
return (
|
||||
<YuanSourceDetailRenderer
|
||||
{...props}
|
||||
fallbackTitle="Back-Shu Points"
|
||||
/>
|
||||
);
|
||||
}
|
||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||
import { asString } from "../helpers/value";
|
||||
import { Hero } from "../shared/Hero";
|
||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
||||
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>; }
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
import React from "react";
|
||||
import { ScrollView } from "react-native";
|
||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||
|
||||
/** Renders Front-Mu category details using the shared Overview and expandable Points accordion layout. */
|
||||
export function FrontMuDetailRenderer(props: DetailRendererProps) {
|
||||
return (
|
||||
<YuanSourceDetailRenderer
|
||||
{...props}
|
||||
fallbackTitle="Front-Mu Points"
|
||||
/>
|
||||
);
|
||||
}
|
||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||
import { asString } from "../helpers/value";
|
||||
import { Hero } from "../shared/Hero";
|
||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
||||
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>; }
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
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,13 +1,8 @@
|
|||
import React from "react";
|
||||
import { ScrollView } from "react-native";
|
||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||
|
||||
/** Renders Luo-Connecting category details using the shared Overview and expandable Points accordion layout. */
|
||||
export function LuoConnectingDetailRenderer(props: DetailRendererProps) {
|
||||
return (
|
||||
<YuanSourceDetailRenderer
|
||||
{...props}
|
||||
fallbackTitle="Luo-Connecting Points"
|
||||
/>
|
||||
);
|
||||
}
|
||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||
import { asString } from "../helpers/value";
|
||||
import { Hero } from "../shared/Hero";
|
||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
||||
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>; }
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import React from "react";
|
||||
import { ScrollView } from "react-native";
|
||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||
import { YuanSourceDetailRenderer } from "./YuanSourceDetailRenderer";
|
||||
|
||||
/** Renders Xi-Cleft category details using the shared Overview and expandable Points accordion layout. */
|
||||
export function XiCleftDetailRenderer(props: DetailRendererProps) {
|
||||
return <YuanSourceDetailRenderer {...props} fallbackTitle="Xi Cleft" />;
|
||||
}
|
||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||
import { asString } from "../helpers/value";
|
||||
import { Hero } from "../shared/Hero";
|
||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
||||
export function XiCleftDetailRenderer({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="Xi-Cleft Points of the Twelve Channels" value={data.xi_cleft_points_of_the_twelve_channels}/><ObjectArrayTable title="Xi-Cleft Points of Extraordinary Channels" value={data.xi_cleft_points_of_extraordinary_channels}/><ObjectCard title="Clinical Application" value={data.clinical_application}/><ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/></ScrollView>; }
|
||||
|
|
|
|||
|
|
@ -1,248 +0,0 @@
|
|||
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,66 +1,68 @@
|
|||
import React, { useMemo } from "react";
|
||||
import { ScrollView, Text, View } from "react-native";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import {
|
||||
LayoutAnimation,
|
||||
Platform,
|
||||
Pressable,
|
||||
ScrollView,
|
||||
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 { useSettingsStore } from "@/store/settings.store";
|
||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||
import { asRecordArray, asString, asStringArray } from "../helpers/value";
|
||||
import { useModuleTemplateContentDetailsQuery } from "../../hooks/use-content-queries";
|
||||
import {
|
||||
buildContentReferenceRoute,
|
||||
parseNavigableContentReference,
|
||||
} from "../../utils/content-reference";
|
||||
import {
|
||||
asRecord,
|
||||
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";
|
||||
|
||||
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
|
||||
UIManager.setLayoutAnimationEnabledExperimental(true);
|
||||
}
|
||||
|
||||
interface PointItemProps {
|
||||
key?: React.Key;
|
||||
item: Record<string, unknown>;
|
||||
defaultExpanded: boolean;
|
||||
moduleCode: string;
|
||||
pointsCatalogMap?: PointsCatalogMap;
|
||||
pointsCatalogMap?: Map<string, { contentId: string; title: string }>;
|
||||
}
|
||||
|
||||
function formatPointHeading(
|
||||
primaryLabel: string,
|
||||
pointName: string,
|
||||
pointCode?: string,
|
||||
): string {
|
||||
const cleanName = pointName.replace(/^\((.*)\)$/, "$1").trim();
|
||||
const cleanCode = (pointCode || "").trim();
|
||||
function sanitizeMeridianHeading(meridian: string, chineseName: string): string {
|
||||
const cleanChinese = chineseName.replace(/^\((.*)\)$/, "$1").trim();
|
||||
|
||||
// Strip meridian abbreviation codes or point codes in parentheses.
|
||||
const cleanedPrimary = primaryLabel
|
||||
// Strip meridian abbreviation codes or point codes in parentheses,
|
||||
// e.g. (ST), (LU-9), (LI), (LV), (LR), (PC), (GB), (HT), etc.
|
||||
const cleanedMeridian = meridian
|
||||
.replace(/\s*\(\s*[A-Z]{1,4}(?:[\s\-_]*\d+)?\s*\)\s*/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
|
||||
const parts: string[] = [];
|
||||
if (cleanedPrimary) {
|
||||
parts.push(cleanedPrimary);
|
||||
}
|
||||
if (
|
||||
cleanCode &&
|
||||
!cleanedPrimary.toLowerCase().includes(cleanCode.toLowerCase())
|
||||
) {
|
||||
parts.push(cleanCode);
|
||||
}
|
||||
if (
|
||||
cleanName &&
|
||||
!cleanedPrimary.toLowerCase().includes(cleanName.toLowerCase())
|
||||
) {
|
||||
parts.push(`(${cleanName})`);
|
||||
if (cleanedMeridian && cleanChinese) {
|
||||
if (cleanedMeridian.toLowerCase().includes(cleanChinese.toLowerCase())) {
|
||||
return cleanedMeridian;
|
||||
}
|
||||
return `${cleanedMeridian} (${cleanChinese})`;
|
||||
}
|
||||
|
||||
return parts.join(" ") || "Point";
|
||||
return cleanedMeridian || cleanChinese || "Point";
|
||||
}
|
||||
|
||||
function PointAccordionCard({
|
||||
|
|
@ -70,133 +72,262 @@ function PointAccordionCard({
|
|||
pointsCatalogMap,
|
||||
}: PointItemProps) {
|
||||
const router = useRouter();
|
||||
const [expanded, setExpanded] = useState(defaultExpanded);
|
||||
|
||||
const primaryLabel =
|
||||
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 meridian = asString(item.meridian).trim();
|
||||
const chineseName = asString(item.chinese_name).trim();
|
||||
const element = asString(item.element).trim();
|
||||
const yinYang = asString(item.yin_yang).trim();
|
||||
const connection = asString(item.connection).trim();
|
||||
const caution = asString(item.caution).trim();
|
||||
const cautionList = asStringArray(item.caution);
|
||||
|
||||
const actions = asStringArray(item.actions);
|
||||
const indications = asStringArray(item.indications);
|
||||
|
||||
const pointLabel = extractPointRefLabel(item.point);
|
||||
// Format header title: e.g. "Stomach (Chongyang)", "Lung (Taiyuan)"
|
||||
const title = useMemo(() => {
|
||||
return sanitizeMeridianHeading(meridian, chineseName);
|
||||
}, [meridian, chineseName]);
|
||||
|
||||
const title = useMemo(
|
||||
() => formatPointHeading(primaryLabel, pointName, pointLabel),
|
||||
[primaryLabel, pointName, pointLabel],
|
||||
);
|
||||
// Resolve point reference for linkable button
|
||||
const rawPoint = asRecord(item.point);
|
||||
const directRef = parseNavigableContentReference(item.point);
|
||||
|
||||
// Extract candidate point codes/labels: e.g. "LU 9", "LU-9"
|
||||
const pointLabel =
|
||||
directRef?.label?.trim() ||
|
||||
asString(rawPoint.label).trim() ||
|
||||
(rawPoint.target && typeof rawPoint.target === "object"
|
||||
? asString((rawPoint.target as Record<string, unknown>).source_code).trim()
|
||||
: "") ||
|
||||
"";
|
||||
|
||||
// Construct button display label: e.g. "LU-9 (Taiyuan)" or "LU 9 (Taiyuan)"
|
||||
const pointButtonLabel = useMemo(() => {
|
||||
const baseCode = pointLabel || "Point Details";
|
||||
if (pointName && !baseCode.toLowerCase().includes(pointName.toLowerCase())) {
|
||||
return `${baseCode} (${pointName})`;
|
||||
if (chineseName && !baseCode.toLowerCase().includes(chineseName.toLowerCase())) {
|
||||
return `${baseCode} (${chineseName})`;
|
||||
}
|
||||
return baseCode;
|
||||
}, [pointLabel, pointName]);
|
||||
}, [pointLabel, chineseName]);
|
||||
|
||||
const badges = [element, yinYang, connection].filter(Boolean);
|
||||
// Resolve navigation destination
|
||||
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 (
|
||||
<PointCategoryAccordionCard
|
||||
title={title}
|
||||
badges={badges}
|
||||
defaultExpanded={defaultExpanded}
|
||||
>
|
||||
{actions.length > 0 ? (
|
||||
<View style={pointCategoryStyles.sectionRow}>
|
||||
<Text style={pointCategoryStyles.sectionLabel}>ACTIONS</Text>
|
||||
{actions.length === 1 ? (
|
||||
<Text style={pointCategoryStyles.sectionValue}>{actions[0]}</Text>
|
||||
) : (
|
||||
<BulletList items={actions} />
|
||||
)}
|
||||
<View style={styles.card}>
|
||||
{/* Accordion Header */}
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
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>
|
||||
) : null}
|
||||
|
||||
{indications.length > 0 ? (
|
||||
<View style={pointCategoryStyles.sectionRow}>
|
||||
<Text style={pointCategoryStyles.sectionLabel}>INDICATIONS</Text>
|
||||
<BulletList items={indications} />
|
||||
<View style={styles.headerRight}>
|
||||
{element ? (
|
||||
<View style={styles.elementBadge}>
|
||||
<Text style={styles.elementBadgeText}>{element}</Text>
|
||||
</View>
|
||||
) : null}
|
||||
<View style={styles.chevron}>
|
||||
<Ionicons
|
||||
name={expanded ? "chevron-up" : "chevron-down"}
|
||||
size={moderateScale(16)}
|
||||
color={Colors.primary}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
) : null}
|
||||
</Pressable>
|
||||
|
||||
{caution ? (
|
||||
<View style={pointCategoryStyles.sectionRow}>
|
||||
<Text style={pointCategoryStyles.sectionLabel}>CAUTION</Text>
|
||||
{cautionList.length > 1 ? (
|
||||
<BulletList items={cautionList} />
|
||||
) : (
|
||||
<Text style={pointCategoryStyles.sectionValue}>{caution}</Text>
|
||||
)}
|
||||
</View>
|
||||
) : null}
|
||||
{/* Accordion Body (Expanded State) */}
|
||||
{expanded ? (
|
||||
<View style={styles.cardBody}>
|
||||
{/* Actions */}
|
||||
{actions.length > 0 ? (
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionLabel}>ACTIONS</Text>
|
||||
{actions.length === 1 ? (
|
||||
<Text style={styles.sectionValue}>{actions[0]}</Text>
|
||||
) : (
|
||||
<BulletList items={actions} />
|
||||
)}
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{pointLabel ? (
|
||||
<View style={pointCategoryStyles.pointLinksRow}>
|
||||
<PointLinkChip
|
||||
label={pointButtonLabel}
|
||||
onPress={() =>
|
||||
navigateToPointRef(router, item.point, moduleCode, pointsCatalogMap)
|
||||
}
|
||||
/>
|
||||
{/* Indications */}
|
||||
{indications.length > 0 ? (
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionLabel}>INDICATIONS</Text>
|
||||
<BulletList items={indications} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* Caution (same UI as Actions and Indications) */}
|
||||
{caution ? (
|
||||
<View style={styles.sectionRow}>
|
||||
<Text style={styles.sectionLabel}>CAUTION</Text>
|
||||
{cautionList.length > 1 ? (
|
||||
<BulletList items={cautionList} />
|
||||
) : (
|
||||
<Text style={styles.sectionValue}>{caution}</Text>
|
||||
)}
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* Linkable Point Button (matching standard ReferenceChipList styling) */}
|
||||
{pointLabel ? (
|
||||
<Pressable
|
||||
accessibilityRole="link"
|
||||
accessibilityLabel={`View point ${pointButtonLabel}`}
|
||||
onPress={navigateToPoint}
|
||||
style={({ pressed }) => [
|
||||
styles.pointLinkButton,
|
||||
pressed && styles.pressed,
|
||||
]}
|
||||
>
|
||||
<Text style={styles.pointLinkLabel}>{pointButtonLabel}</Text>
|
||||
<Ionicons
|
||||
name="chevron-forward"
|
||||
size={moderateScale(14)}
|
||||
color={Colors.primaryDark}
|
||||
/>
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
) : null}
|
||||
</PointCategoryAccordionCard>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
/** Shared category detail renderer supporting Yuan-Source, Xi-Cleft, Luo, Back-Shu, Front-Mu, and Influential points. */
|
||||
export function YuanSourceDetailRenderer({
|
||||
moduleCode = "m0001",
|
||||
content,
|
||||
data,
|
||||
definitions,
|
||||
presentationAttributes,
|
||||
fallbackTitle = "Yuan Source",
|
||||
}: DetailRendererProps & { fallbackTitle?: string }) {
|
||||
}: DetailRendererProps) {
|
||||
const accordionDefaultExpanded = useSettingsStore(
|
||||
(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 =
|
||||
asString(data.title) || asString(data.name) || content.title || fallbackTitle;
|
||||
asString(data.title) || asString(data.name) || content.title || "Yuan Source";
|
||||
const altNames = asStringArray(data.alt_name);
|
||||
const alias = asString(data.alias).trim();
|
||||
const subtitle =
|
||||
altNames.length > 0 ? altNames.join(" · ") : alias || undefined;
|
||||
|
||||
const overviewParagraphs = useMemo(
|
||||
() => buildCategoryOverviewParagraphs(data),
|
||||
[data],
|
||||
);
|
||||
const descriptionParagraphs = asStringArray(data.description);
|
||||
const points = asRecordArray(data.points);
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
contentContainerStyle={pointCategoryStyles.container}
|
||||
contentContainerStyle={styles.container}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<Hero title={rawTitle} subtitle={subtitle} />
|
||||
{/* Screen Title & Subtitle */}
|
||||
<Hero
|
||||
title={rawTitle}
|
||||
subtitle={altNames.length > 0 ? altNames.join(" · ") : undefined}
|
||||
/>
|
||||
|
||||
{/* Visual images (if any assigned) */}
|
||||
<Images data={data} />
|
||||
|
||||
{overviewParagraphs.length > 0 ? (
|
||||
{/* Overview Section */}
|
||||
{descriptionParagraphs.length > 0 ? (
|
||||
<OverviewCard
|
||||
title="Overview"
|
||||
variant="bullets"
|
||||
paragraphs={overviewParagraphs}
|
||||
paragraphs={descriptionParagraphs}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{/* Points Accordion List */}
|
||||
{points.length > 0 ? (
|
||||
<View style={pointCategoryStyles.cardsList}>
|
||||
<View style={styles.pointsList}>
|
||||
{points.map((pointItem, index) => (
|
||||
<PointAccordionCard
|
||||
key={index}
|
||||
|
|
@ -209,12 +340,143 @@ export function YuanSourceDetailRenderer({
|
|||
</View>
|
||||
) : null}
|
||||
|
||||
{/* Generic content link attributes (excluding points already rendered above) */}
|
||||
<ContentLinkAttributeSections
|
||||
data={data}
|
||||
definitions={definitions}
|
||||
presentationAttributes={presentationAttributes}
|
||||
excludeAttributeKeys={["points", "pairings"]}
|
||||
excludeAttributeKeys={["points", "m0001_ct0009.points"]}
|
||||
/>
|
||||
</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,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,422 +0,0 @@
|
|||
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,8 +32,6 @@ import { FourSeasDetailRenderer } from "./details/FourSeasDetailRenderer";
|
|||
import { GhostPointsDetailRenderer } from "./details/GhostPointsDetailRenderer";
|
||||
import { EntryExitPointsDetailRenderer } from "./details/EntryExitPointsDetailRenderer";
|
||||
import { ReturningYangDetailRenderer } from "./details/ReturningYangDetailRenderer";
|
||||
import { YuanLuoDetailRenderer } from "./details/YuanLuoDetailRenderer";
|
||||
import { InfluentialPointsDetailRenderer } from "./details/InfluentialPointsDetailRenderer";
|
||||
import { EarAcupunctureCatalogCollectionRenderer, EarAcupunctureCatalogCardRenderer, EarAcupunctureCollectionRenderer, EarAcupunctureCardRenderer } from "./collections/EarAcupunctureRenderers";
|
||||
import { EarAcupunctureCatalogDetailRenderer } from "./details/EarAcupunctureCatalogDetailRenderer";
|
||||
import { EarAcupunctureDetailRenderer } from "./details/EarAcupunctureDetailRenderer";
|
||||
|
|
@ -148,8 +146,6 @@ export const detailRenderers: Readonly<Record<string, DetailRendererComponent>>
|
|||
ghost_points_detail: GhostPointsDetailRenderer,
|
||||
entry_exit_points_detail: EntryExitPointsDetailRenderer,
|
||||
returning_yang_detail: ReturningYangDetailRenderer,
|
||||
yuan_luo_detail: YuanLuoDetailRenderer,
|
||||
influential_points_detail: InfluentialPointsDetailRenderer,
|
||||
ear_acupuncture_catalog_detail: EarAcupunctureCatalogDetailRenderer,
|
||||
ear_acupuncture_detail: EarAcupunctureDetailRenderer,
|
||||
four_levels_detail: FourLevelsDetailRenderer,
|
||||
|
|
|
|||
|
|
@ -1,60 +1,16 @@
|
|||
import React from "react";
|
||||
import {
|
||||
StyleProp,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TextStyle,
|
||||
View,
|
||||
ViewStyle,
|
||||
} from "react-native";
|
||||
import { StyleSheet, Text, View } from "react-native";
|
||||
|
||||
import { Colors } from "@/theme";
|
||||
|
||||
export interface BulletListProps {
|
||||
items: string[];
|
||||
listStyle?: StyleProp<ViewStyle>;
|
||||
dotStyle?: StyleProp<ViewStyle>;
|
||||
textStyle?: StyleProp<TextStyle>;
|
||||
boldColonPrefix?: boolean;
|
||||
}
|
||||
|
||||
const COLON_PREFIX_RE = /^([A-Za-z][A-Za-z0-9 &/().-]{1,32}:)([\s\S]*)$/;
|
||||
|
||||
function renderBulletText(
|
||||
item: string,
|
||||
textStyle?: StyleProp<TextStyle>,
|
||||
boldColonPrefix?: boolean,
|
||||
) {
|
||||
if (!boldColonPrefix) {
|
||||
return <Text style={[styles.text, textStyle]}>{item}</Text>;
|
||||
}
|
||||
const match = COLON_PREFIX_RE.exec(item);
|
||||
if (!match) {
|
||||
return <Text style={[styles.text, textStyle]}>{item}</Text>;
|
||||
}
|
||||
return (
|
||||
<Text style={[styles.text, textStyle]}>
|
||||
<Text style={styles.prefix}>{match[1]}</Text>
|
||||
{match[2]}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
/** Renders a bulleted list with optional custom typography and bold label prefixes. */
|
||||
export function BulletList({
|
||||
items,
|
||||
listStyle,
|
||||
dotStyle,
|
||||
textStyle,
|
||||
boldColonPrefix = false,
|
||||
}: BulletListProps) {
|
||||
export function BulletList({ items }: { items: string[] }) {
|
||||
if (!items.length) return null;
|
||||
return (
|
||||
<View style={[styles.list, listStyle]}>
|
||||
<View style={styles.list}>
|
||||
{items.map((item, index) => (
|
||||
<View key={`${index}-${item}`} style={styles.row}>
|
||||
<View style={[styles.dot, dotStyle]} />
|
||||
{renderBulletText(item, textStyle, boldColonPrefix)}
|
||||
<View style={styles.dot} />
|
||||
<Text style={styles.text}>{item}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
|
|
@ -72,5 +28,4 @@ const styles = StyleSheet.create({
|
|||
backgroundColor: Colors.primary,
|
||||
},
|
||||
text: { flex: 1, fontSize: 16, lineHeight: 25, color: "#334155" },
|
||||
prefix: { fontWeight: "700", color: Colors.textPrimary },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import { Ionicons } from "@expo/vector-icons";
|
|||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||
|
||||
import { Colors } from "@/theme";
|
||||
import { BulletList } from "./BulletList";
|
||||
|
||||
export interface OverviewCardProps {
|
||||
title?: string;
|
||||
|
|
@ -20,8 +19,6 @@ export interface OverviewCardProps {
|
|||
iconSize?: number;
|
||||
text?: string | null;
|
||||
paragraphs?: Array<string | null | undefined>;
|
||||
variant?: "paragraphs" | "bullets";
|
||||
boldBulletPrefix?: boolean;
|
||||
children?: React.ReactNode;
|
||||
style?: StyleProp<ViewStyle>;
|
||||
titleStyle?: StyleProp<TextStyle>;
|
||||
|
|
@ -35,16 +32,14 @@ export function OverviewCard({
|
|||
iconSize = moderateScale(20),
|
||||
text,
|
||||
paragraphs,
|
||||
variant = "paragraphs",
|
||||
boldBulletPrefix = true,
|
||||
children,
|
||||
style,
|
||||
titleStyle,
|
||||
textStyle,
|
||||
}: OverviewCardProps) {
|
||||
const filteredParagraphs = paragraphs
|
||||
?.filter((p): p is string => typeof p === "string" && p.trim().length > 0)
|
||||
.map((p) => p.replace(/\n[ \t]+/g, "\n").trim());
|
||||
const filteredParagraphs = paragraphs?.filter(
|
||||
(p): p is string => typeof p === "string" && p.trim().length > 0,
|
||||
);
|
||||
|
||||
const hasText = typeof text === "string" && text.trim().length > 0;
|
||||
const hasParagraphs =
|
||||
|
|
@ -67,27 +62,19 @@ export function OverviewCard({
|
|||
<Text style={[styles.text, textStyle]}>{text}</Text>
|
||||
) : null}
|
||||
|
||||
{hasParagraphs && variant === "bullets" ? (
|
||||
<BulletList
|
||||
items={filteredParagraphs}
|
||||
listStyle={[styles.bulletList, hasText && styles.paragraphSpacing]}
|
||||
dotStyle={styles.bulletDot}
|
||||
textStyle={[styles.text, textStyle]}
|
||||
boldColonPrefix={boldBulletPrefix}
|
||||
/>
|
||||
) : hasParagraphs ? (
|
||||
filteredParagraphs.map((para, index) => (
|
||||
<Text
|
||||
key={index}
|
||||
style={[
|
||||
index === 0 && !hasText ? styles.text : styles.paragraph,
|
||||
textStyle,
|
||||
]}
|
||||
>
|
||||
{para}
|
||||
</Text>
|
||||
))
|
||||
) : null}
|
||||
{hasParagraphs
|
||||
? filteredParagraphs.map((para, index) => (
|
||||
<Text
|
||||
key={index}
|
||||
style={[
|
||||
index === 0 && !hasText ? styles.text : styles.paragraph,
|
||||
textStyle,
|
||||
]}
|
||||
>
|
||||
{para}
|
||||
</Text>
|
||||
))
|
||||
: null}
|
||||
|
||||
{children}
|
||||
</View>
|
||||
|
|
@ -124,17 +111,5 @@ const styles = StyleSheet.create({
|
|||
color: Colors.textSecondary,
|
||||
marginTop: verticalScale(8),
|
||||
},
|
||||
paragraphSpacing: {
|
||||
marginTop: verticalScale(8),
|
||||
},
|
||||
bulletList: {
|
||||
gap: verticalScale(7),
|
||||
},
|
||||
bulletDot: {
|
||||
width: moderateScale(5),
|
||||
height: moderateScale(5),
|
||||
borderRadius: moderateScale(2.5),
|
||||
marginTop: moderateScale(7.5),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue