feat(nutrition): direct navigation to food items, capitalize headings, and remove redundant food name card
This commit is contained in:
parent
4145375926
commit
93543583d6
|
|
@ -8,7 +8,15 @@ import { Hero } from "./shared/Hero";
|
|||
import { ImageGallery } from "./shared/ImageGallery";
|
||||
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.
|
||||
|
|
@ -36,6 +44,10 @@ export function GenericDetailRenderer({
|
|||
[definitions],
|
||||
);
|
||||
|
||||
const heroTitle = humanizeKey(
|
||||
content.title || (typeof data.food_name === "string" ? data.food_name : "") || "Untitled content",
|
||||
);
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
contentContainerStyle={{
|
||||
|
|
@ -47,14 +59,14 @@ export function GenericDetailRenderer({
|
|||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<Hero
|
||||
title={content.title || "Untitled content"}
|
||||
title={heroTitle}
|
||||
subtitle={content.summary ?? undefined}
|
||||
/>
|
||||
<ImageGallery images={[]} />
|
||||
{Object.entries(data)
|
||||
.filter(
|
||||
([key]) =>
|
||||
!RESERVED_KEYS.has(key) &&
|
||||
!RESERVED_KEYS.has(key.toLowerCase()) &&
|
||||
!(isTherapeutic && key.toLowerCase() === "name"),
|
||||
)
|
||||
.map(([key, value]) => {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,10 @@ export function PatternAccordionCardRenderer({
|
|||
const router = useRouter();
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
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 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 (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 title = parenMatch
|
||||
? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ export function asString(value: unknown): string {
|
|||
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
||||
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
||||
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) {
|
||||
return (record[key] as string).trim();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { DetailPageShell } from "../renderers/shared/DetailPageShell";
|
|||
import { applyPresentationContractToData } from "../utils/attribute-presentation";
|
||||
import { BackActionContext } from "../context/BackActionContext";
|
||||
import { PageToneProvider, type PageTone } from "../context/PageToneContext";
|
||||
import { humanizeKey } from "../renderers/helpers/value";
|
||||
|
||||
export interface ContentDetailScreenProps {
|
||||
moduleCode: string;
|
||||
|
|
@ -98,9 +99,11 @@ function ContentDetailScreenResolved({
|
|||
const presentationAttributes = screen.contractQuery.data?.presentation.attributes ?? [];
|
||||
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 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]
|
||||
.filter((value): value is string => typeof value === "string" && value.trim().length > 0)
|
||||
.map((value) => value.trim())
|
||||
|
|
@ -133,7 +136,7 @@ function ContentDetailScreenResolved({
|
|||
contentId={response.content.id}
|
||||
content={{
|
||||
id: response.content.id,
|
||||
title: response.content.title,
|
||||
title: displayTitle,
|
||||
slug: response.content.slug,
|
||||
summary: response.content.summary,
|
||||
}}
|
||||
|
|
@ -147,12 +150,12 @@ function ContentDetailScreenResolved({
|
|||
moduleCode={moduleCode}
|
||||
templateCode={templateCode}
|
||||
contentId={response.content.id}
|
||||
content={{
|
||||
id: response.content.id,
|
||||
title: response.content.title,
|
||||
slug: response.content.slug,
|
||||
summary: response.content.summary,
|
||||
}}
|
||||
content={{
|
||||
id: response.content.id,
|
||||
title: displayTitle,
|
||||
slug: response.content.slug,
|
||||
summary: response.content.summary,
|
||||
}}
|
||||
data={presentedData}
|
||||
definitions={screen.definitionsQuery.data?.attributes ?? []}
|
||||
presentationAttributes={presentationAttributes}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ const MODULE_VISUALS: Record<string, ModuleVisualConfig> = {
|
|||
color: "#10B981",
|
||||
isDefaultFree: true,
|
||||
planCode: "NUTRITION_CORE",
|
||||
entryTemplateCode: "m0031_ct0002",
|
||||
},
|
||||
m0041: {
|
||||
icon: "body-outline",
|
||||
|
|
|
|||
Loading…
Reference in New Issue