Compare commits
No commits in common. "bf167e3f0a403133578bb4abe76596330a6df866" and "042c1cff3606e09359fd87d587fa2bef0198cf7a" have entirely different histories.
bf167e3f0a
...
042c1cff36
|
|
@ -16,9 +16,6 @@ const RESERVED_KEYS = new Set([
|
||||||
"link",
|
"link",
|
||||||
"food_name",
|
"food_name",
|
||||||
"foodname",
|
"foodname",
|
||||||
"content_count",
|
|
||||||
"content_label",
|
|
||||||
"food_items",
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,279 +0,0 @@
|
||||||
import React, { useMemo } from "react";
|
|
||||||
import {
|
|
||||||
ActivityIndicator,
|
|
||||||
Pressable,
|
|
||||||
ScrollView,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
View,
|
|
||||||
} from "react-native";
|
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
|
||||||
import { useRouter } from "expo-router";
|
|
||||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
||||||
|
|
||||||
import { Colors } from "@/theme";
|
|
||||||
import { useModuleTemplateContentDetailsQuery } from "../../hooks/use-content-queries";
|
|
||||||
import {
|
|
||||||
buildContentReferenceRoute,
|
|
||||||
getNavigableContentReferences,
|
|
||||||
} from "../../utils/content-reference";
|
|
||||||
import type { NavigableContentReference } from "../../types/content-reference.types";
|
|
||||||
import { asNumber, asString, asStringArray, humanizeKey } from "../helpers/value";
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
|
||||||
|
|
||||||
interface CategoryFoodItem {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
subtitle: string | null;
|
|
||||||
ref: NavigableContentReference;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function NutritionCategoryDetailRenderer({
|
|
||||||
moduleCode,
|
|
||||||
content,
|
|
||||||
data,
|
|
||||||
}: DetailRendererProps) {
|
|
||||||
const router = useRouter();
|
|
||||||
const rawTitle = asString(data.name) || content.title;
|
|
||||||
const normalizedCategory = rawTitle.toLowerCase().trim();
|
|
||||||
|
|
||||||
// Query all food items from m0031_ct0002
|
|
||||||
const { data: foodData, isLoading } = useModuleTemplateContentDetailsQuery({
|
|
||||||
module_code: moduleCode || "m0031",
|
|
||||||
template_code: "m0031_ct0002",
|
|
||||||
});
|
|
||||||
|
|
||||||
const items = useMemo(() => {
|
|
||||||
// Map of food item details from template m0031_ct0002
|
|
||||||
const foodMap = new Map<
|
|
||||||
string,
|
|
||||||
{
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
subtitle: string | null;
|
|
||||||
ref: NavigableContentReference;
|
|
||||||
}
|
|
||||||
>();
|
|
||||||
|
|
||||||
if (foodData?.items) {
|
|
||||||
for (const item of foodData.items) {
|
|
||||||
const foodName =
|
|
||||||
asString(item.data.food_name) ||
|
|
||||||
asString(item.data.name) ||
|
|
||||||
item.content.title;
|
|
||||||
const code = asString(item.data.code) || item.content.slug;
|
|
||||||
const temp = asString(item.data.temperature);
|
|
||||||
const taste = asStringArray(item.data.taste).join(", ");
|
|
||||||
const subtitle = [temp, taste].filter(Boolean).join(" · ") || null;
|
|
||||||
|
|
||||||
const ref: NavigableContentReference = {
|
|
||||||
type: "content_ref",
|
|
||||||
label: foodName,
|
|
||||||
target: {
|
|
||||||
module_code: moduleCode || "m0031",
|
|
||||||
template_code: "m0031_ct0002",
|
|
||||||
content_id: item.content.id,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const entry = {
|
|
||||||
id: item.content.id,
|
|
||||||
title: humanizeKey(foodName),
|
|
||||||
subtitle,
|
|
||||||
ref,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (code) foodMap.set(code.toLowerCase().trim(), entry);
|
|
||||||
if (foodName) foodMap.set(foodName.toLowerCase().trim(), entry);
|
|
||||||
if (item.content.id) foodMap.set(item.content.id, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Try references from data.food_items
|
|
||||||
const foodItemRefs = getNavigableContentReferences(data.food_items);
|
|
||||||
if (foodItemRefs.length > 0) {
|
|
||||||
return foodItemRefs.map((ref, idx): CategoryFoodItem => {
|
|
||||||
const contentId = ref.type === "content_ref" ? ref.target.content_id : undefined;
|
|
||||||
const sourceKey = ref.type === "content_ref" ? ref.target.source_key ?? undefined : undefined;
|
|
||||||
const key =
|
|
||||||
ref.label?.toLowerCase().trim() ||
|
|
||||||
sourceKey?.toLowerCase().trim() ||
|
|
||||||
contentId;
|
|
||||||
const info = key ? foodMap.get(key) : undefined;
|
|
||||||
return {
|
|
||||||
id: contentId || info?.id || `${ref.label}-${idx}`,
|
|
||||||
title: info?.title || humanizeKey(ref.label || `Item ${idx + 1}`),
|
|
||||||
subtitle: info?.subtitle || null,
|
|
||||||
ref: info?.ref || ref,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Fallback: filter foodData items by matching category
|
|
||||||
if (foodData?.items) {
|
|
||||||
const filtered = foodData.items.filter((item) => {
|
|
||||||
const itemCat = asString(item.data.category).toLowerCase().trim();
|
|
||||||
return itemCat === normalizedCategory;
|
|
||||||
});
|
|
||||||
|
|
||||||
return filtered.map((item): CategoryFoodItem => {
|
|
||||||
const foodName =
|
|
||||||
asString(item.data.food_name) ||
|
|
||||||
asString(item.data.name) ||
|
|
||||||
item.content.title;
|
|
||||||
const temp = asString(item.data.temperature);
|
|
||||||
const taste = asStringArray(item.data.taste).join(", ");
|
|
||||||
const subtitle = [temp, taste].filter(Boolean).join(" · ") || null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: item.content.id,
|
|
||||||
title: humanizeKey(foodName),
|
|
||||||
subtitle,
|
|
||||||
ref: {
|
|
||||||
type: "content_ref",
|
|
||||||
label: foodName,
|
|
||||||
target: {
|
|
||||||
module_code: moduleCode || "m0031",
|
|
||||||
template_code: "m0031_ct0002",
|
|
||||||
content_id: item.content.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}, [foodData, data.food_items, normalizedCategory, moduleCode]);
|
|
||||||
|
|
||||||
const totalCount = asNumber(data.content_count) || items.length;
|
|
||||||
|
|
||||||
if (isLoading && items.length === 0) {
|
|
||||||
return (
|
|
||||||
<View style={styles.center}>
|
|
||||||
<ActivityIndicator size="large" color={Colors.primary} />
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ScrollView
|
|
||||||
contentContainerStyle={styles.content}
|
|
||||||
showsVerticalScrollIndicator={false}
|
|
||||||
>
|
|
||||||
<Text style={styles.resultCount} accessibilityLiveRegion="polite">
|
|
||||||
{totalCount} {totalCount === 1 ? "ITEM" : "ITEMS"}
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<View style={styles.list}>
|
|
||||||
{items.map((item) => (
|
|
||||||
<View key={item.id} style={styles.card}>
|
|
||||||
<Pressable
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel={`Open ${item.title}`}
|
|
||||||
onPress={() => router.push(buildContentReferenceRoute(item.ref) as never)}
|
|
||||||
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
|
|
||||||
>
|
|
||||||
<View style={styles.iconWrapper}>
|
|
||||||
<Ionicons name="book-outline" size={22} color={Colors.primary} />
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={styles.textContainer}>
|
|
||||||
<Text style={styles.title}>{item.title}</Text>
|
|
||||||
{item.subtitle ? (
|
|
||||||
<Text numberOfLines={2} style={styles.subtitle}>
|
|
||||||
{item.subtitle}
|
|
||||||
</Text>
|
|
||||||
) : null}
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{items.length === 0 && !isLoading ? (
|
|
||||||
<View style={styles.emptyCard}>
|
|
||||||
<Text style={styles.emptyText}>No items found in this category.</Text>
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
</View>
|
|
||||||
</ScrollView>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
content: {
|
|
||||||
paddingHorizontal: moderateScale(18),
|
|
||||||
paddingTop: verticalScale(16),
|
|
||||||
paddingBottom: verticalScale(32),
|
|
||||||
},
|
|
||||||
center: {
|
|
||||||
paddingVertical: verticalScale(40),
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
},
|
|
||||||
resultCount: {
|
|
||||||
fontSize: moderateScale(12),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: Colors.textSecondary,
|
|
||||||
textTransform: "uppercase",
|
|
||||||
letterSpacing: 1,
|
|
||||||
marginBottom: verticalScale(12),
|
|
||||||
marginLeft: moderateScale(4),
|
|
||||||
},
|
|
||||||
list: {
|
|
||||||
gap: verticalScale(12),
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
borderRadius: moderateScale(18),
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#E2EAE5",
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
subtitle: {
|
|
||||||
fontSize: moderateScale(12),
|
|
||||||
color: Colors.textSecondary,
|
|
||||||
marginTop: verticalScale(2),
|
|
||||||
lineHeight: moderateScale(16),
|
|
||||||
},
|
|
||||||
emptyCard: {
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
borderRadius: moderateScale(18),
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: "#E2EAE5",
|
|
||||||
padding: moderateScale(24),
|
|
||||||
alignItems: "center",
|
|
||||||
},
|
|
||||||
emptyText: {
|
|
||||||
fontSize: moderateScale(14),
|
|
||||||
color: Colors.textSecondary,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
@ -53,7 +53,6 @@ import { SixStagesCollectionRenderer, SixStagesCardRenderer } from "./collection
|
||||||
import { SixStagesDetailRenderer } from "./details/SixStagesDetailRenderer";
|
import { SixStagesDetailRenderer } from "./details/SixStagesDetailRenderer";
|
||||||
import { TcmPatternDetailRenderer } from "./details/TcmPatternDetailRenderer";
|
import { TcmPatternDetailRenderer } from "./details/TcmPatternDetailRenderer";
|
||||||
import { ExtraOrdinaryVesselsDetailRenderer } from "./details/ExtraOrdinaryVesselsDetailRenderer";
|
import { ExtraOrdinaryVesselsDetailRenderer } from "./details/ExtraOrdinaryVesselsDetailRenderer";
|
||||||
import { NutritionCategoryDetailRenderer } from "./details/NutritionCategoryDetailRenderer";
|
|
||||||
|
|
||||||
export const collectionRenderers: Readonly<Record<string, CollectionRendererComponent>> = Object.freeze({
|
export const collectionRenderers: Readonly<Record<string, CollectionRendererComponent>> = Object.freeze({
|
||||||
module_catalog_collection: ModuleCatalogCollectionRenderer,
|
module_catalog_collection: ModuleCatalogCollectionRenderer,
|
||||||
|
|
@ -71,7 +70,6 @@ export const collectionRenderers: Readonly<Record<string, CollectionRendererComp
|
||||||
pathogenic_factors_collection: PathogenicFactorsCollectionRenderer,
|
pathogenic_factors_collection: PathogenicFactorsCollectionRenderer,
|
||||||
chinese_scalp_acupuncture_collection: ModuleCatalogCollectionRenderer,
|
chinese_scalp_acupuncture_collection: ModuleCatalogCollectionRenderer,
|
||||||
nutrition_food_collection: ModuleCatalogCollectionRenderer,
|
nutrition_food_collection: ModuleCatalogCollectionRenderer,
|
||||||
nutrition_category_collection: ModuleCatalogCollectionRenderer,
|
|
||||||
nutrition_effect_collection: ModuleCatalogCollectionRenderer,
|
nutrition_effect_collection: ModuleCatalogCollectionRenderer,
|
||||||
disease_collection: ModuleCatalogCollectionRenderer,
|
disease_collection: ModuleCatalogCollectionRenderer,
|
||||||
auriculotherapy_collection: ModuleCatalogCollectionRenderer,
|
auriculotherapy_collection: ModuleCatalogCollectionRenderer,
|
||||||
|
|
@ -96,7 +94,6 @@ export const collectionItemRenderers: Readonly<Record<string, CollectionItemRend
|
||||||
five_elements_card: FiveElementsCardRenderer,
|
five_elements_card: FiveElementsCardRenderer,
|
||||||
chinese_scalp_acupuncture_card: ModuleCatalogCardRenderer,
|
chinese_scalp_acupuncture_card: ModuleCatalogCardRenderer,
|
||||||
nutrition_food_card: ModuleCatalogCardRenderer,
|
nutrition_food_card: ModuleCatalogCardRenderer,
|
||||||
nutrition_category_card: ModuleCatalogCardRenderer,
|
|
||||||
nutrition_effect_card: ModuleCatalogCardRenderer,
|
nutrition_effect_card: ModuleCatalogCardRenderer,
|
||||||
disease_card: ModuleCatalogCardRenderer,
|
disease_card: ModuleCatalogCardRenderer,
|
||||||
auriculotherapy_card: ModuleCatalogCardRenderer,
|
auriculotherapy_card: ModuleCatalogCardRenderer,
|
||||||
|
|
@ -106,7 +103,6 @@ export const collectionItemRenderers: Readonly<Record<string, CollectionItemRend
|
||||||
export const detailRenderers: Readonly<Record<string, DetailRendererComponent>> = Object.freeze({
|
export const detailRenderers: Readonly<Record<string, DetailRendererComponent>> = Object.freeze({
|
||||||
extra_ordinary_vessel_detail: ExtraOrdinaryVesselsDetailRenderer,
|
extra_ordinary_vessel_detail: ExtraOrdinaryVesselsDetailRenderer,
|
||||||
module_catalog_detail: IndexEntryDetailRenderer,
|
module_catalog_detail: IndexEntryDetailRenderer,
|
||||||
nutrition_category_detail: NutritionCategoryDetailRenderer,
|
|
||||||
acu_point_index_detail: IndexEntryDetailRenderer,
|
acu_point_index_detail: IndexEntryDetailRenderer,
|
||||||
meridian_index_detail: MeridianPointsDetailRenderer,
|
meridian_index_detail: MeridianPointsDetailRenderer,
|
||||||
meridian_points_detail: MeridianPointsDetailRenderer,
|
meridian_points_detail: MeridianPointsDetailRenderer,
|
||||||
|
|
@ -330,13 +326,6 @@ export function resolveDetailRenderer(
|
||||||
return MeridianPointsDetailRenderer;
|
return MeridianPointsDetailRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
normalizedTemplate === "m0031_ct0003" ||
|
|
||||||
code === "nutrition_category_detail"
|
|
||||||
) {
|
|
||||||
return NutritionCategoryDetailRenderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
normalizedTemplate === "m0016_ct0002" ||
|
normalizedTemplate === "m0016_ct0002" ||
|
||||||
(normalizedModule === "m0016" && (code === "pattern_detail" || code === "module_catalog_detail"))
|
(normalizedModule === "m0016" && (code === "pattern_detail" || code === "module_catalog_detail"))
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ const MODULE_VISUALS: Record<string, ModuleVisualConfig> = {
|
||||||
color: "#10B981",
|
color: "#10B981",
|
||||||
isDefaultFree: true,
|
isDefaultFree: true,
|
||||||
planCode: "NUTRITION_CORE",
|
planCode: "NUTRITION_CORE",
|
||||||
entryTemplateCode: "m0031_ct0001",
|
entryTemplateCode: "m0031_ct0002",
|
||||||
},
|
},
|
||||||
m0041: {
|
m0041: {
|
||||||
icon: "body-outline",
|
icon: "body-outline",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue