feat(m0018): implement Twelve Channels drilldown flow and header navigation

This commit is contained in:
ShivaniKhaire 2026-09-26 16:48:43 +05:30
parent fdfc29ba57
commit ef5cc0843c
7 changed files with 1085 additions and 29 deletions

View File

@ -13,6 +13,7 @@ export interface ContentPageHeaderProps {
fallbackRoute?: string;
onTitlePress?: () => void;
titleAccessibilityLabel?: string;
onBack?: () => void;
}
export function ContentPageHeader({
@ -22,8 +23,14 @@ export function ContentPageHeader({
fallbackRoute = "/modules",
onTitlePress,
titleAccessibilityLabel,
onBack,
}: ContentPageHeaderProps) {
const handleBack = () => {
if (onBack) {
onBack();
return;
}
if (router.canGoBack()) {
router.back();
return;

View File

@ -0,0 +1,90 @@
import React from "react";
import { Pressable, StyleSheet, Text, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { moderateScale } from "react-native-size-matters";
import { Colors } from "@/theme";
import { asNumber, asString } from "../helpers/value";
import { CollectionScaffold } from "../shared/CollectionScaffold";
import type {
CollectionItemRendererProps,
CollectionRendererProps,
} from "../../types/renderer.types";
export function TwelveChannelsCollectionRenderer(props: CollectionRendererProps) {
return <CollectionScaffold {...props} />;
}
export function TwelveChannelsCardRenderer({
item,
onPress,
}: CollectionItemRendererProps) {
const a = item.attributes;
const title = asString(a.name) || asString(a.title) || item.title;
const sortOrder = asNumber(a.sort_order);
return (
<Pressable
accessibilityRole="button"
accessibilityLabel={title}
onPress={onPress}
style={({ pressed }) => [styles.cardRow, pressed && styles.pressed]}
>
<View style={styles.numberBadge}>
{typeof sortOrder === "number" ? (
<Text style={styles.numberText}>{sortOrder + 1}</Text>
) : (
<Ionicons name="pulse-outline" size={18} color={Colors.primaryDark} />
)}
</View>
<View style={styles.titleContainer}>
<Text numberOfLines={2} style={styles.cardTitle}>
{title}
</Text>
</View>
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
</Pressable>
);
}
const styles = StyleSheet.create({
cardRow: {
minHeight: moderateScale(60),
flexDirection: "row",
alignItems: "center",
padding: moderateScale(14),
backgroundColor: "#FFFFFF",
borderRadius: moderateScale(14),
borderWidth: 1,
borderColor: "#E2EAE5",
marginBottom: moderateScale(10),
},
pressed: {
opacity: 0.72,
},
numberBadge: {
width: moderateScale(36),
height: moderateScale(36),
borderRadius: moderateScale(18),
backgroundColor: "#E8F5E9",
alignItems: "center",
justifyContent: "center",
},
numberText: {
fontSize: moderateScale(15),
fontWeight: "800",
color: Colors.primaryDark,
},
titleContainer: {
flex: 1,
marginLeft: moderateScale(12),
marginRight: moderateScale(8),
},
cardTitle: {
fontSize: moderateScale(15),
fontWeight: "600",
color: Colors.textPrimary,
},
});

View File

@ -0,0 +1,917 @@
import React, { useContext, useEffect, useMemo, useState } from "react";
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { moderateScale, verticalScale } from "react-native-size-matters";
import { Colors } from "@/theme";
import type { DetailRendererProps } from "../../types/renderer.types";
import { BackActionContext } from "../../screens/SingleTemplateScreen";
import { Hero } from "../shared/Hero";
import { SectionCard } from "../shared/SectionCard";
import { Paragraphs } from "../shared/Paragraphs";
import { asString } from "../helpers/value";
import { useContentSearchInfiniteQuery } from "../../hooks/use-content-search-infinite-query";
interface ConnectingChannelDetails {
empty?: string;
full?: string;
}
interface ChannelData {
name: string;
code?: string;
mainChannel?: string;
connectingChannel?: ConnectingChannelDetails | string;
muscleChannel?: string;
greatConnectingChannelOfSpleen?: string;
}
const FALLBACK_CHANNELS: ChannelData[] = [
{
name: "Lungs",
code: "lungs",
mainChannel:
"Fever, aversion to cold, a feeling of oppression of the chest, pain in the clavicle, shoulders and arms",
connectingChannel: {
empty: "Yawning, frequent urination, shortness of breath.",
full: "Hot palms.",
},
muscleChannel:
"Pain, contraction and sprain of the muscles along the course of the channel, pain and contraction of the muscles of the chest and shoulder.",
},
{
name: "Large Intestine",
code: "large_intestine",
mainChannel:
"Sore throat, toothache, epistaxis, runny nose, swollen and painful gums, swollen eyes, pain along the course of the channel.",
connectingChannel: {
empty: "Sensation of cold in the teeth, feeling of tightness in diaphragm, loss of sense of smell.",
full: "Toothache, deafness, tinnitus, sensation of heat in the centre of the chest, breathlessness.",
},
muscleChannel:
"Pain, stiffness or sprain of the muscles along the course of the channel, inability to raise the arm, inability to rotate the neck, shoulder ache.",
},
{
name: "Stomach",
code: "stomach",
mainChannel:
"Pain in the eyes, epistaxis, swelling of neck, facial paralysis, cold legs and feet, pain along the course of the channel.",
connectingChannel: {
empty: "Flaccidity or atrophy of leg muscles, feeling of cold in the upper teeth.",
full: "Epilepsy, manic behaviour or depression, swollen and sore throat, sudden loss of voice, nosebleed.",
},
muscleChannel:
"Sprain of the middle toe, contraction of the muscles of the lower leg and foot, stiffness of the thigh muscles, swelling in the groin, hernia, spasm of abdominal muscles, strained neck and cheek muscles, deviation of eyes and mouth, inability to close the eye due to muscle spasm, inability to open the eyes due to flaccidity of the muscles.",
greatConnectingChannelOfSpleen: "Palpitations, feeling of fullness of the chest.",
},
{
name: "Spleen",
code: "spleen",
mainChannel:
"Vaginal discharge, cold feeling along the channel, weakness of the leg muscles.",
connectingChannel: {
empty: "Abdominal distension.",
full: "Abdominal pain, food poisoning, vomiting, diarrhoea.",
},
muscleChannel:
"Strain of the big toe, pain in the inner aspect of the ankle, pain in the muscles of the medial aspect of the knee and thigh, strain of the muscles of the groin, strain of the abdominal muscles, pain in the muscles of the chest and middle back.",
greatConnectingChannelOfSpleen:
"Pain all over the body, weakness and flaccidity of the joints of the four limbs, backache radiating to the abdomen.",
},
{
name: "Heart",
code: "heart",
mainChannel:
"Pain in the eyes, pain on the inner side of the arm, pain along the scapula.",
connectingChannel: {
empty: "Aphasia.",
full: "Feeling of distension and fullness of the chest and diaphragm.",
},
muscleChannel:
"Pain, stiffness and sprain of the muscles along the course of the channel.",
},
{
name: "Small Intestine",
code: "small_intestine",
mainChannel:
"Pain in the neck, pain in the elbow, stiff neck, pain along the lateral side of the arm and scapula.",
connectingChannel: {
empty: "Scabies, long, finger-shaped warts.",
full: "Loose joints of the shoulder, weakness of the muscles of the elbow joint.",
},
muscleChannel:
"Stiffness and pain of the muscles of the little finger, arm and elbow, sprain and pain of the muscles of the scapula, pain and sprain of the neck muscles, pain from the ear to the mandible, earache radiating to the chin, swelling of the sides of the neck.",
},
{
name: "Bladder",
code: "bladder",
mainChannel:
"Fever and aversion to cold, headache, stiff neck, pain in the lower back, pain in the eyes, pain behind the leg along the channel.",
connectingChannel: {
empty: "Runny nose, nosebleed.",
full: "Stuffy nose, headache, backache, neck ache, shoulder ache.",
},
muscleChannel:
"Pain and stiffness of the muscles of the little toe, foot, heel, knee and spine, backache and spasm of the back, stiff neck, inability to raise the shoulder, stiffness of the muscles of the axillary region, inability to twist the waist.",
},
{
name: "Kidney",
code: "kidney",
mainChannel: "Pain in the lower back, pain in the sole of the foot.",
connectingChannel: {
empty: "Lower backache.",
full: "Mental restlessness, depression, retention of urine, pain in the heart region, distension and fullness of the chest.",
},
muscleChannel:
"Pain, stiffness and sprain of the muscles of the toes, foot, inner aspect of the ankle, stiffness of the muscles of the spine and neck, inability to bend forward (if the muscles of the back are affected), inability to bend backwards (if the muscles of the chest are affected, convulsions (arching of the back).",
},
{
name: "Pericardium",
code: "pericardium",
mainChannel:
"Stiff neck, pain along the course of the channel, contraction of elbow or hand.",
connectingChannel: {
empty: "Stiffness of head.",
full: "Pain in the heart region, mental restlessness.",
},
muscleChannel:
"Pain, stiffness and sprain of the muscles of the palms, inner aspect of arm, elbow and axilla, pain in the heart region.",
},
{
name: "Triple Burner",
code: "triple_burner",
mainChannel:
"Pain along the course of the channel, pain in the elbow, alternation of chills and fever, deafness, pain and discharge from the ear, pain at the top of the shoulders.",
connectingChannel: {
empty: "Loosening of elbow joint.",
full: "Contraction of elbow, swollen and painful throat, dry mouth, pain of the outer aspect of the arm, inability to raise the arm.",
},
muscleChannel:
"Sprain, stiffness and sprain of the muscles of the ring finger, wrist, elbow, upper arm, shoulder and neck, curling of the tongue.",
},
{
name: "Gall Bladder",
code: "gall_bladder",
mainChannel:
"Alternation of chills and fever, headache, deafness, pain in the hip and lateral side of legs, pain and distension of breasts.",
connectingChannel: {
empty: "Weakness and flaccidity of food muscles, cold feet, paralysis of legs, difficulty in standing.",
full: "Fainting, hypochondrial pain.",
},
muscleChannel:
"Pain, stiffness and sprain of the muscles of the fourth toe, external aspect of the ankle, lateral aspect of leg and knee, difficulty in bending knees, paralysis of the legs, chest and hypochondrial pain, inability to open the eyes.",
},
{
name: "Liver",
code: "liver",
mainChannel: "Headache, pain and swelling of the eye, cramps in the legs.",
connectingChannel: {
empty: "Itching of the genital region, impotence.",
full: "Swelling and pain of testicle, colic, abnormal erection, hernia.",
},
muscleChannel:
"Pain, stiffness and sprain of the muscles of the big toe, inner aspect of the ankle and leg, impotence, contraction of the scrotum or vagina, priapism (persistent erection).",
},
];
const DEFAULT_TWELVE_CHANNELS_OVERVIEW =
"The pattern identification according to the channels is the oldest of the pattern identification methods. It is found in the ‘Spiritual Axis’. Basically, this method of pattern identification allows us to distinguish symptoms and signs according to the involved channel: it is therefore concerned with the pathological changes occurring in the channel rather than the organ.";
const DEFAULT_ORGAN_VERSUS_CHANNEL =
"The organs and their relevant channels form an indivisible energetic unit: problems of the Internal Organs can affect the relevant channels and, conversely, problems that start as channel problems can penetrate into the Interior and be transmitted to the organs.\n\nIt is important, however, to appreciate both the unity and the separation between the organ and the channel. They form a unity, but they are also energetically separate: the channels pertain to what is called the Exterior, i.e. the superficial energetic layers of the body (including skin and muscles), and the organs pertain to the Interior, i.e. the deep energetic layer of the body, including the organs and bones.\n\nIn disease, there can be problems of the channels not affecting the organs and vice versa. It is very important to appreciate (and be able to identify) when a problem is situated in the Exterior and affecting the channels only.";
const DEFAULT_CHANNEL_EXAMPLE =
"If a person has a pain in the shoulder along the Large Intestine channel without any Large Intestine organ symptoms, one can safely conclude that this is a channel problem only, not affecting the Internal Organs. If, on the contrary, a person suffers from chronic diarrhoea over a long period of time with mucus and blood in the stools and, after some years, develops a pain in the shoulder along the Large Intestine channel, then this channel problem is possibly caused by its corresponding Internal Organ disease. However, even in this case there could be an overlap of an Internal Organ problem with a separate invasion of an exterior pathogenic factor in the channel.";
const DEFAULT_FOUR_FACTORS: { num: string; text: string }[] = [
{
num: "1",
text: "First of all, they arise from invasion of exterior pathogenic factors, such as Cold, Wind, or Dampness. These invade the Connecting (Luo) channels first, and then the main channels, settling in the joints and causing Painful Obstruction Syndrome (Bi Syndrome). This is an extremely frequent cause of channel problems which affects most people at one time or another.",
},
{
num: "2",
text: "Channel pathology is, in fact, closely related to joint pathology. Joints in Chinese medicine are more than just anatomical entities: they have an important function with regard to the circulation of Qi and Blood, with several implications in pathology. Joints are places where Qi and Blood concentrate or gather, and they are also the places where Qi goes from the Interior to the Exterior or vice versa. Qi has complex directions of movement, upwards and downwards and in and out, constituting the ascending/descending and entering/exiting of Qi, respectively. The joints are the places along the channels where Qi enters and exits. It is not by chance that many of the major Transporting (Shu) points of the limbs below elbows and knees are situated on joints. As a consequence of this concentration of Qi, the joints are the places where a pathogenic factor easily settles. When a pathogenic factor invades the joint, it alters the balance of Yin and Yang, upsets the circulation of Qi in the channel and causes Qi and Blood to stagnate: this causes pain and in the long run gives rise to Painful Obstruction Syndrome (Bi Syndrome). If the pathogenic factor is associated with Heat, the joint will feel hot; if it is associated with Cold, it will feel cold; if there is Dampness, the joint is swollen; if there is Wind, the pain moves from joint to joint.\nBesides being affected by exterior pathogenic factors, joints are affected by general deficiency of Qi and Blood, which may cause their lack of nourishment and hence weakness.",
},
{
num: "3",
text: "Another frequent cause of channel problems is from overuse of a limb or part of the body, giving rise to local stagnation of Qi. Anyone who, because of their work circumstances, has to constantly repeat the same movements, will be liable to suffer from channel problems, manifesting with local stagnation of Qi. This is a very common cause of repetitive strain injury. Sports injuries are another frequent cause of channel problems, causing local stagnation of Qi in the channel.",
},
{
num: "4",
text: "Finally, channel problems can, of course, spring from Internal Organ disharmonies. The channel pattern identification describes the pathological changes occurring in channels. However, although this is the main aim of this pattern identification, it can be slightly confusing as the symptoms and signs described in the ‘Spiritual Axis’ also include some from the relevant organ and sometimes even from other organs.",
},
];
const DEFAULT_FULL_VS_EMPTY = {
full: "Intense pain, stiffness, contractions and cramps.",
empty: "Dull ache, weakness of the muscles, atrophy of the muscles and numbness.",
};
const DEFAULT_OTHER_CONSIDERATIONS =
"We must also remember that a channel problem can affect the orifices and sense organs and that such problems are not always related to the Internal Organs. For example, the Kidneys open into the ears but not every ear problem is related to the Kidneys. The channel pattern identification is important to identify the affected channel from the symptoms and signs. The clinical manifestations related to the channel itself are therefore more important. Of course, the channel pattern identification needs to be based on a thorough knowledge of the main channels and their deep pathways.";
const DEFAULT_SUMMARY =
"To summarize, if we know the pathway of the channels thoroughly and are able to identify Full or Empty conditions of the channels according to the above guidelines, any clinical manifestation appearing along the channel can be correctly identified.";
function normalizeKey(str: string): string {
return str.toLowerCase().replace(/[^a-z0-9]/g, "");
}
function parseConnectingChannel(val: unknown): ConnectingChannelDetails | string | undefined {
if (!val) return undefined;
if (typeof val === "string") return val;
if (typeof val === "object") {
const obj = val as Record<string, unknown>;
const empty = asString(obj.empty);
const full = asString(obj.full);
if (empty || full) {
return {
empty: empty || undefined,
full: full || undefined,
};
}
}
return undefined;
}
export function TwelveChannelsDetailRenderer({
content,
data,
}: DetailRendererProps) {
const [selectedChannelName, setSelectedChannelName] = useState<string | null>(null);
const { setCustomBackAction } = useContext(BackActionContext);
// Query m0018_ct0002 for dynamic published channel records
const channelsQuery = useContentSearchInfiniteQuery({
module_code: "m0018",
template_code: "m0018_ct0002",
page_size: 50,
logic: "and",
filters: [],
sort: [],
});
// Index channel records for quick lookup and list display
const { channelList, channelMap } = useMemo(() => {
const map = new Map<string, ChannelData>();
const list: ChannelData[] = [];
// 1. Seed fallback channels
for (const ch of FALLBACK_CHANNELS) {
map.set(normalizeKey(ch.name), ch);
if (ch.code) map.set(normalizeKey(ch.code), ch);
list.push(ch);
}
// 2. Overlay live queried items if available
const pages = channelsQuery.data?.pages ?? [];
for (const page of pages) {
for (const item of page.items) {
const a = item.attributes;
const name = asString(a.name) || item.title;
if (!name) continue;
const mainChannel = asString(a.main_channel);
const connectingChannel = parseConnectingChannel(a.connecting_channel);
const muscleChannel = asString(a.muscle_channel);
const greatConnecting = a.great_connecting_channel_of_the_spleen;
let greatConnectingStr: string | undefined;
if (typeof greatConnecting === "object" && greatConnecting !== null) {
greatConnectingStr = asString(
(greatConnecting as Record<string, unknown>).clinical_manifestations,
);
} else if (typeof greatConnecting === "string") {
greatConnectingStr = greatConnecting;
}
const channelData: ChannelData = {
name,
code: asString(a.code) || item.slug,
mainChannel: mainChannel || undefined,
connectingChannel,
muscleChannel: muscleChannel || undefined,
greatConnectingChannelOfSpleen: greatConnectingStr || undefined,
};
const key = normalizeKey(name);
map.set(key, channelData);
if (channelData.code) {
map.set(normalizeKey(channelData.code), channelData);
}
// Replace or append in list
const existingIdx = list.findIndex(
(c) => normalizeKey(c.name) === key || (c.code && channelData.code && c.code === channelData.code),
);
if (existingIdx >= 0) {
list[existingIdx] = { ...list[existingIdx], ...channelData };
} else {
list.push(channelData);
}
}
}
return { channelList: list, channelMap: map };
}, [channelsQuery.data]);
// Check if this component is rendered directly for a single channel leaf (e.g. from search or deep link)
const isDirectLeafChannel = Boolean(
data.main_channel || data.connecting_channel || data.muscle_channel,
);
const activeChannelData: ChannelData | null = useMemo(() => {
if (isDirectLeafChannel) {
const name = asString(data.name) || content.title || "Twelve Channels";
const greatConnecting = data.great_connecting_channel_of_the_spleen;
let greatConnectingStr: string | undefined;
if (typeof greatConnecting === "object" && greatConnecting !== null) {
greatConnectingStr = asString(
(greatConnecting as Record<string, unknown>).clinical_manifestations,
);
} else if (typeof greatConnecting === "string") {
greatConnectingStr = greatConnecting;
}
return {
name,
code: asString(data.code) || undefined,
mainChannel: asString(data.main_channel) || undefined,
connectingChannel: parseConnectingChannel(data.connecting_channel),
muscleChannel: asString(data.muscle_channel) || undefined,
greatConnectingChannelOfSpleen: greatConnectingStr,
};
}
if (!selectedChannelName) return null;
return (
channelMap.get(normalizeKey(selectedChannelName)) || {
name: selectedChannelName,
}
);
}, [isDirectLeafChannel, selectedChannelName, data, content.title, channelMap]);
// Handle header back action
useEffect(() => {
if (isDirectLeafChannel) {
setCustomBackAction(null);
return;
}
if (selectedChannelName) {
setCustomBackAction(() => () => {
setSelectedChannelName(null);
});
} else {
setCustomBackAction(null);
}
return () => {
setCustomBackAction(null);
};
}, [isDirectLeafChannel, selectedChannelName, setCustomBackAction]);
// ----------------------------------------------------
// SCREEN 2: Leaf Node Data (e.g. "Lungs")
// ----------------------------------------------------
if (activeChannelData) {
const connecting = activeChannelData.connectingChannel;
const isConnectingObj =
typeof connecting === "object" && connecting !== null && ("empty" in connecting || "full" in connecting);
return (
<ScrollView
contentContainerStyle={styles.container}
showsVerticalScrollIndicator={false}
>
<Hero title={activeChannelData.name} />
{/* 1. Main Channel Card */}
{activeChannelData.mainChannel ? (
<SectionCard title="Main Channel" defaultExpanded>
<Paragraphs items={[activeChannelData.mainChannel]} />
</SectionCard>
) : null}
{/* 2. Connecting Channel Card */}
{connecting ? (
<SectionCard title="Connecting Channel" defaultExpanded>
{isConnectingObj ? (
<View style={styles.connectingDetailsContainer}>
{(connecting as ConnectingChannelDetails).full ? (
<View style={styles.conditionBlock}>
<View style={styles.conditionHeader}>
<View style={[styles.conditionDot, { backgroundColor: Colors.error || "#EF4444" }]} />
<Text style={styles.conditionTitle}>Full Condition</Text>
</View>
<Text style={styles.conditionText}>
{(connecting as ConnectingChannelDetails).full}
</Text>
</View>
) : null}
{(connecting as ConnectingChannelDetails).empty ? (
<View style={[styles.conditionBlock, { marginTop: moderateScale(10) }]}>
<View style={styles.conditionHeader}>
<View style={[styles.conditionDot, { backgroundColor: "#3B82F6" }]} />
<Text style={styles.conditionTitle}>Empty Condition</Text>
</View>
<Text style={styles.conditionText}>
{(connecting as ConnectingChannelDetails).empty}
</Text>
</View>
) : null}
</View>
) : typeof connecting === "string" ? (
<Paragraphs items={[connecting]} />
) : null}
</SectionCard>
) : null}
{/* 3. Muscle Channel Card */}
{activeChannelData.muscleChannel ? (
<SectionCard title="Muscle Channel" defaultExpanded>
<Paragraphs items={[activeChannelData.muscleChannel]} />
</SectionCard>
) : null}
{/* 4. Great Connecting Channel of the Spleen (if present) */}
{activeChannelData.greatConnectingChannelOfSpleen ? (
<SectionCard title="Great Connecting Channel of the Spleen" defaultExpanded>
<Paragraphs items={[activeChannelData.greatConnectingChannelOfSpleen]} />
</SectionCard>
) : null}
</ScrollView>
);
}
// ----------------------------------------------------
// SCREEN 1: Twelve Channels (Module Root Screen)
// ----------------------------------------------------
// 1. Overview description
const overviewText =
asString(data.description) ||
asString(data.overview) ||
asString(data.content) ||
content.summary ||
DEFAULT_TWELVE_CHANNELS_OVERVIEW;
// 2. Organ vs Channel
let organVsChannelText: string | undefined;
if (data.organ_versus_channel) {
if (typeof data.organ_versus_channel === "object" && data.organ_versus_channel !== null) {
organVsChannelText = asString((data.organ_versus_channel as Record<string, unknown>).content);
} else if (typeof data.organ_versus_channel === "string") {
organVsChannelText = data.organ_versus_channel;
}
}
if (!organVsChannelText) {
organVsChannelText = DEFAULT_ORGAN_VERSUS_CHANNEL;
}
// Channel Problem Example
let channelExampleText: string | undefined;
if (data.channel_problem_examples) {
if (typeof data.channel_problem_examples === "object" && data.channel_problem_examples !== null) {
const exObj = data.channel_problem_examples as Record<string, unknown>;
channelExampleText = asString(exObj.large_Intestine_channel) || asString(Object.values(exObj)[0]);
} else if (typeof data.channel_problem_examples === "string") {
channelExampleText = data.channel_problem_examples;
}
}
if (!channelExampleText) {
channelExampleText = DEFAULT_CHANNEL_EXAMPLE;
}
// 3. Four Factors
const fourFactors: { num: string; text: string }[] = useMemo(() => {
const raw = data.channel_problems_can_arise_from_four_factors;
if (raw && typeof raw === "object") {
const items = Object.entries(raw as Record<string, unknown>)
.map(([k, v]) => ({ num: k, text: asString(v) || "" }))
.filter((item) => item.text.length > 0);
if (items.length > 0) return items;
}
return DEFAULT_FOUR_FACTORS;
}, [data.channel_problems_can_arise_from_four_factors]);
// 4. Full vs Empty Conditions
const fullVsEmpty = useMemo(() => {
const raw = data.full_versus_empty_conditions;
if (raw && typeof raw === "object") {
const obj = raw as Record<string, unknown>;
const full = asString(obj.full_conditions);
const empty = asString(obj.empty_conditions);
if (full || empty) {
return {
full: full || DEFAULT_FULL_VS_EMPTY.full,
empty: empty || DEFAULT_FULL_VS_EMPTY.empty,
};
}
}
return DEFAULT_FULL_VS_EMPTY;
}, [data.full_versus_empty_conditions]);
// 5. Other Considerations
let otherConsiderationsText: string | undefined;
if (data.other_considerations) {
if (typeof data.other_considerations === "object" && data.other_considerations !== null) {
otherConsiderationsText = asString((data.other_considerations as Record<string, unknown>).content);
} else if (typeof data.other_considerations === "string") {
otherConsiderationsText = data.other_considerations;
}
}
if (!otherConsiderationsText) {
otherConsiderationsText = DEFAULT_OTHER_CONSIDERATIONS;
}
// 6. Summary
const summaryText = asString(data.summary) || DEFAULT_SUMMARY;
return (
<ScrollView
contentContainerStyle={styles.container}
showsVerticalScrollIndicator={false}
>
<Hero title="Twelve Channels" />
{/* 1. Overview Card */}
{overviewText ? (
<View style={styles.overviewCard}>
<View style={styles.overviewHeader}>
<Ionicons name="information-circle" size={20} color={Colors.primary} />
<Text style={styles.overviewTitle}>Overview</Text>
</View>
<Text style={styles.overviewText}>{overviewText}</Text>
</View>
) : null}
{/* 2. Organ vs Channel Card */}
{organVsChannelText ? (
<View style={styles.infoCard}>
<View style={styles.infoHeader}>
<Ionicons name="git-compare-outline" size={18} color={Colors.primaryDark} />
<Text style={styles.infoTitle}>Organ versus Channel</Text>
</View>
<Text style={styles.infoText}>{organVsChannelText}</Text>
{/* Example callout if present */}
{channelExampleText ? (
<View style={styles.exampleBox}>
<View style={styles.exampleHeader}>
<Ionicons name="bulb-outline" size={16} color="#0284C7" />
<Text style={styles.exampleTitle}>Example (Large Intestine Channel)</Text>
</View>
<Text style={styles.exampleText}>{channelExampleText}</Text>
</View>
) : null}
</View>
) : null}
{/* 3. Four Factors Causing Channel Problems */}
{fourFactors.length > 0 ? (
<View style={styles.infoCard}>
<View style={styles.infoHeader}>
<Ionicons name="layers-outline" size={18} color={Colors.primaryDark} />
<Text style={styles.infoTitle}>Channel problems can arise from four factors</Text>
</View>
<View style={styles.factorsList}>
{fourFactors.map((factor) => (
<View key={factor.num} style={styles.factorItem}>
<View style={styles.factorBadge}>
<Text style={styles.factorBadgeText}>{factor.num}</Text>
</View>
<View style={styles.factorContent}>
<Text style={styles.factorText}>{factor.text}</Text>
</View>
</View>
))}
</View>
</View>
) : null}
{/* 4. Full vs Empty Conditions */}
{fullVsEmpty ? (
<View style={styles.infoCard}>
<View style={styles.infoHeader}>
<Ionicons name="swap-vertical-outline" size={18} color={Colors.primaryDark} />
<Text style={styles.infoTitle}>Full versus Empty Conditions</Text>
</View>
<View style={styles.conditionBlocksContainer}>
{fullVsEmpty.full ? (
<View style={styles.conditionCard}>
<View style={styles.conditionCardHeader}>
<View style={[styles.conditionDot, { backgroundColor: "#EF4444" }]} />
<Text style={styles.conditionCardTitle}>Full Conditions</Text>
</View>
<Text style={styles.conditionCardText}>{fullVsEmpty.full}</Text>
</View>
) : null}
{fullVsEmpty.empty ? (
<View style={styles.conditionCard}>
<View style={styles.conditionCardHeader}>
<View style={[styles.conditionDot, { backgroundColor: "#3B82F6" }]} />
<Text style={styles.conditionCardTitle}>Empty Conditions</Text>
</View>
<Text style={styles.conditionCardText}>{fullVsEmpty.empty}</Text>
</View>
) : null}
</View>
</View>
) : null}
{/* 5. Other Considerations */}
{otherConsiderationsText ? (
<View style={styles.infoCard}>
<View style={styles.infoHeader}>
<Ionicons name="alert-circle-outline" size={18} color={Colors.primaryDark} />
<Text style={styles.infoTitle}>Other Considerations</Text>
</View>
<Text style={styles.infoText}>{otherConsiderationsText}</Text>
</View>
) : null}
{/* 6. Summary Card */}
{summaryText ? (
<View style={styles.summaryCard}>
<View style={styles.summaryHeader}>
<Ionicons name="checkmark-done-circle-outline" size={18} color={Colors.primaryDark} />
<Text style={styles.summaryTitle}>Summary</Text>
</View>
<Text style={styles.summaryText}>{summaryText}</Text>
</View>
) : null}
{/* 7. Twelve Channels List (1 to 12) */}
<View style={styles.channelsContainer}>
<Text style={styles.sectionHeading}>Twelve Channels</Text>
{channelList.map((ch, idx) => (
<Pressable
key={ch.name}
accessibilityRole="button"
accessibilityLabel={`Open ${ch.name}`}
onPress={() => setSelectedChannelName(ch.name)}
style={({ pressed }) => [styles.channelRow, pressed && styles.pressed]}
>
<View style={styles.numberBadge}>
<Text style={styles.numberText}>{idx + 1}</Text>
</View>
<View style={styles.channelTitleContainer}>
<Text style={styles.channelTitle}>{ch.name}</Text>
</View>
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
</Pressable>
))}
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
paddingHorizontal: moderateScale(16),
paddingTop: verticalScale(14),
paddingBottom: verticalScale(36),
},
overviewCard: {
backgroundColor: "#F0FDF4",
borderRadius: moderateScale(14),
borderWidth: 1,
borderColor: "#DCFCE7",
padding: moderateScale(16),
marginBottom: verticalScale(14),
},
overviewHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: moderateScale(8),
gap: moderateScale(6),
},
overviewTitle: {
fontSize: moderateScale(15),
fontWeight: "700",
color: Colors.primaryDark,
},
overviewText: {
fontSize: moderateScale(14),
color: Colors.textSecondary,
lineHeight: moderateScale(21),
},
infoCard: {
backgroundColor: "#FFFFFF",
borderRadius: moderateScale(14),
borderWidth: 1,
borderColor: "#E5E7EB",
padding: moderateScale(14),
marginBottom: verticalScale(14),
},
infoHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: moderateScale(8),
gap: moderateScale(6),
},
infoTitle: {
fontSize: moderateScale(14),
fontWeight: "700",
color: Colors.textPrimary,
},
infoText: {
fontSize: moderateScale(13),
color: Colors.textSecondary,
lineHeight: moderateScale(20),
},
exampleBox: {
marginTop: moderateScale(10),
backgroundColor: "#F0F9FF",
borderRadius: moderateScale(10),
borderWidth: 1,
borderColor: "#BAE6FD",
padding: moderateScale(12),
},
exampleHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: moderateScale(4),
gap: moderateScale(6),
},
exampleTitle: {
fontSize: moderateScale(13),
fontWeight: "700",
color: "#0369A1",
},
exampleText: {
fontSize: moderateScale(12.5),
color: "#334155",
lineHeight: moderateScale(18),
},
factorsList: {
marginTop: moderateScale(6),
gap: moderateScale(10),
},
factorItem: {
flexDirection: "row",
alignItems: "flex-start",
gap: moderateScale(10),
},
factorBadge: {
width: moderateScale(24),
height: moderateScale(24),
borderRadius: moderateScale(12),
backgroundColor: "#E0F2FE",
alignItems: "center",
justifyContent: "center",
marginTop: moderateScale(2),
},
factorBadgeText: {
fontSize: moderateScale(12),
fontWeight: "800",
color: "#0284C7",
},
factorContent: {
flex: 1,
},
factorText: {
fontSize: moderateScale(13),
color: Colors.textSecondary,
lineHeight: moderateScale(19),
},
conditionBlocksContainer: {
marginTop: moderateScale(6),
gap: moderateScale(8),
},
conditionCard: {
backgroundColor: "#F9FAFB",
borderRadius: moderateScale(10),
borderWidth: 1,
borderColor: "#E5E7EB",
padding: moderateScale(10),
},
conditionCardHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: moderateScale(4),
gap: moderateScale(6),
},
conditionCardTitle: {
fontSize: moderateScale(13),
fontWeight: "700",
color: Colors.textPrimary,
},
conditionCardText: {
fontSize: moderateScale(12.5),
color: Colors.textSecondary,
lineHeight: moderateScale(18),
},
summaryCard: {
backgroundColor: "#F8FAFC",
borderRadius: moderateScale(14),
borderWidth: 1,
borderColor: "#E2E8F0",
padding: moderateScale(14),
marginBottom: verticalScale(14),
},
summaryHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: moderateScale(6),
gap: moderateScale(6),
},
summaryTitle: {
fontSize: moderateScale(14),
fontWeight: "700",
color: Colors.primaryDark,
},
summaryText: {
fontSize: moderateScale(13),
fontStyle: "italic",
color: Colors.textSecondary,
lineHeight: moderateScale(19),
},
channelsContainer: {
marginTop: verticalScale(6),
gap: verticalScale(8),
},
sectionHeading: {
fontSize: moderateScale(16),
fontWeight: "700",
color: Colors.textPrimary,
marginBottom: verticalScale(8),
},
channelRow: {
minHeight: moderateScale(56),
flexDirection: "row",
alignItems: "center",
paddingVertical: moderateScale(10),
paddingHorizontal: moderateScale(14),
backgroundColor: "#FFFFFF",
borderRadius: moderateScale(14),
borderWidth: 1,
borderColor: "#E2EAE5",
},
pressed: {
opacity: 0.72,
backgroundColor: "#F9FAFB",
},
numberBadge: {
width: moderateScale(34),
height: moderateScale(34),
borderRadius: moderateScale(17),
backgroundColor: "#E8F5E9",
alignItems: "center",
justifyContent: "center",
},
numberText: {
fontSize: moderateScale(14),
fontWeight: "800",
color: Colors.primaryDark,
},
channelTitleContainer: {
flex: 1,
marginLeft: moderateScale(12),
marginRight: moderateScale(8),
},
channelTitle: {
fontSize: moderateScale(15),
fontWeight: "600",
color: Colors.textPrimary,
},
connectingDetailsContainer: {
gap: moderateScale(6),
},
conditionBlock: {
backgroundColor: "#F9FAFB",
borderRadius: moderateScale(10),
padding: moderateScale(12),
borderWidth: 1,
borderColor: "#E5E7EB",
},
conditionHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: moderateScale(4),
gap: moderateScale(6),
},
conditionDot: {
width: moderateScale(8),
height: moderateScale(8),
borderRadius: moderateScale(4),
},
conditionTitle: {
fontSize: moderateScale(13),
fontWeight: "700",
color: Colors.textPrimary,
},
conditionText: {
fontSize: moderateScale(13),
color: Colors.textSecondary,
lineHeight: moderateScale(19),
},
});

View File

@ -36,6 +36,8 @@ import { EightPrinciplesDetailRenderer } from "./details/EightPrinciplesDetailRe
import { FourLevelsCollectionRenderer, FourLevelsCardRenderer } from "./collections/FourLevelsRenderers";
import { PathogenicFactorsCollectionRenderer, PathogenicFactorsCardRenderer } from "./collections/PathogenicFactorsRenderers";
import { PathogenicFactorsDetailRenderer } from "./details/PathogenicFactorsDetailRenderer";
import { TwelveChannelsCollectionRenderer, TwelveChannelsCardRenderer } from "./collections/TwelveChannelsRenderers";
import { TwelveChannelsDetailRenderer } from "./details/TwelveChannelsDetailRenderer";
export const collectionRenderers: Readonly<Record<string, CollectionRendererComponent>> = Object.freeze({
module_catalog_collection: ModuleCatalogCollectionRenderer,
@ -58,6 +60,8 @@ export const collectionRenderers: Readonly<Record<string, CollectionRendererComp
m0016_ct0001_collection: FourLevelsCollectionRenderer,
m0011_ct0005_collection: EightPrinciplesCollectionRenderer,
m0014_ct0001_collection: PathogenicFactorsCollectionRenderer,
twelve_channels_collection: TwelveChannelsCollectionRenderer,
m0018_ct0002_collection: TwelveChannelsCollectionRenderer,
});
export const collectionItemRenderers: Readonly<Record<string, CollectionItemRendererComponent>> = Object.freeze({
module_catalog_card: ModuleCatalogCardRenderer,
@ -80,6 +84,8 @@ export const collectionItemRenderers: Readonly<Record<string, CollectionItemRend
m0016_ct0001_card: FourLevelsCardRenderer,
m0011_ct0005_card: EightPrinciplesCardRenderer,
m0014_ct0001_card: PathogenicFactorsCardRenderer,
twelve_channels_card: TwelveChannelsCardRenderer,
m0018_ct0002_card: TwelveChannelsCardRenderer,
});
export const detailRenderers: Readonly<Record<string, DetailRendererComponent>> = Object.freeze({
module_catalog_detail: IndexEntryDetailRenderer,
@ -126,6 +132,10 @@ export const detailRenderers: Readonly<Record<string, DetailRendererComponent>>
m0011_ct0005_detail: EightPrinciplesDetailRenderer,
m0014_ct0001_detail: PathogenicFactorsDetailRenderer,
m0014_ct0002_detail: PathogenicFactorsDetailRenderer,
twelve_channels_detail: TwelveChannelsDetailRenderer,
twelve_channels_connecting_and_muscle_channel_detail: TwelveChannelsDetailRenderer,
m0018_ct0001_detail: TwelveChannelsDetailRenderer,
m0018_ct0002_detail: TwelveChannelsDetailRenderer,
});
function reportMissingRenderer(kind: string, code?: string | null) {
if (__DEV__) {
@ -168,6 +178,9 @@ export function resolveCollectionRenderer(
if (normalizedTemplate === "m0014_ct0001" || normalizedModule === "m0014") {
return PathogenicFactorsCollectionRenderer;
}
if (normalizedTemplate === "m0018_ct0002" || (normalizedModule === "m0018" && normalizedTemplate?.includes("ct0002"))) {
return TwelveChannelsCollectionRenderer;
}
if (code && collectionRenderers[code]) return collectionRenderers[code];
reportMissingRenderer("collection", code);
@ -195,6 +208,9 @@ export function resolveCollectionItemRenderer(
if (normalizedTemplate === "m0014_ct0001" || normalizedModule === "m0014") {
return PathogenicFactorsCardRenderer;
}
if (normalizedTemplate === "m0018_ct0002" || (normalizedModule === "m0018" && normalizedTemplate?.includes("ct0002"))) {
return TwelveChannelsCardRenderer;
}
if (code && collectionItemRenderers[code]) return collectionItemRenderers[code];
reportMissingRenderer("collection-item", code);
@ -236,6 +252,12 @@ export function resolveDetailRenderer(
) {
return PathogenicFactorsDetailRenderer;
}
if (
normalizedTemplate?.startsWith("m0018_") ||
normalizedModule === "m0018"
) {
return TwelveChannelsDetailRenderer;
}
if (code && detailRenderers[code]) return detailRenderers[code];
reportMissingRenderer("detail", code);

View File

@ -11,9 +11,10 @@ import { useModuleDisplayName } from "../../hooks/use-module-display-name";
interface DetailPageShellProps extends PropsWithChildren {
title: string;
subtitle?: string;
onBack?: () => void;
}
export function DetailPageShell({ children }: DetailPageShellProps) {
export function DetailPageShell({ children, onBack }: DetailPageShellProps) {
const [isFavorite, setIsFavorite] = useState(false);
const { moduleCode } = useLocalSearchParams<{ moduleCode?: string }>();
const currentModuleCode = typeof moduleCode === "string" ? moduleCode : "";
@ -53,6 +54,7 @@ export function DetailPageShell({ children }: DetailPageShellProps) {
<SafeAreaView style={styles.screen} edges={["top", "left", "right"]}>
<ContentPageHeader
title={moduleDisplay.name}
onBack={onBack}
onTitlePress={
currentModuleCode
? () => router.push(moduleDisplay.homeRoute as never)

View File

@ -1,13 +1,22 @@
import React, { useMemo } from "react";
import React, { createContext, useMemo, useState } from "react";
import { ContentMediaProvider } from "../media/ContentMediaContext";
import { ScreenEmpty, ScreenError, ScreenLoading } from "../components/ContentScreenState";
import { useSingleTemplateContentQuery } from "../hooks/use-single-template-content-query";
import { GenericDetailRenderer } from "../renderers/GenericDetailRenderer";
import { resolveDetailRenderer } from "../renderers/registry";
import { RendererFallbackBoundary } from "../renderers/shared/RendererFallbackBoundary";
import { DetailPageShell } from "../renderers/shared/DetailPageShell";
import { applyPresentationContractToData } from "../utils/attribute-presentation";
import type { TemplateContractResponse } from "../types/presentation.types";
export interface BackActionContextType {
setCustomBackAction: (action: (() => void) | null) => void;
}
export const BackActionContext = createContext<BackActionContextType>({
setCustomBackAction: () => {},
});
export function SingleTemplateScreen({
moduleCode,
templateCode,
@ -17,6 +26,7 @@ export function SingleTemplateScreen({
templateCode: string;
contract: TemplateContractResponse;
}) {
const [customBack, setCustomBack] = useState<(() => void) | null>(null);
const query = useSingleTemplateContentQuery({ moduleCode, templateCode });
const rendererCode = contract.presentation.renderers.detail;
@ -57,32 +67,36 @@ export function SingleTemplateScreen({
const presentedData = applyPresentationContractToData(data, presentationAttributes);
return (
<ContentMediaProvider media={media}>
<RendererFallbackBoundary
rendererKind="detail"
rendererCode={rendererCode}
fallback={
<GenericDetailRenderer
moduleCode={moduleCode}
templateCode={templateCode}
contentId={content.id}
content={content}
data={presentedData}
definitions={[]}
presentationAttributes={presentationAttributes}
/>
}
>
<Renderer
moduleCode={moduleCode}
templateCode={templateCode}
contentId={content.id}
content={content}
data={presentedData}
definitions={[]}
presentationAttributes={presentationAttributes}
/>
</RendererFallbackBoundary>
</ContentMediaProvider>
<DetailPageShell title={content.title || moduleCode} onBack={customBack ?? undefined}>
<BackActionContext.Provider value={{ setCustomBackAction: setCustomBack }}>
<ContentMediaProvider media={media}>
<RendererFallbackBoundary
rendererKind="detail"
rendererCode={rendererCode}
fallback={
<GenericDetailRenderer
moduleCode={moduleCode}
templateCode={templateCode}
contentId={content.id}
content={content}
data={presentedData}
definitions={[]}
presentationAttributes={presentationAttributes}
/>
}
>
<Renderer
moduleCode={moduleCode}
templateCode={templateCode}
contentId={content.id}
content={content}
data={presentedData}
definitions={[]}
presentationAttributes={presentationAttributes}
/>
</RendererFallbackBoundary>
</ContentMediaProvider>
</BackActionContext.Provider>
</DetailPageShell>
);
}

View File

@ -92,6 +92,7 @@ const MODULE_VISUALS: Record<string, ModuleVisualConfig> = {
color: "#06B6D4",
isDefaultFree: false,
planCode: "PATTERN_CORE",
entryTemplateCode: "m0018_ct0001",
},
m0019: {
icon: "flower-outline",
@ -176,6 +177,9 @@ export function resolveModuleCategory(module: ModuleResponse): string {
}
export function resolveModuleEntryTemplateCode(module: ModuleResponse): string {
const visual = MODULE_VISUALS[module.code.toLowerCase()];
if (visual?.entryTemplateCode) return visual.entryTemplateCode.toLowerCase();
const defaultTemplateCode = asNonBlankString(module.default_template_code);
if (defaultTemplateCode) return defaultTemplateCode.toLowerCase();