Compare commits
No commits in common. "e7854ceb938ecff2afd89b2b2e6f617255d22420" and "8f9caa1c39050be0cb6cf84f997a4b0e24290575" have entirely different histories.
e7854ceb93
...
8f9caa1c39
|
|
@ -1,70 +1,14 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
import { ScrollView, StyleSheet } 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 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 { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
|
import { BulletList } from "../shared/BulletList";
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
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({
|
export function FourLevelsDetailRenderer({
|
||||||
content,
|
content,
|
||||||
|
|
@ -72,17 +16,12 @@ export function FourLevelsDetailRenderer({
|
||||||
definitions,
|
definitions,
|
||||||
presentationAttributes,
|
presentationAttributes,
|
||||||
}: DetailRendererProps) {
|
}: DetailRendererProps) {
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const title =
|
const title =
|
||||||
asString(data.name) ||
|
asString(data.name) ||
|
||||||
asString(data.title) ||
|
asString(data.title) ||
|
||||||
content.title;
|
content.title;
|
||||||
|
|
||||||
const overview = asString(data.overview);
|
const overview = asString(data.overview);
|
||||||
const rawPatterns = Array.isArray(data.patterns) ? data.patterns : [];
|
|
||||||
const hasPatterns = rawPatterns.length > 0;
|
|
||||||
|
|
||||||
const clinicalManifestationsRaw =
|
const clinicalManifestationsRaw =
|
||||||
data.clinical_manifestation ??
|
data.clinical_manifestation ??
|
||||||
data.clinical_manifestations ??
|
data.clinical_manifestations ??
|
||||||
|
|
@ -97,102 +36,9 @@ export function FourLevelsDetailRenderer({
|
||||||
asString(data.treatment_principle) ||
|
asString(data.treatment_principle) ||
|
||||||
asString(data["treatment principle"]);
|
asString(data["treatment principle"]);
|
||||||
const treatment = asString(data.treatment);
|
const treatment = asString(data.treatment);
|
||||||
const treatmentBullets = parseTreatmentBullets(treatment);
|
|
||||||
const explanation = asString(data.explanation);
|
const explanation = asString(data.explanation);
|
||||||
const explanationBullets = parseExplanationBullets(explanation);
|
|
||||||
const contentText = asString(data.content);
|
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 (
|
return (
|
||||||
<ScrollView
|
<ScrollView
|
||||||
contentContainerStyle={styles.content}
|
contentContainerStyle={styles.content}
|
||||||
|
|
@ -238,21 +84,13 @@ export function FourLevelsDetailRenderer({
|
||||||
|
|
||||||
{treatment ? (
|
{treatment ? (
|
||||||
<SectionCard title="Treatment">
|
<SectionCard title="Treatment">
|
||||||
{treatmentBullets.length > 0 ? (
|
|
||||||
<BulletList items={treatmentBullets} />
|
|
||||||
) : (
|
|
||||||
<Paragraphs items={[treatment]} />
|
<Paragraphs items={[treatment]} />
|
||||||
)}
|
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{explanation ? (
|
{explanation ? (
|
||||||
<SectionCard title="Explanation">
|
<SectionCard title="Explanation">
|
||||||
{explanationBullets.length > 0 ? (
|
|
||||||
<BulletList items={explanationBullets} />
|
|
||||||
) : (
|
|
||||||
<Paragraphs items={[explanation]} />
|
<Paragraphs items={[explanation]} />
|
||||||
)}
|
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
@ -273,104 +111,9 @@ export function FourLevelsDetailRenderer({
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
content: {
|
content: {
|
||||||
paddingHorizontal: moderateScale(16),
|
paddingHorizontal: 18,
|
||||||
paddingTop: verticalScale(14),
|
paddingTop: 16,
|
||||||
paddingBottom: verticalScale(40),
|
paddingBottom: 40,
|
||||||
gap: verticalScale(14),
|
gap: 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,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue