diff --git a/src/app/(tabs)/_layout.tsx b/src/app/(tabs)/_layout.tsx index 790a275..55da028 100644 --- a/src/app/(tabs)/_layout.tsx +++ b/src/app/(tabs)/_layout.tsx @@ -66,6 +66,35 @@ export default function TabsLayout() { }} /> + + ( + + ), + }} + /> + + ( + + ), + }} + /> + ; +} + +export function EarAcupunctureCatalogCardRenderer({ + item, + onPress, +}: CollectionItemRendererProps) { + const attributes = item.attributes; + const name = asString(attributes.name).trim(); + const point = asString(attributes.point).trim(); + const title = name || point || item.title; + + const contentCount = asNumber(attributes.content_count); + const contentLabel = asString(attributes.content_label).trim(); + + return ( + + ); +} + +/** Shared collection shell for concrete Ear Acupuncture points (CT0011). */ +export function EarAcupunctureCollectionRenderer(props: CollectionRendererProps) { + return ; +} + +export function EarAcupunctureCardRenderer({ + item, + onPress, +}: CollectionItemRendererProps) { + const attributes = item.attributes; + const point = asString(attributes.point).trim() || item.title; + const category = asString(attributes.category).trim(); + const subCategory = asString(attributes.sub_category).trim(); + const subtitle = [category, subCategory].filter(Boolean).join(" · "); + + return ( + + ); +} diff --git a/src/features/content/renderers/details/EarAcupunctureCatalogDetailRenderer.tsx b/src/features/content/renderers/details/EarAcupunctureCatalogDetailRenderer.tsx new file mode 100644 index 0000000..995de87 --- /dev/null +++ b/src/features/content/renderers/details/EarAcupunctureCatalogDetailRenderer.tsx @@ -0,0 +1,105 @@ +import React, { useMemo } from "react"; +import { ScrollView } from "react-native"; + +import type { DetailRendererProps } from "../../types/renderer.types"; +import { + bareAttributeKey, + findAttributePresentationRule, + getEmptyDisplayText, + presentationDisplayOrder, + shouldRenderAttribute, +} from "../../utils/attribute-presentation"; +import { asString, humanizeKey } from "../helpers/value"; +import { ContentValue } from "../shared/ContentValue"; +import { Hero } from "../shared/Hero"; +import { ImageGallery } from "../shared/ImageGallery"; +import { SectionCard } from "../shared/SectionCard"; + +const RESERVED_KEYS = new Set(["name", "point", "code", "sort_order", "link"]); + +/** + * Detail renderer for CT0001-CT0007 catalogue/index entries. + * + * Normally catalogue rows navigate through their hydrated `link` reference and + * never open a detail page. This renderer is still fully implemented because + * the presentation contract declares it and it is also a safe fallback when a + * row has no navigable reference. + */ +export function EarAcupunctureCatalogDetailRenderer({ + content, + data, + definitions, + presentationAttributes, +}: DetailRendererProps) { + const title = asString(data.name).trim() || asString(data.point).trim() || content.title; + + const attributes = useMemo(() => { + const roots = definitions.filter((definition) => definition.is_root); + const contractIndex = new Map( + presentationAttributes.map((rule, index) => [rule.attribute_key, index]), + ); + + const definitionByKey = new Map( + roots.map((definition) => [ + definition.code || bareAttributeKey(definition.attribute_key), + definition, + ]), + ); + + const keys = new Set(); + for (const definition of roots) { + keys.add(definition.code || bareAttributeKey(definition.attribute_key)); + } + for (const key of Object.keys(data)) keys.add(key); + + return [...keys] + .flatMap((key) => { + if (!key || RESERVED_KEYS.has(key)) return []; + + const value = data[key]; + const definition = definitionByKey.get(key); + const rule = findAttributePresentationRule( + definition?.attribute_key ?? key, + presentationAttributes, + ); + if (!shouldRenderAttribute(value, rule)) return []; + + return [{ + key, + label: definition?.label?.trim() || humanizeKey(key), + value, + emptyText: getEmptyDisplayText(value, rule), + order: presentationDisplayOrder( + rule, + definition?.sort_order, + rule ? contractIndex.get(rule.attribute_key) : undefined, + ), + }]; + }) + .sort((a, b) => a.order - b.order || a.label.localeCompare(b.label)); + }, [data, definitions, presentationAttributes]); + + return ( + + + + + {attributes.map((attribute) => ( + + + + ))} + + ); +} diff --git a/src/features/content/renderers/details/EarAcupunctureDetailRenderer.tsx b/src/features/content/renderers/details/EarAcupunctureDetailRenderer.tsx new file mode 100644 index 0000000..864ecd2 --- /dev/null +++ b/src/features/content/renderers/details/EarAcupunctureDetailRenderer.tsx @@ -0,0 +1,117 @@ +import React, { useMemo } from "react"; +import { ScrollView, Text } from "react-native"; + +import type { DetailRendererProps } from "../../types/renderer.types"; +import { + bareAttributeKey, + findAttributePresentationRule, + getEmptyDisplayText, + presentationDisplayOrder, + shouldRenderAttribute, +} from "../../utils/attribute-presentation"; +import { asString, humanizeKey } from "../helpers/value"; +import { ContentValue } from "../shared/ContentValue"; +import { Hero } from "../shared/Hero"; +import { ImageGallery } from "../shared/ImageGallery"; +import { SectionCard } from "../shared/SectionCard"; + +const RESERVED_KEYS = new Set([ + "point", + "category", + "sub_category", + "code", + "sort_order", + "link", +]); + +/** Semantic detail renderer for M0002_CT0011 Ear Acupuncture points. */ +export function EarAcupunctureDetailRenderer({ + content, + data, + definitions, + presentationAttributes, +}: DetailRendererProps) { + const point = asString(data.point).trim() || content.title; + const category = asString(data.category).trim(); + const subCategory = asString(data.sub_category).trim(); + const subtitle = [category, subCategory].filter(Boolean).join(" · "); + + const attributes = useMemo(() => { + const roots = definitions.filter((definition) => definition.is_root); + const contractIndex = new Map( + presentationAttributes.map((rule, index) => [rule.attribute_key, index]), + ); + const definitionByKey = new Map( + roots.map((definition) => [ + definition.code || bareAttributeKey(definition.attribute_key), + definition, + ]), + ); + + const keys = new Set(); + for (const definition of roots) { + keys.add(definition.code || bareAttributeKey(definition.attribute_key)); + } + for (const rule of presentationAttributes) { + const key = bareAttributeKey(rule.attribute_key); + if (Object.prototype.hasOwnProperty.call(data, key)) keys.add(key); + } + for (const key of Object.keys(data)) keys.add(key); + + return [...keys] + .flatMap((key) => { + if (!key || RESERVED_KEYS.has(key)) return []; + + const value = data[key]; + const definition = definitionByKey.get(key); + const rule = findAttributePresentationRule( + definition?.attribute_key ?? key, + presentationAttributes, + ); + if (!shouldRenderAttribute(value, rule)) return []; + + return [{ + key, + label: definition?.label?.trim() || humanizeKey(key), + value, + emptyText: getEmptyDisplayText(value, rule), + order: presentationDisplayOrder( + rule, + definition?.sort_order, + rule ? contractIndex.get(rule.attribute_key) : undefined, + ), + }]; + }) + .sort((a, b) => a.order - b.order || a.label.localeCompare(b.label)); + }, [data, definitions, presentationAttributes]); + + return ( + + + + + {attributes.map((attribute) => ( + + {typeof attribute.value === "string" ? ( + + {attribute.value} + + ) : ( + + )} + + ))} + + ); +} diff --git a/src/features/content/renderers/registry.ts b/src/features/content/renderers/registry.ts index b274036..b5d6feb 100644 --- a/src/features/content/renderers/registry.ts +++ b/src/features/content/renderers/registry.ts @@ -24,6 +24,9 @@ import { FourSeasDetailRenderer } from "./details/FourSeasDetailRenderer"; import { GhostPointsDetailRenderer } from "./details/GhostPointsDetailRenderer"; import { EntryExitPointsDetailRenderer } from "./details/EntryExitPointsDetailRenderer"; import { ReturningYangDetailRenderer } from "./details/ReturningYangDetailRenderer"; +import { EarAcupunctureCatalogCollectionRenderer, EarAcupunctureCatalogCardRenderer, EarAcupunctureCollectionRenderer, EarAcupunctureCardRenderer } from "./collections/EarAcupunctureRenderers"; +import { EarAcupunctureCatalogDetailRenderer } from "./details/EarAcupunctureCatalogDetailRenderer"; +import { EarAcupunctureDetailRenderer } from "./details/EarAcupunctureDetailRenderer"; export const collectionRenderers: Readonly> = Object.freeze({ module_catalog_collection: ModuleCatalogCollectionRenderer, @@ -34,6 +37,8 @@ export const collectionRenderers: Readonly> = Object.freeze({ module_catalog_card: ModuleCatalogCardRenderer, @@ -44,6 +49,8 @@ export const collectionItemRenderers: Readonly> = Object.freeze({ module_catalog_detail: IndexEntryDetailRenderer, @@ -70,6 +77,8 @@ export const detailRenderers: Readonly> ghost_points_detail: GhostPointsDetailRenderer, entry_exit_points_detail: EntryExitPointsDetailRenderer, returning_yang_detail: ReturningYangDetailRenderer, + ear_acupuncture_catalog_detail: EarAcupunctureCatalogDetailRenderer, + ear_acupuncture_detail: EarAcupunctureDetailRenderer, }); export function resolveCollectionRenderer(code:string):CollectionRendererComponent { const r=collectionRenderers[code]; if(!r) throw new Error(`Unknown collection renderer: ${code}`); return r; } export function resolveCollectionItemRenderer(code:string):CollectionItemRendererComponent { const r=collectionItemRenderers[code]; if(!r) throw new Error(`Unknown collection item renderer: ${code}`); return r; } diff --git a/src/features/modules/module-index.ts b/src/features/modules/module-index.ts index a8c82c6..c51df0d 100644 --- a/src/features/modules/module-index.ts +++ b/src/features/modules/module-index.ts @@ -1,12 +1,14 @@ import type { ModuleResponse } from "@/features/content/types/content.types"; import type { TemplateReference } from "@/features/content/types/content-reference.types"; +/** + * Client-only fallbacks for presentation and commerce values that are not yet + * guaranteed by the modules API. Business/content metadata such as module + * name, description and category must come from the API response. + */ export interface ModuleVisualConfig { - title?: string; - description?: string; icon: string; color: string; - category: string; isDefaultFree: boolean; planCode: string; entryTemplateCode?: string; @@ -26,147 +28,99 @@ export interface ModuleIndexItem { const MODULE_VISUALS: Record = { M0001: { - title: "Acupuncture", - description: "All points, locations, indications & more", icon: "water-outline", color: "#2563EB", - category: "point", isDefaultFree: true, planCode: "POINTS_ACU", entryTemplateCode: "M0001_CT0001", }, M0002: { - title: "Ear-acupuncture", - description: "Ear Points & Point Category", icon: "ear-outline", color: "#F59E0B", - category: "point", isDefaultFree: false, planCode: "POINTS_EAR", }, M0003: { - title: "Scalp acupuncture", - description: "Scalp zones, points & protocols", icon: "accessibility-outline", color: "#EF4444", - category: "point", isDefaultFree: false, planCode: "POINTS_SCALP", }, M0011: { - title: "Eight principle", - description: "Exterior/Interior, Cold/Heat, Deficiency/Excess, Yin/Yang patterns", icon: "git-network-outline", color: "#7C3AED", - category: "Patterns", isDefaultFree: true, planCode: "PATTERN_CORE", }, M0012: { - title: "TCM Patterns", - description: "Zangfu organ and channel identification", icon: "pulse-outline", color: "#06B6D4", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0013: { - title: "Qi-Blood-body fluid", - description: "Qi, Blood, and Body Fluid identification of patterns", icon: "water-outline", color: "#3B82F6", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0014: { - title: "Pathogenic factors", - description: "Wind, Cold, Summer-Heat, Dampness, Dryness, Fire patterns", icon: "flame-outline", color: "#F59E0B", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0015: { - title: "Six stages", - description: "Tai Yang, Yang Ming, Shao Yang, Tai Yin, Shao Yin, Jue Yin", icon: "layers-outline", color: "#10B981", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0016: { - title: "Four level", - description: "Wei, Qi, Ying, Xue level pattern identification", icon: "trending-up-outline", color: "#EF4444", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0017: { - title: "Three burners", - description: "Upper, Middle, and Lower Burner pattern identification", icon: "thermometer-outline", color: "#EC4899", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0018: { - title: "Twelve channel", - description: "Twelve-channel theory and clinical reference", icon: "pulse-outline", color: "#06B6D4", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0019: { - title: "Five elements", - description: "Wood, Fire, Earth, Metal, Water relationships and patterns", icon: "flower-outline", color: "#6366F1", - category: "Patterns", isDefaultFree: false, planCode: "PATTERN_CORE", }, M0020: { - title: "Extra Ordinary Vessel", - description: "Extraordinary vessel theory, pathways and relationships", icon: "git-branch-outline", color: "#8B5CF6", - category: "point", isDefaultFree: false, planCode: "POINTS_ACU", }, M0031: { - title: "Nutrition", - description: "Nutritional food classifications, properties and indications", icon: "nutrition-outline", color: "#10B981", - category: "Nutrition", isDefaultFree: true, planCode: "NUTRITION_CORE", }, M0041: { - title: "Auriculotherapy", - description: "Auriculotherapy reflexology systems", icon: "body-outline", color: "#8B5CF6", - category: "point", isDefaultFree: false, planCode: "LIFETIME_ALL", }, M0042: { - title: "Gynecology", - description: "Menstrual irregularities and pregnancy patterns", icon: "woman-outline", color: "#EC4899", - category: "Therapeutics", isDefaultFree: false, planCode: "THERAPEUTICS_GYNAE", }, @@ -182,6 +136,46 @@ function readMetadataString(module: ModuleResponse, key: string): string | null return asNonBlankString(module.metadata?.[key]); } +function readMetadataBoolean(module: ModuleResponse, key: string): boolean | null { + const value = module.metadata?.[key]; + if (typeof value === "boolean") return value; + if (typeof value === "string") { + const normalized = value.trim().toLowerCase(); + if (normalized === "true") return true; + if (normalized === "false") return false; + } + return null; +} + +export function resolveModuleCategory(module: ModuleResponse): string { + const explicitCategory = readMetadataString(module, "category"); + if (explicitCategory) return explicitCategory; + + const kind = readMetadataString(module, "kind")?.toLowerCase(); + + switch (kind) { + case "point": + case "points": + return "Points"; + + case "pattern": + case "patterns": + case "five-elements": + case "five_elements": + return "Patterns"; + + case "nutrition": + return "Nutrition"; + + case "therapeutic": + case "therapeutics": + return "Therapeutics"; + + default: + return "Other"; + } +} + export function resolveModuleEntryTemplateCode(module: ModuleResponse): string { const configured = MODULE_VISUALS[module.code]?.entryTemplateCode; const metadataConfigured = @@ -210,27 +204,25 @@ export function buildModuleTemplateReference(module: ModuleResponse): TemplateRe export function toModuleIndexItem(module: ModuleResponse): ModuleIndexItem { const visual = MODULE_VISUALS[module.code]; - const metadataCategory = readMetadataString(module, "category"); const metadataIcon = readMetadataString(module, "icon"); const metadataColor = readMetadataString(module, "color"); const metadataPlanCode = readMetadataString(module, "plan_code"); + const metadataIsDefaultFree = readMetadataBoolean(module, "is_default_free"); return { module, reference: buildModuleTemplateReference(module), - title: visual?.title ?? module.name, - description: - visual?.description ?? - module.description ?? - "Structured clinical reference content", + + // API is authoritative for module content/business metadata. + title: module.name, + description: module.description?.trim() || "Structured clinical reference content", + category: resolveModuleCategory(module), + + // Presentation/commerce values use API metadata when supplied and retain + // current client fallbacks until those fields are guaranteed by the API. icon: metadataIcon ?? visual?.icon ?? "folder-outline", color: metadataColor ?? visual?.color ?? "#4F46E5", - category: - metadataCategory ?? - visual?.category ?? - readMetadataString(module, "kind") ?? - "Other", - isDefaultFree: visual?.isDefaultFree ?? false, + isDefaultFree: metadataIsDefaultFree ?? visual?.isDefaultFree ?? false, planCode: metadataPlanCode ?? visual?.planCode ?? "", }; } diff --git a/versions/src-v0.1.zip b/versions/src-v0.1.zip deleted file mode 100644 index 95a0f56..0000000 Binary files a/versions/src-v0.1.zip and /dev/null differ diff --git a/versions/src-v0.11.zip b/versions/src-v0.11.zip deleted file mode 100644 index 7b39c39..0000000 Binary files a/versions/src-v0.11.zip and /dev/null differ diff --git a/versions/src-v0.12.zip b/versions/src-v0.12.zip deleted file mode 100644 index 19ab929..0000000 Binary files a/versions/src-v0.12.zip and /dev/null differ diff --git a/versions/src-v0.13.zip b/versions/src-v0.13.zip deleted file mode 100644 index a89a925..0000000 Binary files a/versions/src-v0.13.zip and /dev/null differ diff --git a/versions/src-v0.2.zip b/versions/src-v0.2.zip deleted file mode 100644 index f44e6ec..0000000 Binary files a/versions/src-v0.2.zip and /dev/null differ diff --git a/versions/src-v0.3.zip b/versions/src-v0.3.zip deleted file mode 100644 index 2e2268d..0000000 Binary files a/versions/src-v0.3.zip and /dev/null differ diff --git a/versions/src-v0.4.zip b/versions/src-v0.4.zip deleted file mode 100644 index 2a7c836..0000000 Binary files a/versions/src-v0.4.zip and /dev/null differ diff --git a/versions/src-v0.5.zip b/versions/src-v0.5.zip deleted file mode 100644 index 80d4963..0000000 Binary files a/versions/src-v0.5.zip and /dev/null differ diff --git a/versions/src-v0.6.zip b/versions/src-v0.6.zip deleted file mode 100644 index 003db0a..0000000 Binary files a/versions/src-v0.6.zip and /dev/null differ diff --git a/versions/src-v0.7.zip b/versions/src-v0.7.zip deleted file mode 100644 index 6687b26..0000000 Binary files a/versions/src-v0.7.zip and /dev/null differ diff --git a/versions/src-v08.zip b/versions/src-v08.zip deleted file mode 100644 index 388c902..0000000 Binary files a/versions/src-v08.zip and /dev/null differ diff --git a/versions/src-v09.zip b/versions/src-v09.zip deleted file mode 100644 index d39997e..0000000 Binary files a/versions/src-v09.zip and /dev/null differ diff --git a/versions/src-v10.zip b/versions/src-v10.zip deleted file mode 100644 index ee5582e..0000000 Binary files a/versions/src-v10.zip and /dev/null differ