Merge pull request 'acupedia-acupoint' (#69) from acupedia-acupoint into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-mobile-ui/pulls/69 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
ec115ba9ce
|
|
@ -23,10 +23,11 @@ export function AcuPointIndexCardRenderer({ item, onPress }: CollectionItemRende
|
|||
}
|
||||
export function AcuPointCardRenderer({ item, onPress }: CollectionItemRendererProps) {
|
||||
const a = item.attributes;
|
||||
const altNames = [asString(a.alt_name_1), asString(a.alt_name_2)].filter(Boolean).join(" · ");
|
||||
const subtitle =
|
||||
altNames ||
|
||||
asString(a.pt_meaning) ||
|
||||
asString(a.channel) ||
|
||||
[asString(a.alt_name_1), asString(a.alt_name_2)].filter(Boolean).join(" · ");
|
||||
asString(a.channel);
|
||||
|
||||
return (
|
||||
<StandardIndexCard
|
||||
|
|
|
|||
|
|
@ -0,0 +1,134 @@
|
|||
import React, { useMemo } from "react";
|
||||
import { ScrollView, StyleSheet, Text, View } from "react-native";
|
||||
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 { asNumber, asString } from "../helpers/value";
|
||||
import { Hero } from "../shared/Hero";
|
||||
import { StandardIndexCard } from "../shared/StandardIndexCard";
|
||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||
|
||||
export function MeridianPointsDetailRenderer({
|
||||
moduleCode,
|
||||
content,
|
||||
data,
|
||||
}: DetailRendererProps) {
|
||||
const router = useRouter();
|
||||
const rawTitle = asString(data.name) || asString(data.title) || content.title;
|
||||
const pointValue = data.point_codes ?? data.points ?? data.point_list;
|
||||
const rawPoints = getNavigableContentReferences(pointValue);
|
||||
const totalCount = asNumber(data.content_count) || rawPoints.length;
|
||||
const countLabel = asString(data.content_label) || "points";
|
||||
|
||||
const targetTemplateCode = useMemo(() => {
|
||||
for (const ref of rawPoints) {
|
||||
if (ref.target?.template_code) {
|
||||
return ref.target.template_code;
|
||||
}
|
||||
}
|
||||
return "m0001_ct0003";
|
||||
}, [rawPoints]);
|
||||
|
||||
const { data: pointsData } = useModuleTemplateContentDetailsQuery({
|
||||
module_code: moduleCode || "m0001",
|
||||
template_code: targetTemplateCode,
|
||||
});
|
||||
|
||||
const detailsMap = useMemo(() => {
|
||||
const map = new Map<string, { title?: string; subtitle?: string }>();
|
||||
if (!pointsData?.items) return map;
|
||||
for (const item of pointsData.items) {
|
||||
const code =
|
||||
asString(item.data.code) || asString(item.data.name) || item.content.title;
|
||||
const alt1 = asString(item.data.alt_name_1);
|
||||
const alt2 = asString(item.data.alt_name_2);
|
||||
const subtitle = [alt1, alt2].filter(Boolean).join(" · ");
|
||||
const info = {
|
||||
title: code,
|
||||
subtitle: subtitle || undefined,
|
||||
};
|
||||
if (code) map.set(code.toLowerCase(), info);
|
||||
if (item.content.id) map.set(item.content.id, info);
|
||||
if (item.content.title) map.set(item.content.title.toLowerCase(), info);
|
||||
}
|
||||
return map;
|
||||
}, [pointsData?.items]);
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
contentContainerStyle={styles.content}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<Hero
|
||||
title={rawTitle}
|
||||
subtitle={totalCount ? `${totalCount} ${countLabel}` : undefined}
|
||||
/>
|
||||
|
||||
<View style={styles.list}>
|
||||
{rawPoints.map((ref, index) => {
|
||||
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() || sourceKey?.toLowerCase() || contentId;
|
||||
const info = key ? detailsMap.get(key) : undefined;
|
||||
const title = ref.label || info?.title || sourceKey || `Point ${index + 1}`;
|
||||
const subtitle = info?.subtitle || null;
|
||||
|
||||
return (
|
||||
<View
|
||||
key={contentId || `${title}-${index}`}
|
||||
style={styles.card}
|
||||
>
|
||||
<StandardIndexCard
|
||||
title={title}
|
||||
subtitle={subtitle}
|
||||
onPress={() =>
|
||||
router.push(buildContentReferenceRoute(ref) as never)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
|
||||
{rawPoints.length === 0 ? (
|
||||
<View style={styles.emptyContainer}>
|
||||
<Text style={styles.emptyText}>No points available for this channel.</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
content: {
|
||||
paddingHorizontal: moderateScale(18),
|
||||
paddingTop: verticalScale(16),
|
||||
paddingBottom: verticalScale(32),
|
||||
gap: verticalScale(14),
|
||||
},
|
||||
list: {
|
||||
gap: verticalScale(10),
|
||||
},
|
||||
card: {
|
||||
backgroundColor: "#FFFFFF",
|
||||
borderRadius: moderateScale(18),
|
||||
borderWidth: 1,
|
||||
borderColor: "#E2EAE5",
|
||||
overflow: "hidden",
|
||||
},
|
||||
emptyContainer: {
|
||||
padding: moderateScale(24),
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
emptyText: {
|
||||
fontSize: moderateScale(14),
|
||||
color: Colors.textSecondary,
|
||||
},
|
||||
});
|
||||
|
|
@ -11,6 +11,7 @@ import { AcuPointDetailRenderer } from "./details/AcuPointDetailRenderer";
|
|||
import { MeridianDetailRenderer } from "./details/MeridianDetailRenderer";
|
||||
import { EovDetailRenderer } from "./details/EovDetailRenderer";
|
||||
import { IndexEntryDetailRenderer } from "./details/IndexEntryDetailRenderer";
|
||||
import { MeridianPointsDetailRenderer } from "./details/MeridianPointsDetailRenderer";
|
||||
import { YuanSourceDetailRenderer } from "./details/YuanSourceDetailRenderer";
|
||||
import { LuoConnectingDetailRenderer } from "./details/LuoConnectingDetailRenderer";
|
||||
import { XiCleftDetailRenderer } from "./details/XiCleftDetailRenderer";
|
||||
|
|
@ -110,7 +111,8 @@ export const collectionItemRenderers: Readonly<Record<string, CollectionItemRend
|
|||
export const detailRenderers: Readonly<Record<string, DetailRendererComponent>> = Object.freeze({
|
||||
module_catalog_detail: IndexEntryDetailRenderer,
|
||||
acu_point_index_detail: IndexEntryDetailRenderer,
|
||||
meridian_index_detail: IndexEntryDetailRenderer,
|
||||
meridian_index_detail: MeridianPointsDetailRenderer,
|
||||
meridian_points_detail: MeridianPointsDetailRenderer,
|
||||
eov_index_detail: IndexEntryDetailRenderer,
|
||||
point_category_index_detail: IndexEntryDetailRenderer,
|
||||
acu_point_detail: AcuPointDetailRenderer,
|
||||
|
|
@ -291,6 +293,14 @@ export function resolveDetailRenderer(
|
|||
const normalizedModule = moduleCode?.trim().toLowerCase();
|
||||
const normalizedTemplate = templateCode?.trim().toLowerCase();
|
||||
|
||||
if (
|
||||
normalizedTemplate === "m0001_ct0002" ||
|
||||
code === "meridian_index_detail" ||
|
||||
code === "meridian_points_detail"
|
||||
) {
|
||||
return MeridianPointsDetailRenderer;
|
||||
}
|
||||
|
||||
if (
|
||||
normalizedTemplate === "m0016_ct0002" ||
|
||||
(normalizedModule === "m0016" && (code === "pattern_detail" || code === "module_catalog_detail"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue