Compare commits

..

2 Commits

5 changed files with 37 additions and 15 deletions

View File

@ -8,7 +8,15 @@ import { Hero } from "./shared/Hero";
import { ImageGallery } from "./shared/ImageGallery"; import { ImageGallery } from "./shared/ImageGallery";
import { SectionCard } from "./shared/SectionCard"; import { SectionCard } from "./shared/SectionCard";
const RESERVED_KEYS = new Set(["code", "id", "slug", "sort_order", "link"]); const RESERVED_KEYS = new Set([
"code",
"id",
"slug",
"sort_order",
"link",
"food_name",
"foodname",
]);
/** /**
* Generic detail renderer for modules and catalog items. * Generic detail renderer for modules and catalog items.
@ -36,6 +44,10 @@ export function GenericDetailRenderer({
[definitions], [definitions],
); );
const heroTitle = humanizeKey(
content.title || (typeof data.food_name === "string" ? data.food_name : "") || "Untitled content",
);
return ( return (
<ScrollView <ScrollView
contentContainerStyle={{ contentContainerStyle={{
@ -47,14 +59,14 @@ export function GenericDetailRenderer({
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
> >
<Hero <Hero
title={content.title || "Untitled content"} title={heroTitle}
subtitle={content.summary ?? undefined} subtitle={content.summary ?? undefined}
/> />
<ImageGallery images={[]} /> <ImageGallery images={[]} />
{Object.entries(data) {Object.entries(data)
.filter( .filter(
([key]) => ([key]) =>
!RESERVED_KEYS.has(key) && !RESERVED_KEYS.has(key.toLowerCase()) &&
!(isTherapeutic && key.toLowerCase() === "name"), !(isTherapeutic && key.toLowerCase() === "name"),
) )
.map(([key, value]) => { .map(([key, value]) => {

View File

@ -54,7 +54,10 @@ export function PatternAccordionCardRenderer({
const router = useRouter(); const router = useRouter();
const [expanded, setExpanded] = useState(false); const [expanded, setExpanded] = useState(false);
const attributes = item.attributes; const attributes = item.attributes;
const rawTitle = asString(attributes.name) || item.title; const rawTitle =
asString(attributes.food_name) ||
asString(attributes.name) ||
item.title;
const title = humanizeKey(rawTitle); const title = humanizeKey(rawTitle);
const link = attributes?.link as Record<string, unknown> | undefined; const link = attributes?.link as Record<string, unknown> | undefined;
@ -343,10 +346,13 @@ export function ModuleCatalogCardRenderer({
// If this item points to a pattern content item, render inline accordion // If this item points to a pattern content item, render inline accordion
if (isContentRef) { if (isContentRef) {
return <PatternAccordionCardRenderer item={item} />; return <PatternAccordionCardRenderer item={item} onPress={onPress} />;
} }
const rawTitle = asString(attributes.name) || item.title; const rawTitle =
asString(attributes.food_name) ||
asString(attributes.name) ||
item.title;
const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/); const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/);
const title = parenMatch const title = parenMatch
? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim() ? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim()

View File

@ -3,7 +3,7 @@ export function asString(value: unknown): string {
if (typeof value === "number" || typeof value === "boolean") return String(value); if (typeof value === "number" || typeof value === "boolean") return String(value);
if (value !== null && typeof value === "object" && !Array.isArray(value)) { if (value !== null && typeof value === "object" && !Array.isArray(value)) {
const record = value as Record<string, unknown>; const record = value as Record<string, unknown>;
for (const key of ["label", "point_name", "name", "title", "code"]) { for (const key of ["label", "point_name", "food_name", "name", "title", "code"]) {
if (typeof record[key] === "string" && (record[key] as string).trim().length > 0) { if (typeof record[key] === "string" && (record[key] as string).trim().length > 0) {
return (record[key] as string).trim(); return (record[key] as string).trim();
} }

View File

@ -9,6 +9,7 @@ import { DetailPageShell } from "../renderers/shared/DetailPageShell";
import { applyPresentationContractToData } from "../utils/attribute-presentation"; import { applyPresentationContractToData } from "../utils/attribute-presentation";
import { BackActionContext } from "../context/BackActionContext"; import { BackActionContext } from "../context/BackActionContext";
import { PageToneProvider, type PageTone } from "../context/PageToneContext"; import { PageToneProvider, type PageTone } from "../context/PageToneContext";
import { humanizeKey } from "../renderers/helpers/value";
export interface ContentDetailScreenProps { export interface ContentDetailScreenProps {
moduleCode: string; moduleCode: string;
@ -98,9 +99,11 @@ function ContentDetailScreenResolved({
const presentationAttributes = screen.contractQuery.data?.presentation.attributes ?? []; const presentationAttributes = screen.contractQuery.data?.presentation.attributes ?? [];
const presentedData = applyPresentationContractToData(response.data, presentationAttributes); const presentedData = applyPresentationContractToData(response.data, presentationAttributes);
const foodName = typeof response.data.food_name === "string" ? response.data.food_name.trim() : "";
const pointName = typeof response.data.point_name === "string" ? response.data.point_name.trim() : ""; const pointName = typeof response.data.point_name === "string" ? response.data.point_name.trim() : "";
const name = typeof response.data.name === "string" ? response.data.name.trim() : ""; const name = typeof response.data.name === "string" ? response.data.name.trim() : "";
const displayTitle = pointName || name || response.content.title; const rawTitle = foodName || pointName || name || response.content.title;
const displayTitle = humanizeKey(rawTitle);
const alternateNames = [response.data.alt_name_1, response.data.alt_name_2] const alternateNames = [response.data.alt_name_1, response.data.alt_name_2]
.filter((value): value is string => typeof value === "string" && value.trim().length > 0) .filter((value): value is string => typeof value === "string" && value.trim().length > 0)
.map((value) => value.trim()) .map((value) => value.trim())
@ -133,7 +136,7 @@ function ContentDetailScreenResolved({
contentId={response.content.id} contentId={response.content.id}
content={{ content={{
id: response.content.id, id: response.content.id,
title: response.content.title, title: displayTitle,
slug: response.content.slug, slug: response.content.slug,
summary: response.content.summary, summary: response.content.summary,
}} }}
@ -147,12 +150,12 @@ function ContentDetailScreenResolved({
moduleCode={moduleCode} moduleCode={moduleCode}
templateCode={templateCode} templateCode={templateCode}
contentId={response.content.id} contentId={response.content.id}
content={{ content={{
id: response.content.id, id: response.content.id,
title: response.content.title, title: displayTitle,
slug: response.content.slug, slug: response.content.slug,
summary: response.content.summary, summary: response.content.summary,
}} }}
data={presentedData} data={presentedData}
definitions={screen.definitionsQuery.data?.attributes ?? []} definitions={screen.definitionsQuery.data?.attributes ?? []}
presentationAttributes={presentationAttributes} presentationAttributes={presentationAttributes}

View File

@ -114,6 +114,7 @@ const MODULE_VISUALS: Record<string, ModuleVisualConfig> = {
color: "#10B981", color: "#10B981",
isDefaultFree: true, isDefaultFree: true,
planCode: "NUTRITION_CORE", planCode: "NUTRITION_CORE",
entryTemplateCode: "m0031_ct0002",
}, },
m0041: { m0041: {
icon: "body-outline", icon: "body-outline",