diff --git a/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx b/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx index 25f15f5..94997d2 100644 --- a/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx +++ b/src/features/content/renderers/collections/ModuleCatalogRenderers.tsx @@ -21,10 +21,16 @@ export function ModuleCatalogCardRenderer({ onPress, }: CollectionItemRendererProps) { const attributes = item.attributes; - const title = asString(attributes.name) || item.title; + const rawTitle = asString(attributes.name) || item.title; + const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/); + const title = parenMatch + ? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim() + : rawTitle; + const parenSubtitle = parenMatch ? parenMatch[2].trim() : null; + const label = + parenSubtitle || asString(attributes.sub_title) || - asString(attributes.content_label) || (asString(attributes.title) && asString(attributes.title) !== title ? asString(attributes.title) : null) || diff --git a/src/features/content/renderers/collections/SixStagesRenderers.tsx b/src/features/content/renderers/collections/SixStagesRenderers.tsx new file mode 100644 index 0000000..c316664 --- /dev/null +++ b/src/features/content/renderers/collections/SixStagesRenderers.tsx @@ -0,0 +1,145 @@ +import React from "react"; +import { Pressable, StyleSheet, Text, View } from "react-native"; +import { Ionicons } from "@expo/vector-icons"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import { Colors } from "@/theme"; +import { asNumber, asString, humanizeKey } from "../helpers/value"; +import { CollectionScaffold } from "../shared/CollectionScaffold"; +import { SectionCard } from "../shared/SectionCard"; +import type { + CollectionItemRendererProps, + CollectionRendererProps, +} from "../../types/renderer.types"; + +export function SixStagesCollectionRenderer(props: CollectionRendererProps) { + const overviewText = asString(props.items[0]?.attributes.stage_overview).trim(); + + const header = overviewText ? ( + + + {overviewText} + + + ) : null; + + return ( + + ); +} + +export function SixStagesCardRenderer({ + item, + onPress, +}: CollectionItemRendererProps) { + const attributes = item.attributes; + const rawTitle = asString(attributes.name) || item.title; + const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/); + const title = parenMatch + ? [parenMatch[1], parenMatch[3]].filter(Boolean).join(" ").trim() + : rawTitle; + const parenSubtitle = parenMatch ? parenMatch[2].trim() : null; + + const label = + parenSubtitle || + asString(attributes.sub_title) || + null; + + const cleanTitle = humanizeKey(title); + const cleanLabel = label ? humanizeKey(label) : null; + + const count = asNumber(attributes.content_count); + const rawContentLabel = asString(attributes.content_label); + const contentLabel = rawContentLabel ? humanizeKey(rawContentLabel) : null; + + const badgeText = + count !== null && count > 0 && contentLabel + ? `${count} ${contentLabel}` + : contentLabel || (count !== null ? `${count}` : null); + + return ( + [styles.row, pressed && styles.pressed]} + > + + + + + + {cleanTitle} + {cleanLabel ? ( + + {cleanLabel} + + ) : null} + + + {badgeText ? ( + + {badgeText} + + ) : null} + + + ); +} + +const styles = StyleSheet.create({ + overviewContainer: { + marginBottom: verticalScale(14), + }, + overviewText: { + fontSize: moderateScale(14), + lineHeight: moderateScale(22), + color: "#374151", + }, + row: { + 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", + }, + 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, + }, + badge: { + backgroundColor: "#F3F4F6", + borderRadius: moderateScale(12), + paddingHorizontal: moderateScale(9), + paddingVertical: verticalScale(5), + marginRight: moderateScale(8), + }, + badgeText: { + fontSize: moderateScale(11), + fontWeight: "700", + color: Colors.textSecondary, + }, +}); diff --git a/src/features/content/renderers/details/SixStagesDetailRenderer.tsx b/src/features/content/renderers/details/SixStagesDetailRenderer.tsx index 480c8ff..fa44c86 100644 --- a/src/features/content/renderers/details/SixStagesDetailRenderer.tsx +++ b/src/features/content/renderers/details/SixStagesDetailRenderer.tsx @@ -1,8 +1,13 @@ -import React from "react"; +import React, { useMemo } from "react"; import { ScrollView, StyleSheet } from "react-native"; import type { DetailRendererProps } from "../../types/renderer.types"; import { asString, humanizeKey } from "../helpers/value"; +import { + findAttributePresentationRule, + isEmptyValue, + presentationDisplayOrder, +} from "../../utils/attribute-presentation"; import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections"; import { ContentValue } from "../shared/ContentValue"; import { Hero } from "../shared/Hero"; @@ -19,18 +24,43 @@ const CATALOG_METADATA_KEYS = new Set([ "link", "point_images", "default_image_id", + "stage_overview", ]); export function SixStagesDetailRenderer({ content, data, + definitions, presentationAttributes, }: DetailRendererProps) { - const title = + const rawTitle = asString(data.name) || asString(data.title) || content.title || "Six Stages"; + const title = humanizeKey(rawTitle); + + const orderedSections = useMemo(() => { + const definitionByLabel = new Map( + (definitions ?? []).map((d) => [d.code, d.label]), + ); + + return Object.entries(data) + .filter( + ([key, value]) => + !RESERVED_KEYS.has(key) && + !CATALOG_METADATA_KEYS.has(key) && + !isEmptyValue(value), + ) + .map(([key, value]) => { + const rule = findAttributePresentationRule(key, presentationAttributes); + const order = presentationDisplayOrder(rule); + const rawLabel = definitionByLabel.get(key) || key; + const label = humanizeKey(rawLabel); + return { key, value, order, label }; + }) + .sort((a, b) => a.order - b.order || a.label.localeCompare(b.label)); + }, [data, definitions, presentationAttributes]); return ( - {Object.entries(data) - .filter(([key]) => !RESERVED_KEYS.has(key) && !CATALOG_METADATA_KEYS.has(key)) - .map(([key, value]) => ( - - - - ))} + {orderedSections.map(({ key, value, label }) => ( + + + + ))} > = Object.freeze({ module_catalog_card: ModuleCatalogCardRenderer, @@ -108,6 +116,13 @@ export const collectionItemRenderers: Readonly> = Object.freeze({ extra_ordinary_vessel_detail: ExtraOrdinaryVesselsDetailRenderer, @@ -232,6 +247,12 @@ export function resolveCollectionRenderer( if (normalizedTemplate === "m0017_ct0002" || (normalizedModule === "m0017" && normalizedTemplate?.includes("ct0002"))) { return ThreeBurnersCollectionRenderer; } + if ( + normalizedTemplate?.startsWith("m0015_ct000") && + normalizedTemplate !== "m0015_ct0007" + ) { + return SixStagesCollectionRenderer; + } if (code && collectionRenderers[code]) return collectionRenderers[code]; reportMissingRenderer("collection", code); @@ -272,6 +293,12 @@ export function resolveCollectionItemRenderer( if (normalizedTemplate === "m0017_ct0002" || (normalizedModule === "m0017" && normalizedTemplate?.includes("ct0002"))) { return ThreeBurnersCardRenderer; } + if ( + normalizedTemplate?.startsWith("m0015_ct000") && + normalizedTemplate !== "m0015_ct0007" + ) { + return SixStagesCardRenderer; + } if (code && collectionItemRenderers[code]) return collectionItemRenderers[code]; reportMissingRenderer("collection-item", code);