feat(mobile): render direct overview and patterns list in four levels with bullet points for treatment and explanation #75

Merged
amit merged 2 commits from four-levels-of-patterns into main 2026-10-22 07:59:30 +00:00
1 changed files with 267 additions and 10 deletions

View File

@ -1,14 +1,70 @@
import React from "react";
import { ScrollView, StyleSheet } from "react-native";
import { Pressable, ScrollView, StyleSheet, Text, 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 } from "@/theme";
import type { DetailRendererProps } from "../../types/renderer.types";
import {
buildContentReferenceRoute,
parseNavigableContentReference,
} from "../../utils/content-reference";
import { asRecord, asString, asStringArray } from "../helpers/value";
import { BulletList } from "../shared/BulletList";
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
import { Hero } from "../shared/Hero";
import { BulletList } from "../shared/BulletList";
import { Paragraphs } from "../shared/Paragraphs";
import { SectionCard } from "../shared/SectionCard";
import { asString, asStringArray } from "../helpers/value";
function parseExplanationBullets(value: unknown): string[] {
if (!value) return [];
if (Array.isArray(value)) {
return value.map(asString).filter(Boolean);
}
const str = asString(value);
if (!str) return [];
if (str.includes("\n")) {
return str
.split(/\n+/)
.map((s) => s.trim().replace(/^\t+/, ""))
.filter(Boolean);
}
const regex =
/(?<=[^\s:,\+])(?<!\band)\s+(?=(?:(?:[A-Z]{2,4}-\d+|RN-\d+|DU-\d+|REN-\d+)(?:[,\s]+(?:[A-Z]{2,4}-\d+|RN-\d+|DU-\d+|REN-\d+))*(?:\s*(?:and|\+)\s*(?:[A-Z]{2,4}-\d+|RN-\d+|DU-\d+|REN-\d+))?(?:\s*\([^)]*\))?:\s*|Cupping\b|Moxa\b))/i;
const parts = str
.split(regex)
.map((s) => s.trim().replace(/^\t+/, ""))
.filter(Boolean);
return parts.length > 0 ? parts : [str];
}
function parseTreatmentBullets(value: unknown): string[] {
if (!value) return [];
if (Array.isArray(value)) {
return value.map(asString).filter(Boolean);
}
const str = asString(value);
if (!str) return [];
if (str.includes("\n")) {
return str
.split(/\n+/)
.map((s) => s.trim().replace(/^\t+/, ""))
.filter(Boolean);
}
const items = str
.split(/,\s*(?![^()]*\))/)
.map((s) => s.trim().replace(/\.$/, ""))
.filter(Boolean);
return items.length > 0 ? items : [str];
}
export function FourLevelsDetailRenderer({
content,
@ -16,12 +72,17 @@ export function FourLevelsDetailRenderer({
definitions,
presentationAttributes,
}: DetailRendererProps) {
const router = useRouter();
const title =
asString(data.name) ||
asString(data.title) ||
content.title;
const overview = asString(data.overview);
const rawPatterns = Array.isArray(data.patterns) ? data.patterns : [];
const hasPatterns = rawPatterns.length > 0;
const clinicalManifestationsRaw =
data.clinical_manifestation ??
data.clinical_manifestations ??
@ -36,9 +97,102 @@ export function FourLevelsDetailRenderer({
asString(data.treatment_principle) ||
asString(data["treatment principle"]);
const treatment = asString(data.treatment);
const treatmentBullets = parseTreatmentBullets(treatment);
const explanation = asString(data.explanation);
const explanationBullets = parseExplanationBullets(explanation);
const contentText = asString(data.content);
if (hasPatterns) {
return (
<ScrollView
contentContainerStyle={styles.content}
showsVerticalScrollIndicator={false}
>
<Hero title={title} />
{/* Direct Overview Card matching Four Levels 1st page */}
{overview ? (
<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}>{overview}</Text>
</View>
) : null}
{/* Patterns List with numbered cards matching 1st page */}
<View style={styles.patternsSection}>
<View style={styles.sectionHeaderRow}>
<Text style={styles.sectionHeading}>Patterns</Text>
<View style={styles.countBadge}>
<Text style={styles.countBadgeText}>
{rawPatterns.length} {rawPatterns.length === 1 ? "pattern" : "patterns"}
</Text>
</View>
</View>
<View style={styles.patternsList}>
{rawPatterns.map((item, idx) => {
const reference = parseNavigableContentReference(item);
const raw = asRecord(item);
const patternTitle =
reference?.label?.trim() ||
asString(raw?.label) ||
asString(raw?.name) ||
`Pattern ${idx + 1}`;
const handlePress = () => {
if (reference) {
router.push(buildContentReferenceRoute(reference) as never);
} else if (raw && typeof raw.target === "object" && raw.target !== null) {
const target = raw.target as Record<string, unknown>;
const mod = asString(target.module_code);
const tpl = asString(target.template_code);
const cid = asString(target.content_id);
if (mod && tpl && cid) {
router.push(
`/modules/${encodeURIComponent(mod)}/${encodeURIComponent(tpl)}/${encodeURIComponent(cid)}` as never,
);
}
}
};
return (
<View key={idx} style={styles.patternCard}>
<Pressable
accessibilityRole="button"
accessibilityLabel={`Open ${patternTitle}`}
onPress={handlePress}
style={({ pressed }) => [styles.patternRow, pressed && styles.pressed]}
>
<View style={styles.iconWrapper}>
<Text style={styles.levelNumber}>{idx + 1}</Text>
</View>
<View style={styles.textContainer}>
<Text style={styles.title}>{patternTitle}</Text>
<Text style={styles.description}>pattern</Text>
</View>
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
</Pressable>
</View>
);
})}
</View>
</View>
<ContentLinkAttributeSections
data={data}
definitions={definitions}
presentationAttributes={presentationAttributes}
excludeAttributeKeys={["patterns", "m0016_ct0003.patterns"]}
/>
</ScrollView>
);
}
return (
<ScrollView
contentContainerStyle={styles.content}
@ -84,13 +238,21 @@ export function FourLevelsDetailRenderer({
{treatment ? (
<SectionCard title="Treatment">
<Paragraphs items={[treatment]} />
{treatmentBullets.length > 0 ? (
<BulletList items={treatmentBullets} />
) : (
<Paragraphs items={[treatment]} />
)}
</SectionCard>
) : null}
{explanation ? (
<SectionCard title="Explanation">
<Paragraphs items={[explanation]} />
{explanationBullets.length > 0 ? (
<BulletList items={explanationBullets} />
) : (
<Paragraphs items={[explanation]} />
)}
</SectionCard>
) : null}
@ -111,9 +273,104 @@ export function FourLevelsDetailRenderer({
const styles = StyleSheet.create({
content: {
paddingHorizontal: 18,
paddingTop: 16,
paddingBottom: 40,
gap: 14,
paddingHorizontal: moderateScale(16),
paddingTop: verticalScale(14),
paddingBottom: verticalScale(40),
gap: verticalScale(14),
},
overviewCard: {
backgroundColor: "#FFFFFF",
borderRadius: moderateScale(16),
borderWidth: 1,
borderColor: "#E2EAE5",
padding: moderateScale(16),
},
overviewHeader: {
flexDirection: "row",
alignItems: "center",
marginBottom: verticalScale(8),
gap: moderateScale(8),
},
overviewTitle: {
fontSize: moderateScale(16),
fontWeight: "700",
color: Colors.textPrimary,
},
overviewText: {
fontSize: moderateScale(13),
lineHeight: verticalScale(19),
color: Colors.textSecondary,
},
patternsSection: {
gap: verticalScale(10),
},
sectionHeaderRow: {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
paddingHorizontal: moderateScale(4),
},
sectionHeading: {
fontSize: moderateScale(15),
fontWeight: "700",
color: Colors.textPrimary,
},
countBadge: {
backgroundColor: "#E8F5E9",
paddingHorizontal: moderateScale(10),
paddingVertical: verticalScale(4),
borderRadius: moderateScale(12),
},
countBadgeText: {
fontSize: moderateScale(12),
fontWeight: "600",
color: Colors.primaryDark,
},
patternsList: {
gap: verticalScale(12),
},
patternCard: {
backgroundColor: "#FFFFFF",
borderRadius: moderateScale(18),
borderWidth: 1,
borderColor: "#E2EAE5",
overflow: "hidden",
},
patternRow: {
minHeight: moderateScale(68),
flexDirection: "row",
alignItems: "center",
padding: moderateScale(14),
},
pressed: {
opacity: 0.72,
},
iconWrapper: {
width: moderateScale(40),
height: moderateScale(40),
borderRadius: moderateScale(20),
justifyContent: "center",
alignItems: "center",
backgroundColor: "#E8F5E9",
},
levelNumber: {
fontSize: moderateScale(16),
fontWeight: "800",
color: Colors.primaryDark,
},
textContainer: {
flex: 1,
marginLeft: moderateScale(12),
marginRight: moderateScale(10),
},
title: {
fontSize: moderateScale(15),
fontWeight: "600",
color: Colors.textPrimary,
marginBottom: verticalScale(2),
},
description: {
fontSize: moderateScale(12),
color: Colors.textSecondary,
},
});