From 3fc56f344e4e7fa7eefb48b3461a0dce22b40edc Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Fri, 30 Oct 2026 17:11:16 +0530 Subject: [PATCH] feat(gynecology): add pattern accordion card renderer matching design sketches --- .../collections/ModuleCatalogRenderers.tsx | 477 +++++++++++++++++- src/features/content/renderers/registry.ts | 7 +- 2 files changed, 481 insertions(+), 3 deletions(-) diff --git a/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx b/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx index 0cb0bcb..9849d09 100644 --- a/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx +++ b/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx @@ -1,5 +1,14 @@ -import React from "react"; -import { Pressable, StyleSheet, Text, View } from "react-native"; +import React, { useState } from "react"; +import { + ActivityIndicator, + LayoutAnimation, + Platform, + Pressable, + StyleSheet, + Text, + UIManager, + View, +} from "react-native"; import { Ionicons } from "@expo/vector-icons"; import { moderateScale, verticalScale } from "react-native-size-matters"; @@ -7,20 +16,250 @@ import { Colors } from "@/theme"; import { asNumber, asString, asStringArray, humanizeKey } from "../helpers/value"; import { CollectionScaffold } from "../shared/CollectionScaffold"; import { ContentCountBadge } from "../shared/ContentCountBadge"; +import { useModuleContentDetailQuery } from "../../hooks/use-content-queries"; import type { CollectionItemRendererProps, CollectionRendererProps, } from "../../types/renderer.types"; +if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) { + UIManager.setLayoutAnimationEnabledExperimental(true); +} + export function ModuleCatalogCollectionRenderer(props: CollectionRendererProps) { return ; } +export function PatternAccordionCardRenderer({ + item, + onPress, +}: CollectionItemRendererProps) { + const [expanded, setExpanded] = useState(false); + const attributes = item.attributes; + const rawTitle = asString(attributes.name) || item.title; + const title = humanizeKey(rawTitle); + + const link = attributes?.link as Record | undefined; + const linkTarget = link?.target as Record | undefined; + const contentId = (linkTarget?.content_id as string) || item.id; + const moduleCode = (linkTarget?.module_code as string) || "m0042"; + + const detailQuery = useModuleContentDetailQuery( + { module_code: moduleCode }, + contentId, + ); + + const toggle = () => { + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); + setExpanded((prev) => !prev); + }; + + const detailData = (detailQuery.data?.data as Record | undefined) || attributes; + + // Extract fields matching the user's diagram + const rawManifestations = detailData.clinical_manifestations; + const clinicalManifestations: string[] = Array.isArray(rawManifestations) + ? (rawManifestations as string[]).map(String) + : typeof rawManifestations === "string" && rawManifestations.trim() + ? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean) + : []; + + const tongue = asString(detailData.tongue); + const pulse = asString(detailData.pulse); + const treatmentPrinciple = asString(detailData.treatment_principle); + + const rawAcupuncture = detailData.acupuncture; + let acuPoints = ""; + let acuMethod = ""; + if (rawAcupuncture && typeof rawAcupuncture === "object") { + const acuObj = rawAcupuncture as Record; + acuPoints = asString(acuObj.points); + acuMethod = asString(acuObj.method); + } else if (typeof rawAcupuncture === "string") { + acuPoints = rawAcupuncture; + } + + const rawExplanation = detailData.explanation; + const explanations: string[] = Array.isArray(rawExplanation) + ? (rawExplanation as string[]).map(String) + : typeof rawExplanation === "string" && rawExplanation.trim() + ? rawExplanation.split("\n").map((s) => s.trim()).filter(Boolean) + : []; + + const category = asString(detailData.category); + + // Split points by comma into chips + const pointChips = acuPoints + ? acuPoints.split(/,\s*/).map((p) => p.trim()).filter(Boolean) + : []; + + return ( + + [ + accordionStyles.headerRow, + expanded && accordionStyles.headerRowExpanded, + pressed && accordionStyles.pressed, + ]} + > + {title} + + + + + + {expanded ? ( + + {detailQuery.isLoading && !detailQuery.data ? ( + + + Loading pattern details… + + ) : ( + + {/* 1. Clinical Manifestations */} + {clinicalManifestations.length > 0 ? ( + + + Clinical Manifestations + + + {clinicalManifestations.map((itemText, idx) => ( + + • + {itemText} + + ))} + + + ) : null} + + {/* 2. Tongue & Pulse (Side-by-Side as drawn) */} + {tongue || pulse ? ( + + {tongue ? ( + + Tongue + {tongue} + + ) : null} + {tongue && pulse ? : null} + {pulse ? ( + + Pulse + {pulse} + + ) : null} + + ) : null} + + {/* 3. Treatment Principle */} + {treatmentPrinciple ? ( + + + Treatment Principle + + + {treatmentPrinciple} + + + ) : null} + + {/* 4. Acupuncture Points & Method */} + {pointChips.length > 0 || acuMethod ? ( + + + Acupuncture Points + + {pointChips.length > 0 ? ( + + {pointChips.map((pt, idx) => ( + + {pt} + + ))} + + ) : null} + {acuMethod ? ( + + Method: + {acuMethod} + + ) : null} + + ) : null} + + {/* 5. Explanation */} + {explanations.length > 0 ? ( + + + Explanation + + + {explanations.map((exp, idx) => ( + + – + {exp} + + ))} + + + ) : null} + + {/* 6. Category */} + {category ? ( + + Category: + + {category} + + + ) : null} + + {/* Optional link to navigate to full detail screen */} + {onPress ? ( + [ + accordionStyles.viewFullDetailBtn, + pressed && accordionStyles.pressed, + ]} + > + + View Full Details + + + + ) : null} + + )} + + ) : null} + + ); +} + export function ModuleCatalogCardRenderer({ item, onPress, }: CollectionItemRendererProps) { const attributes = item.attributes; + const link = attributes?.link as Record | undefined; + const isContentRef = link?.type === "content_ref"; + + // If this item points to a pattern content item, render inline accordion + if (isContentRef) { + return ; + } + const rawTitle = asString(attributes.name) || item.title; const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/); const title = parenMatch @@ -76,6 +315,239 @@ export function ModuleCatalogCardRenderer({ ); } +const accordionStyles = StyleSheet.create({ + cardContainer: { + backgroundColor: "#FFFFFF", + marginHorizontal: moderateScale(14), + marginVertical: verticalScale(5), + borderRadius: moderateScale(14), + borderWidth: 1, + borderColor: "#E5E7EB", + overflow: "hidden", + shadowColor: "#000", + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.05, + shadowRadius: 3, + elevation: 1, + }, + headerRow: { + minHeight: verticalScale(52), + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", + paddingHorizontal: moderateScale(16), + paddingVertical: verticalScale(12), + backgroundColor: "#FFFFFF", + }, + headerRowExpanded: { + backgroundColor: "#F0FDF4", + borderBottomWidth: 1, + borderBottomColor: "#DCFCE7", + }, + pressed: { + opacity: 0.75, + }, + title: { + flex: 1, + fontSize: moderateScale(15), + fontWeight: "600", + color: "#111827", + marginRight: moderateScale(10), + }, + chevronWrapper: { + width: moderateScale(28), + height: moderateScale(28), + borderRadius: moderateScale(14), + alignItems: "center", + justifyContent: "center", + backgroundColor: "#F3F4F6", + }, + expandedBody: { + padding: moderateScale(12), + backgroundColor: "#F9FAFB", + }, + loadingRow: { + flexDirection: "row", + alignItems: "center", + justifyContent: "center", + paddingVertical: verticalScale(16), + gap: moderateScale(8), + }, + loadingText: { + fontSize: moderateScale(13), + color: "#6B7280", + }, + innerBox: { + backgroundColor: "#FFFFFF", + borderRadius: moderateScale(10), + borderWidth: 1, + borderColor: "#E5E7EB", + padding: moderateScale(14), + gap: verticalScale(12), + }, + section: { + borderBottomWidth: 1, + borderBottomColor: "#F3F4F6", + paddingBottom: verticalScale(10), + gap: verticalScale(6), + }, + sectionTitle: { + fontSize: moderateScale(12), + fontWeight: "700", + color: "#059669", + textTransform: "uppercase", + letterSpacing: 0.4, + }, + bulletList: { + gap: verticalScale(4), + }, + bulletRow: { + flexDirection: "row", + alignItems: "flex-start", + gap: moderateScale(6), + }, + bulletDot: { + fontSize: moderateScale(14), + color: "#10B981", + lineHeight: moderateScale(18), + }, + bulletText: { + flex: 1, + fontSize: moderateScale(13), + color: "#374151", + lineHeight: moderateScale(18), + }, + twoColumnBox: { + flexDirection: "row", + backgroundColor: "#F9FAFB", + borderRadius: moderateScale(8), + borderWidth: 1, + borderColor: "#E5E7EB", + padding: moderateScale(10), + alignItems: "stretch", + }, + column: { + flex: 1, + gap: verticalScale(2), + }, + columnDivider: { + width: 1, + backgroundColor: "#E5E7EB", + marginHorizontal: moderateScale(10), + }, + columnLabel: { + fontSize: moderateScale(11), + fontWeight: "700", + color: "#4B5563", + textTransform: "uppercase", + }, + columnValue: { + fontSize: moderateScale(13), + color: "#111827", + fontWeight: "500", + lineHeight: moderateScale(18), + }, + principleText: { + fontSize: moderateScale(13), + color: "#1F2937", + lineHeight: moderateScale(19), + fontStyle: "italic", + backgroundColor: "#ECFDF5", + padding: moderateScale(8), + borderRadius: moderateScale(6), + borderLeftWidth: 3, + borderLeftColor: "#10B981", + }, + chipsContainer: { + flexDirection: "row", + flexWrap: "wrap", + gap: moderateScale(6), + }, + pointChip: { + backgroundColor: "#E0E7FF", + borderWidth: 1, + borderColor: "#C7D2FE", + paddingHorizontal: moderateScale(8), + paddingVertical: verticalScale(3), + borderRadius: moderateScale(6), + }, + pointChipText: { + fontSize: moderateScale(12), + fontWeight: "700", + color: "#3730A3", + }, + methodContainer: { + marginTop: verticalScale(4), + flexDirection: "row", + alignItems: "flex-start", + gap: moderateScale(4), + }, + subSectionLabel: { + fontSize: moderateScale(12), + fontWeight: "600", + color: "#4B5563", + }, + methodText: { + flex: 1, + fontSize: moderateScale(12), + color: "#4B5563", + lineHeight: moderateScale(17), + }, + explanationList: { + gap: verticalScale(4), + }, + explanationRow: { + flexDirection: "row", + alignItems: "flex-start", + gap: moderateScale(6), + }, + explanationBullet: { + fontSize: moderateScale(13), + color: "#9CA3AF", + lineHeight: moderateScale(17), + }, + explanationText: { + flex: 1, + fontSize: moderateScale(12), + color: "#4B5563", + lineHeight: moderateScale(17), + }, + categoryRow: { + flexDirection: "row", + alignItems: "center", + gap: moderateScale(8), + paddingTop: verticalScale(2), + }, + categoryLabel: { + fontSize: moderateScale(12), + fontWeight: "600", + color: "#6B7280", + }, + categoryBadge: { + backgroundColor: "#F3F4F6", + paddingHorizontal: moderateScale(8), + paddingVertical: verticalScale(2), + borderRadius: moderateScale(6), + }, + categoryBadgeText: { + fontSize: moderateScale(12), + fontWeight: "600", + color: "#374151", + }, + viewFullDetailBtn: { + flexDirection: "row", + alignItems: "center", + justifyContent: "flex-end", + gap: moderateScale(4), + paddingTop: verticalScale(4), + }, + viewFullDetailText: { + fontSize: moderateScale(12), + fontWeight: "600", + color: Colors.primary, + }, +}); + const styles = StyleSheet.create({ row: { minHeight: moderateScale(68), @@ -111,3 +583,4 @@ const styles = StyleSheet.create({ lineHeight: moderateScale(16), }, }); + diff --git a/src/features/content/renderers/registry.ts b/src/features/content/renderers/registry.ts index 9fe4357..a5be779 100644 --- a/src/features/content/renderers/registry.ts +++ b/src/features/content/renderers/registry.ts @@ -2,7 +2,11 @@ import type { CollectionItemRendererComponent, CollectionRendererComponent, Deta import { GenericCollectionRenderer } from "./GenericCollectionRenderer"; import { GenericCardRenderer } from "./GenericCardRenderer"; import { GenericDetailRenderer } from "./GenericDetailRenderer"; -import { ModuleCatalogCollectionRenderer, ModuleCatalogCardRenderer } from "./collections/ModuleCatalogRenderers"; +import { + ModuleCatalogCollectionRenderer, + ModuleCatalogCardRenderer, + PatternAccordionCardRenderer, +} from "./collections/ModuleCatalogRenderers"; import { AcuPointCollectionRenderer, AcuPointIndexCollectionRenderer, AcuPointCardRenderer, AcuPointIndexCardRenderer } from "./collections/PointRenderers"; import { MeridianCollectionRenderer, MeridianIndexCollectionRenderer, MeridianCardRenderer, MeridianIndexCardRenderer } from "./collections/MeridianRenderers"; import { EovCollectionRenderer, EovIndexCollectionRenderer, EovCardRenderer, EovIndexCardRenderer } from "./collections/EovRenderers"; @@ -74,6 +78,7 @@ export const collectionRenderers: Readonly> = Object.freeze({ module_catalog_card: ModuleCatalogCardRenderer, + pattern_accordion_card: PatternAccordionCardRenderer, acu_point_index_card: AcuPointIndexCardRenderer, acu_point_card: AcuPointCardRenderer, meridian_index_card: MeridianIndexCardRenderer,