Compare commits
23 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
ededd6f0c1 | |
|
|
053d08eb5d | |
|
|
967aec6403 | |
|
|
5d76e8ba19 | |
|
|
6291c325eb | |
|
|
e153668f06 | |
|
|
4453a2a96c | |
|
|
e442a9825a | |
|
|
b052bb97d7 | |
|
|
68e8c2a07b | |
|
|
b2c70e1b2e | |
|
|
49fe5196ef | |
|
|
ac89c8a834 | |
|
|
4b0a6b5669 | |
|
|
4885ac72b9 | |
|
|
eee01a5211 | |
|
|
e24e235d18 | |
|
|
550de8025c | |
|
|
8990f90132 | |
|
|
effed053b8 | |
|
|
0f68e31285 | |
|
|
8a158258ef | |
|
|
7e75204237 |
|
|
@ -1,9 +1,11 @@
|
||||||
|
import { useState } from "react";
|
||||||
import { Tabs, router } from "expo-router";
|
import { Tabs, router } from "expo-router";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { Alert, Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
import { AuthColors } from "@/features/auth/constants/colors";
|
import { AuthColors } from "@/features/auth/constants/colors";
|
||||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||||
import { useAuthStore } from "@/store/auth.store";
|
import { useAuthStore } from "@/store/auth.store";
|
||||||
|
import LogoutConfirmModal from "@/components/LogoutConfirmModal";
|
||||||
|
|
||||||
export default function TabsLayout() {
|
export default function TabsLayout() {
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
|
|
@ -13,40 +15,24 @@ export default function TabsLayout() {
|
||||||
|
|
||||||
const { accessToken, logout } = useAuthStore();
|
const { accessToken, logout } = useAuthStore();
|
||||||
const isAuthenticated = !!accessToken;
|
const isAuthenticated = !!accessToken;
|
||||||
|
const [logoutModalVisible, setLogoutModalVisible] = useState(false);
|
||||||
|
|
||||||
const handleAuthAction = () => {
|
|
||||||
if (isAuthenticated) {
|
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
|
setLogoutModalVisible(false);
|
||||||
logout();
|
logout();
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Platform.OS === "web") {
|
const handleAuthAction = () => {
|
||||||
const confirmed = typeof window !== "undefined" ? window.confirm("Are you sure you want to logout?") : true;
|
if (isAuthenticated) {
|
||||||
if (confirmed) {
|
setLogoutModalVisible(true);
|
||||||
doLogout();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Alert.alert(
|
|
||||||
"Logout",
|
|
||||||
"Are you sure you want to logout?",
|
|
||||||
[
|
|
||||||
{ text: "Cancel", style: "cancel" },
|
|
||||||
{
|
|
||||||
text: "Yes",
|
|
||||||
style: "destructive",
|
|
||||||
onPress: doLogout,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{ cancelable: true }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Tabs
|
<Tabs
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
headerShown: false,
|
headerShown: false,
|
||||||
|
|
@ -142,5 +128,11 @@ export default function TabsLayout() {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
<LogoutConfirmModal
|
||||||
|
visible={logoutModalVisible}
|
||||||
|
onCancel={() => setLogoutModalVisible(false)}
|
||||||
|
onConfirm={doLogout}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,11 @@ export default function LibraryScreen() {
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
isNavigatingRef.current = false;
|
isNavigatingRef.current = false;
|
||||||
|
void modulesQuery.refetch().catch((error) => console.warn("Unable to refresh modules:", error));
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
void refreshAccess().catch((error) => console.warn("Unable to refresh library access:", error));
|
void refreshAccess().catch((error) => console.warn("Unable to refresh library access:", error));
|
||||||
}
|
}
|
||||||
}, [accessToken, refreshAccess]),
|
}, [accessToken, modulesQuery.refetch, refreshAccess]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,6 @@ export default function ChangePasswordScreen() {
|
||||||
if (!newPassword) {
|
if (!newPassword) {
|
||||||
setNewError("New password is required");
|
setNewError("New password is required");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (currentPassword && newPassword === currentPassword) {
|
|
||||||
setNewError("New password cannot be the same as current password");
|
|
||||||
hasError = true;
|
|
||||||
} else if (newPassword.length < 8) {
|
} else if (newPassword.length < 8) {
|
||||||
setNewError("New password must be at least 8 characters");
|
setNewError("New password must be at least 8 characters");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
|
@ -97,6 +94,16 @@ export default function ChangePasswordScreen() {
|
||||||
errMsg.toLowerCase().includes("same")
|
errMsg.toLowerCase().includes("same")
|
||||||
) {
|
) {
|
||||||
setNewError(errMsg);
|
setNewError(errMsg);
|
||||||
|
} else if (
|
||||||
|
typeof errMsg === "string" &&
|
||||||
|
(errMsg.toLowerCase().includes("current") || errMsg.toLowerCase().includes("old"))
|
||||||
|
) {
|
||||||
|
setCurrentError(errMsg);
|
||||||
|
} else if (
|
||||||
|
typeof errMsg === "string" &&
|
||||||
|
errMsg.toLowerCase().includes("confirm")
|
||||||
|
) {
|
||||||
|
setConfirmError(errMsg);
|
||||||
} else {
|
} else {
|
||||||
setCurrentError(errMsg);
|
setCurrentError(errMsg);
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +131,10 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="Current Password" required />
|
<FieldLabel label="Current Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={currentPassword}
|
value={currentPassword}
|
||||||
onChangeText={setCurrentPassword}
|
onChangeText={(text) => {
|
||||||
|
setCurrentPassword(text);
|
||||||
|
if (currentError) setCurrentError("");
|
||||||
|
}}
|
||||||
placeholder="Enter current password"
|
placeholder="Enter current password"
|
||||||
error={currentError}
|
error={currentError}
|
||||||
/>
|
/>
|
||||||
|
|
@ -134,7 +144,10 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="New Password" required />
|
<FieldLabel label="New Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={newPassword}
|
value={newPassword}
|
||||||
onChangeText={setNewPassword}
|
onChangeText={(text) => {
|
||||||
|
setNewPassword(text);
|
||||||
|
if (newError) setNewError("");
|
||||||
|
}}
|
||||||
placeholder="Min. 8 characters with numbers & symbols"
|
placeholder="Min. 8 characters with numbers & symbols"
|
||||||
error={newError}
|
error={newError}
|
||||||
/>
|
/>
|
||||||
|
|
@ -144,7 +157,10 @@ export default function ChangePasswordScreen() {
|
||||||
<FieldLabel label="Confirm New Password" required />
|
<FieldLabel label="Confirm New Password" required />
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
value={confirmPassword}
|
value={confirmPassword}
|
||||||
onChangeText={setConfirmPassword}
|
onChangeText={(text) => {
|
||||||
|
setConfirmPassword(text);
|
||||||
|
if (confirmError) setConfirmError("");
|
||||||
|
}}
|
||||||
placeholder="Re-enter new password"
|
placeholder="Re-enter new password"
|
||||||
error={confirmError}
|
error={confirmError}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
import React from "react";
|
||||||
|
import {
|
||||||
|
Modal,
|
||||||
|
Pressable,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
TouchableOpacity,
|
||||||
|
View,
|
||||||
|
} from "react-native";
|
||||||
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
import { moderateScale, scale, verticalScale } from "react-native-size-matters";
|
||||||
|
|
||||||
|
import { Colors } from "@/theme";
|
||||||
|
|
||||||
|
interface LogoutConfirmModalProps {
|
||||||
|
visible: boolean;
|
||||||
|
onCancel: () => void;
|
||||||
|
onConfirm: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function LogoutConfirmModal({
|
||||||
|
visible,
|
||||||
|
onCancel,
|
||||||
|
onConfirm,
|
||||||
|
}: LogoutConfirmModalProps) {
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
visible={visible}
|
||||||
|
transparent
|
||||||
|
animationType="fade"
|
||||||
|
onRequestClose={onCancel}
|
||||||
|
>
|
||||||
|
<Pressable style={styles.backdrop} onPress={onCancel}>
|
||||||
|
<Pressable style={styles.card} onPress={() => {}}>
|
||||||
|
<View style={styles.iconContainer}>
|
||||||
|
<Ionicons name="log-out-outline" size={26} color="#DC2626" />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<Text style={styles.title}>Log Out</Text>
|
||||||
|
<Text style={styles.message}>
|
||||||
|
Are you sure you want to log out of Acupedia?
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<View style={styles.actions}>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[styles.button, styles.cancelButton]}
|
||||||
|
onPress={onCancel}
|
||||||
|
activeOpacity={0.8}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Cancel"
|
||||||
|
>
|
||||||
|
<Text style={styles.cancelText}>Cancel</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[styles.button, styles.confirmButton]}
|
||||||
|
onPress={onConfirm}
|
||||||
|
activeOpacity={0.8}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Log Out"
|
||||||
|
>
|
||||||
|
<Text style={styles.confirmText}>Log Out</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
</Pressable>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
backdrop: {
|
||||||
|
flex: 1,
|
||||||
|
backgroundColor: "rgba(15, 23, 42, 0.55)",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
paddingHorizontal: scale(24),
|
||||||
|
},
|
||||||
|
card: {
|
||||||
|
width: "100%",
|
||||||
|
maxWidth: 360,
|
||||||
|
backgroundColor: Colors.surface ?? "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(20),
|
||||||
|
padding: moderateScale(22),
|
||||||
|
alignItems: "center",
|
||||||
|
shadowColor: "#000",
|
||||||
|
shadowOffset: { width: 0, height: 10 },
|
||||||
|
shadowOpacity: 0.18,
|
||||||
|
shadowRadius: 20,
|
||||||
|
elevation: 8,
|
||||||
|
},
|
||||||
|
iconContainer: {
|
||||||
|
width: scale(48),
|
||||||
|
height: scale(48),
|
||||||
|
borderRadius: scale(24),
|
||||||
|
backgroundColor: "#FEE2E2",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: verticalScale(12),
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontSize: moderateScale(18),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textPrimary ?? "#0F172A",
|
||||||
|
marginBottom: verticalScale(6),
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
color: Colors.textSecondary ?? "#475569",
|
||||||
|
textAlign: "center",
|
||||||
|
lineHeight: moderateScale(20),
|
||||||
|
marginBottom: verticalScale(20),
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
flexDirection: "row",
|
||||||
|
gap: scale(10),
|
||||||
|
width: "100%",
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
flex: 1,
|
||||||
|
paddingVertical: verticalScale(11),
|
||||||
|
borderRadius: moderateScale(12),
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
},
|
||||||
|
cancelButton: {
|
||||||
|
backgroundColor: "#F1F5F9",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2E8F0",
|
||||||
|
},
|
||||||
|
confirmButton: {
|
||||||
|
backgroundColor: "#DC2626",
|
||||||
|
},
|
||||||
|
cancelText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
fontWeight: "600",
|
||||||
|
color: "#334155",
|
||||||
|
},
|
||||||
|
confirmText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#FFFFFF",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
@ -15,7 +15,7 @@ export function useModulesQuery() {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: contentQueryKeys.modules(preview),
|
queryKey: contentQueryKeys.modules(preview),
|
||||||
queryFn: () => contentApi.getModules(preview),
|
queryFn: () => contentApi.getModules(preview),
|
||||||
staleTime: 10 * 60 * 1000,
|
staleTime: 30 * 1000,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,21 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
||||||
const [viewerIndex, setViewerIndex] = useState<number | null>(null);
|
const [viewerIndex, setViewerIndex] = useState<number | null>(null);
|
||||||
const listRef = useRef<FlatList<ContentMediaItem>>(null);
|
const listRef = useRef<FlatList<ContentMediaItem>>(null);
|
||||||
|
|
||||||
|
const MAX_VISIBLE_DOTS = 7;
|
||||||
|
const visibleDots = useMemo(() => {
|
||||||
|
if (items.length <= MAX_VISIBLE_DOTS) {
|
||||||
|
return items.map((item, index) => ({ item, index }));
|
||||||
|
}
|
||||||
|
const half = Math.floor(MAX_VISIBLE_DOTS / 2);
|
||||||
|
let start = Math.max(0, activeIndex - half);
|
||||||
|
let end = start + MAX_VISIBLE_DOTS;
|
||||||
|
if (end > items.length) {
|
||||||
|
end = items.length;
|
||||||
|
start = Math.max(0, end - MAX_VISIBLE_DOTS);
|
||||||
|
}
|
||||||
|
return items.slice(start, end).map((item, i) => ({ item, index: start + i }));
|
||||||
|
}, [items, activeIndex]);
|
||||||
|
|
||||||
if (!items.length) return null;
|
if (!items.length) return null;
|
||||||
|
|
||||||
const handleMomentumEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
const handleMomentumEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||||
|
|
@ -169,6 +184,12 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
||||||
offset: carouselWidth * index,
|
offset: carouselWidth * index,
|
||||||
index,
|
index,
|
||||||
})}
|
})}
|
||||||
|
onScrollToIndexFailed={(info) => {
|
||||||
|
listRef.current?.scrollToOffset({
|
||||||
|
offset: info.index * carouselWidth,
|
||||||
|
animated: true,
|
||||||
|
});
|
||||||
|
}}
|
||||||
onMomentumScrollEnd={handleMomentumEnd}
|
onMomentumScrollEnd={handleMomentumEnd}
|
||||||
renderItem={({ item, index }) => (
|
renderItem={({ item, index }) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
|
|
@ -192,12 +213,16 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
||||||
|
|
||||||
{items.length > 1 ? (
|
{items.length > 1 ? (
|
||||||
<View style={styles.dots} accessibilityElementsHidden>
|
<View style={styles.dots} accessibilityElementsHidden>
|
||||||
{items.map((item, index) => (
|
{visibleDots.map(({ item, index }) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={item.id}
|
key={item.id}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setActiveIndex(index);
|
setActiveIndex(index);
|
||||||
|
try {
|
||||||
listRef.current?.scrollToIndex({ index, animated: true });
|
listRef.current?.scrollToIndex({ index, animated: true });
|
||||||
|
} catch {
|
||||||
|
listRef.current?.scrollToOffset({ offset: index * carouselWidth, animated: true });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
hitSlop={6}
|
hitSlop={6}
|
||||||
>
|
>
|
||||||
|
|
@ -254,7 +279,12 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
zoomText: { color: Colors.white, fontSize: 12, fontWeight: "700" },
|
zoomText: { color: Colors.white, fontSize: 12, fontWeight: "700" },
|
||||||
caption: { color: Colors.textSecondary, fontSize: 13, lineHeight: 19, textAlign: "center" },
|
caption: { color: Colors.textSecondary, fontSize: 13, lineHeight: 19, textAlign: "center" },
|
||||||
dots: { flexDirection: "row", flexWrap: "wrap", justifyContent: "center", gap: 7 },
|
dots: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
gap: 7,
|
||||||
|
},
|
||||||
dot: { width: 7, height: 7, borderRadius: 4, backgroundColor: Colors.border },
|
dot: { width: 7, height: 7, borderRadius: 4, backgroundColor: Colors.border },
|
||||||
dotActive: { width: 18, backgroundColor: Colors.primary },
|
dotActive: { width: 18, backgroundColor: Colors.primary },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import React, { useMemo } from "react";
|
||||||
import { ScrollView } from "react-native";
|
import { ScrollView } from "react-native";
|
||||||
|
|
||||||
import type { DetailRendererProps } from "../types/renderer.types";
|
import type { DetailRendererProps } from "../types/renderer.types";
|
||||||
import { humanizeKey } from "./helpers/value";
|
import { buildDefinitionLabelMap, humanizeKey, resolveAttributeLabel } from "./helpers/value";
|
||||||
import { ContentValue } from "./shared/ContentValue";
|
import { ContentValue } from "./shared/ContentValue";
|
||||||
import { Hero } from "./shared/Hero";
|
import { Hero } from "./shared/Hero";
|
||||||
import { ImageGallery } from "./shared/ImageGallery";
|
import { ImageGallery } from "./shared/ImageGallery";
|
||||||
|
|
@ -40,10 +40,7 @@ export function GenericDetailRenderer({
|
||||||
);
|
);
|
||||||
|
|
||||||
const definitionMap = useMemo(
|
const definitionMap = useMemo(
|
||||||
() =>
|
() => buildDefinitionLabelMap(definitions),
|
||||||
new Map(
|
|
||||||
(definitions ?? []).map((d) => [d.code, d.label]),
|
|
||||||
),
|
|
||||||
[definitions],
|
[definitions],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -73,8 +70,7 @@ export function GenericDetailRenderer({
|
||||||
!(isTherapeutic && key.toLowerCase() === "name"),
|
!(isTherapeutic && key.toLowerCase() === "name"),
|
||||||
)
|
)
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
const rawLabel = definitionMap.get(key) || key;
|
const label = resolveAttributeLabel(key, definitionMap);
|
||||||
const label = humanizeKey(rawLabel);
|
|
||||||
return (
|
return (
|
||||||
<SectionCard key={key} title={label}>
|
<SectionCard key={key} title={label}>
|
||||||
<ContentValue value={value} />
|
<ContentValue value={value} />
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,13 @@ export function GynecologyDiseaseCollectionRenderer(
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
return <CollectionScaffold {...props} header={header} />;
|
return (
|
||||||
|
<CollectionScaffold
|
||||||
|
{...props}
|
||||||
|
header={header}
|
||||||
|
countLabel="Identifications of patterns"
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createGynecologyDiseaseCollectionRenderer(templateCode: string) {
|
export function createGynecologyDiseaseCollectionRenderer(templateCode: string) {
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,21 @@ import { useRouter } from "expo-router";
|
||||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
|
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import { asNumber, asString, asStringArray, humanizeKey } from "../helpers/value";
|
import {
|
||||||
|
asNumber,
|
||||||
|
asString,
|
||||||
|
asStringArray,
|
||||||
|
buildDefinitionLabelMap,
|
||||||
|
humanizeKey,
|
||||||
|
resolveAttributeLabel,
|
||||||
|
} from "../helpers/value";
|
||||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||||
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
||||||
import { greenTone } from "../shared/reading-palette";
|
import { greenTone } from "../shared/reading-palette";
|
||||||
import {
|
import {
|
||||||
useModuleContentDetailQuery,
|
useModuleContentDetailQuery,
|
||||||
useModuleTemplateContentDetailsQuery,
|
useModuleTemplateContentDetailsQuery,
|
||||||
|
useTemplateDefinitionsQuery,
|
||||||
} from "../../hooks/use-content-queries";
|
} from "../../hooks/use-content-queries";
|
||||||
import type {
|
import type {
|
||||||
CollectionItemRendererProps,
|
CollectionItemRendererProps,
|
||||||
|
|
@ -35,6 +43,10 @@ export function ModuleCatalogCollectionRenderer(props: CollectionRendererProps)
|
||||||
return <CollectionScaffold {...props} />;
|
return <CollectionScaffold {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripTrailingPeriod(value: string): string {
|
||||||
|
return value.replace(/\s*\.+\s*$/, "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
function normalizePointCode(raw: string): string {
|
function normalizePointCode(raw: string): string {
|
||||||
let code = raw.replace(/\s*\([^)]*\)/g, "").trim().toLowerCase();
|
let code = raw.replace(/\s*\([^)]*\)/g, "").trim().toLowerCase();
|
||||||
code = code.replace(/^ren-/, "cv-");
|
code = code.replace(/^ren-/, "cv-");
|
||||||
|
|
@ -70,6 +82,16 @@ export function PatternAccordionCardRenderer({
|
||||||
contentId,
|
contentId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const detailTemplateCode =
|
||||||
|
asString(linkTarget?.template_code) ||
|
||||||
|
asString(detailQuery.data?.content?.metadata?.template_code) ||
|
||||||
|
(moduleCode.toLowerCase() === "m0042" ? "m0042_ct0005" : "");
|
||||||
|
const templateDefsQuery = useTemplateDefinitionsQuery(detailTemplateCode || undefined);
|
||||||
|
const labelMap = useMemo(
|
||||||
|
() => buildDefinitionLabelMap(templateDefsQuery.data?.attributes),
|
||||||
|
[templateDefsQuery.data?.attributes],
|
||||||
|
);
|
||||||
|
|
||||||
// Query all acupuncture points from m0001 to resolve links
|
// Query all acupuncture points from m0001 to resolve links
|
||||||
const { data: pointsData } = useModuleTemplateContentDetailsQuery({
|
const { data: pointsData } = useModuleTemplateContentDetailsQuery({
|
||||||
module_code: "m0001",
|
module_code: "m0001",
|
||||||
|
|
@ -138,8 +160,8 @@ export function PatternAccordionCardRenderer({
|
||||||
? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean)
|
? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const tongue = asString(detailData.tongue);
|
const tongue = stripTrailingPeriod(asString(detailData.tongue));
|
||||||
const pulse = asString(detailData.pulse);
|
const pulse = stripTrailingPeriod(asString(detailData.pulse));
|
||||||
const rawPrinciples = detailData.treatment_principle;
|
const rawPrinciples = detailData.treatment_principle;
|
||||||
const treatmentPrinciples: string[] = Array.isArray(rawPrinciples)
|
const treatmentPrinciples: string[] = Array.isArray(rawPrinciples)
|
||||||
? (rawPrinciples as string[]).map(String).map((s) => s.trim()).filter(Boolean)
|
? (rawPrinciples as string[]).map(String).map((s) => s.trim()).filter(Boolean)
|
||||||
|
|
@ -213,7 +235,7 @@ export function PatternAccordionCardRenderer({
|
||||||
{clinicalManifestations.length > 0 ? (
|
{clinicalManifestations.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
Clinical Manifestations
|
{resolveAttributeLabel("clinical_manifestations", labelMap, "Clinical Manifestations")}
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.bulletList}>
|
<View style={accordionStyles.bulletList}>
|
||||||
{clinicalManifestations.map((itemText, idx) => (
|
{clinicalManifestations.map((itemText, idx) => (
|
||||||
|
|
@ -226,22 +248,23 @@ export function PatternAccordionCardRenderer({
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 2. Tongue & Pulse (Side-by-Side as drawn) */}
|
{/* 2. Tongue */}
|
||||||
{tongue || pulse ? (
|
|
||||||
<View style={accordionStyles.twoColumnBox}>
|
|
||||||
{tongue ? (
|
{tongue ? (
|
||||||
<View style={accordionStyles.column}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.columnLabel}>Tongue</Text>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
<Text style={accordionStyles.columnValue}>{tongue}</Text>
|
{resolveAttributeLabel("tongue", labelMap, "Tongue")}
|
||||||
|
</Text>
|
||||||
|
<Text style={accordionStyles.sectionText}>{tongue}</Text>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
{tongue && pulse ? <View style={accordionStyles.columnDivider} /> : null}
|
|
||||||
|
{/* 3. Pulse */}
|
||||||
{pulse ? (
|
{pulse ? (
|
||||||
<View style={accordionStyles.column}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.columnLabel}>Pulse</Text>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
<Text style={accordionStyles.columnValue}>{pulse}</Text>
|
{resolveAttributeLabel("pulse", labelMap, "Pulse")}
|
||||||
</View>
|
</Text>
|
||||||
) : null}
|
<Text style={accordionStyles.sectionText}>{pulse}</Text>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
@ -249,7 +272,7 @@ export function PatternAccordionCardRenderer({
|
||||||
{treatmentPrinciples.length > 0 ? (
|
{treatmentPrinciples.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
Treatment Principle
|
{resolveAttributeLabel("treatment_principle", labelMap, "Treatment Principle")}
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.bulletList}>
|
<View style={accordionStyles.bulletList}>
|
||||||
{treatmentPrinciples.map((itemText, idx) => (
|
{treatmentPrinciples.map((itemText, idx) => (
|
||||||
|
|
@ -262,13 +285,12 @@ export function PatternAccordionCardRenderer({
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 4. Acupuncture Points & Method */}
|
{/* 4. Acupuncture Points */}
|
||||||
{pointChips.length > 0 || acuMethod ? (
|
{pointChips.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
Acupuncture Points
|
{resolveAttributeLabel("acupuncture", labelMap, "Acupuncture Points")}
|
||||||
</Text>
|
</Text>
|
||||||
{pointChips.length > 0 ? (
|
|
||||||
<View style={accordionStyles.chipsContainer}>
|
<View style={accordionStyles.chipsContainer}>
|
||||||
{pointChips.map((pt, idx) => (
|
{pointChips.map((pt, idx) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
|
|
@ -291,13 +313,16 @@ export function PatternAccordionCardRenderer({
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
|
||||||
{acuMethod ? (
|
|
||||||
<View style={accordionStyles.methodContainer}>
|
|
||||||
<Text style={accordionStyles.subSectionLabel}>Method:</Text>
|
|
||||||
<Text style={accordionStyles.methodText}>{acuMethod}</Text>
|
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
{/* 5. Method */}
|
||||||
|
{acuMethod ? (
|
||||||
|
<View style={accordionStyles.section}>
|
||||||
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
|
{resolveAttributeLabel("acupuncture.method", labelMap, "Method")}
|
||||||
|
</Text>
|
||||||
|
<Text style={accordionStyles.sectionText}>{acuMethod}</Text>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
@ -305,7 +330,7 @@ export function PatternAccordionCardRenderer({
|
||||||
{explanations.length > 0 ? (
|
{explanations.length > 0 ? (
|
||||||
<View style={accordionStyles.section}>
|
<View style={accordionStyles.section}>
|
||||||
<Text style={accordionStyles.sectionTitle}>
|
<Text style={accordionStyles.sectionTitle}>
|
||||||
Explanation
|
{resolveAttributeLabel("explanation", labelMap, "Explanation")}
|
||||||
</Text>
|
</Text>
|
||||||
<View style={accordionStyles.explanationList}>
|
<View style={accordionStyles.explanationList}>
|
||||||
{explanations.map((exp, idx) => (
|
{explanations.map((exp, idx) => (
|
||||||
|
|
@ -321,7 +346,9 @@ export function PatternAccordionCardRenderer({
|
||||||
{/* 6. Category */}
|
{/* 6. Category */}
|
||||||
{category ? (
|
{category ? (
|
||||||
<View style={accordionStyles.categoryRow}>
|
<View style={accordionStyles.categoryRow}>
|
||||||
<Text style={accordionStyles.categoryLabel}>Category:</Text>
|
<Text style={accordionStyles.categoryLabel}>
|
||||||
|
{`${resolveAttributeLabel("category", labelMap, "Category")}:`}
|
||||||
|
</Text>
|
||||||
<View style={accordionStyles.categoryBadge}>
|
<View style={accordionStyles.categoryBadge}>
|
||||||
<Text style={accordionStyles.categoryBadgeText}>{category}</Text>
|
<Text style={accordionStyles.categoryBadgeText}>{category}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -495,8 +522,7 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(16),
|
lineHeight: moderateScale(16),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#4A6B5B",
|
color: "#4A6B5B",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.7,
|
|
||||||
},
|
},
|
||||||
bulletList: {
|
bulletList: {
|
||||||
gap: verticalScale(8),
|
gap: verticalScale(8),
|
||||||
|
|
@ -519,38 +545,10 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(21),
|
lineHeight: moderateScale(21),
|
||||||
color: "#334155",
|
color: "#334155",
|
||||||
},
|
},
|
||||||
twoColumnBox: {
|
sectionText: {
|
||||||
flexDirection: "row",
|
|
||||||
backgroundColor: greenTone.soft,
|
|
||||||
borderRadius: moderateScale(10),
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: greenTone.border,
|
|
||||||
paddingHorizontal: moderateScale(14),
|
|
||||||
paddingVertical: verticalScale(11),
|
|
||||||
alignItems: "stretch",
|
|
||||||
},
|
|
||||||
column: {
|
|
||||||
flex: 1,
|
|
||||||
gap: verticalScale(3),
|
|
||||||
},
|
|
||||||
columnDivider: {
|
|
||||||
width: StyleSheet.hairlineWidth,
|
|
||||||
backgroundColor: greenTone.border,
|
|
||||||
marginHorizontal: moderateScale(12),
|
|
||||||
},
|
|
||||||
columnLabel: {
|
|
||||||
fontSize: moderateScale(11),
|
|
||||||
lineHeight: moderateScale(15),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: "#597064",
|
|
||||||
textTransform: "uppercase",
|
|
||||||
letterSpacing: 0.5,
|
|
||||||
},
|
|
||||||
columnValue: {
|
|
||||||
fontSize: moderateScale(14),
|
fontSize: moderateScale(14),
|
||||||
lineHeight: moderateScale(20),
|
lineHeight: moderateScale(21),
|
||||||
color: "#1E293B",
|
color: "#334155",
|
||||||
fontWeight: "600",
|
|
||||||
},
|
},
|
||||||
principleBox: {
|
principleBox: {
|
||||||
backgroundColor: greenTone.soft,
|
backgroundColor: greenTone.soft,
|
||||||
|
|
@ -591,23 +589,6 @@ const accordionStyles = StyleSheet.create({
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#35664E",
|
color: "#35664E",
|
||||||
},
|
},
|
||||||
methodContainer: {
|
|
||||||
marginTop: verticalScale(4),
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "flex-start",
|
|
||||||
gap: moderateScale(6),
|
|
||||||
},
|
|
||||||
subSectionLabel: {
|
|
||||||
fontSize: moderateScale(13),
|
|
||||||
fontWeight: "700",
|
|
||||||
color: "#597064",
|
|
||||||
},
|
|
||||||
methodText: {
|
|
||||||
flex: 1,
|
|
||||||
fontSize: moderateScale(13),
|
|
||||||
lineHeight: moderateScale(19),
|
|
||||||
color: "#334155",
|
|
||||||
},
|
|
||||||
explanationList: {
|
explanationList: {
|
||||||
gap: verticalScale(8),
|
gap: verticalScale(8),
|
||||||
},
|
},
|
||||||
|
|
@ -640,8 +621,7 @@ const accordionStyles = StyleSheet.create({
|
||||||
lineHeight: moderateScale(15),
|
lineHeight: moderateScale(15),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.5,
|
|
||||||
},
|
},
|
||||||
categoryBadge: {
|
categoryBadge: {
|
||||||
backgroundColor: "#EEF7F1",
|
backgroundColor: "#EEF7F1",
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.4,
|
|
||||||
},
|
},
|
||||||
pathway: {
|
pathway: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,6 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#536F61",
|
color: "#536F61",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,7 @@ const styles = StyleSheet.create({
|
||||||
fontSize: moderateScale(12),
|
fontSize: moderateScale(12),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.2,
|
||||||
letterSpacing: 1,
|
|
||||||
marginBottom: verticalScale(12),
|
marginBottom: verticalScale(12),
|
||||||
marginLeft: moderateScale(4),
|
marginLeft: moderateScale(4),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@ import React, { useMemo } from "react";
|
||||||
import { ScrollView, StyleSheet } from "react-native";
|
import { ScrollView, StyleSheet } from "react-native";
|
||||||
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { asString, humanizeKey } from "../helpers/value";
|
import {
|
||||||
|
asString,
|
||||||
|
buildDefinitionLabelMap,
|
||||||
|
humanizeKey,
|
||||||
|
resolveAttributeLabel,
|
||||||
|
} from "../helpers/value";
|
||||||
import {
|
import {
|
||||||
findAttributePresentationRule,
|
findAttributePresentationRule,
|
||||||
isEmptyValue,
|
isEmptyValue,
|
||||||
|
|
@ -41,9 +46,7 @@ export function SixStagesDetailRenderer({
|
||||||
const title = humanizeKey(rawTitle);
|
const title = humanizeKey(rawTitle);
|
||||||
|
|
||||||
const orderedSections = useMemo(() => {
|
const orderedSections = useMemo(() => {
|
||||||
const definitionByLabel = new Map(
|
const definitionByLabel = buildDefinitionLabelMap(definitions);
|
||||||
(definitions ?? []).map((d) => [d.code, d.label]),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Object.entries(data)
|
return Object.entries(data)
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -55,8 +58,7 @@ export function SixStagesDetailRenderer({
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
const rule = findAttributePresentationRule(key, presentationAttributes);
|
const rule = findAttributePresentationRule(key, presentationAttributes);
|
||||||
const order = presentationDisplayOrder(rule);
|
const order = presentationDisplayOrder(rule);
|
||||||
const rawLabel = definitionByLabel.get(key) || key;
|
const label = resolveAttributeLabel(key, definitionByLabel);
|
||||||
const label = humanizeKey(rawLabel);
|
|
||||||
return { key, value, order, label };
|
return { key, value, order, label };
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@ import React, { useMemo } from "react";
|
||||||
import { ScrollView, StyleSheet } from "react-native";
|
import { ScrollView, StyleSheet } from "react-native";
|
||||||
|
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
import { asString, humanizeKey } from "../helpers/value";
|
import {
|
||||||
|
asString,
|
||||||
|
buildDefinitionLabelMap,
|
||||||
|
humanizeKey,
|
||||||
|
resolveAttributeLabel,
|
||||||
|
} from "../helpers/value";
|
||||||
import {
|
import {
|
||||||
findAttributePresentationRule,
|
findAttributePresentationRule,
|
||||||
isEmptyValue,
|
isEmptyValue,
|
||||||
|
|
@ -36,9 +41,7 @@ export function TcmPatternDetailRenderer({
|
||||||
const title = humanizeKey(rawTitle);
|
const title = humanizeKey(rawTitle);
|
||||||
|
|
||||||
const orderedSections = useMemo(() => {
|
const orderedSections = useMemo(() => {
|
||||||
const definitionByLabel = new Map(
|
const definitionByLabel = buildDefinitionLabelMap(definitions);
|
||||||
(definitions ?? []).map((d) => [d.code, d.label]),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Object.entries(data)
|
return Object.entries(data)
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -49,8 +52,7 @@ export function TcmPatternDetailRenderer({
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
const rule = findAttributePresentationRule(key, presentationAttributes);
|
const rule = findAttributePresentationRule(key, presentationAttributes);
|
||||||
const order = presentationDisplayOrder(rule);
|
const order = presentationDisplayOrder(rule);
|
||||||
const rawLabel = definitionByLabel.get(key) || key;
|
const label = resolveAttributeLabel(key, definitionByLabel);
|
||||||
const label = humanizeKey(rawLabel);
|
|
||||||
return { key, value, order, label };
|
return { key, value, order, label };
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,482 @@
|
||||||
import React from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import { ScrollView } from "react-native";
|
import {
|
||||||
|
LayoutAnimation,
|
||||||
|
Platform,
|
||||||
|
Pressable,
|
||||||
|
ScrollView,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
UIManager,
|
||||||
|
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, Radius } from "@/theme";
|
||||||
|
import { useSettingsStore } from "@/store/settings.store";
|
||||||
import type { DetailRendererProps } from "../../types/renderer.types";
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
||||||
|
import { useModuleTemplateContentDetailsQuery } from "../../hooks/use-content-queries";
|
||||||
|
import {
|
||||||
|
buildContentReferenceRoute,
|
||||||
|
parseNavigableContentReference,
|
||||||
|
} from "../../utils/content-reference";
|
||||||
|
import {
|
||||||
|
asRecord,
|
||||||
|
asRecordArray,
|
||||||
|
asString,
|
||||||
|
asStringArray,
|
||||||
|
} from "../helpers/value";
|
||||||
|
import { BulletList } from "../shared/BulletList";
|
||||||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
import { asString } from "../helpers/value";
|
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { DescriptionList, Images, ObjectArrayCards, ObjectArrayTable, ObjectCard, PointCodes, Strings } from "./categoryParts";
|
import { OverviewCard } from "../shared/OverviewCard";
|
||||||
export function YuanSourceDetailRenderer({content,data,definitions,presentationAttributes}:DetailRendererProps){ return <ScrollView contentContainerStyle={{paddingHorizontal:18,paddingTop:16,paddingBottom:40,gap:14}}><Hero title={asString(data.title)||asString(data.name)||content.title}/><Images data={data}/><PointCodes data={data}/><ObjectArrayTable title="Source Points" value={data.source_point} columns={["meridian","point"]}/><Strings title="Key Clinical Features" value={data.key_clinical_feature}/><Strings title="Yin vs Yang" value={data.yin_vs_yang}/><Strings title="Functions" value={data.functions}/><Strings title="Diagnostic Utility" value={data.diagnostic_utility}/><ContentLinkAttributeSections data={data} definitions={definitions} presentationAttributes={presentationAttributes}/></ScrollView>; }
|
import { Images } from "./categoryParts";
|
||||||
|
|
||||||
|
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
|
||||||
|
UIManager.setLayoutAnimationEnabledExperimental(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PointItemProps {
|
||||||
|
key?: React.Key;
|
||||||
|
item: Record<string, unknown>;
|
||||||
|
defaultExpanded: boolean;
|
||||||
|
moduleCode: string;
|
||||||
|
pointsCatalogMap?: Map<string, { contentId: string; title: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sanitizeMeridianHeading(meridian: string, chineseName: string): string {
|
||||||
|
const cleanChinese = chineseName.replace(/^\((.*)\)$/, "$1").trim();
|
||||||
|
|
||||||
|
// Strip meridian abbreviation codes or point codes in parentheses,
|
||||||
|
// e.g. (ST), (LU-9), (LI), (LV), (LR), (PC), (GB), (HT), etc.
|
||||||
|
const cleanedMeridian = meridian
|
||||||
|
.replace(/\s*\(\s*[A-Z]{1,4}(?:[\s\-_]*\d+)?\s*\)\s*/g, " ")
|
||||||
|
.replace(/\s+/g, " ")
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
if (cleanedMeridian && cleanChinese) {
|
||||||
|
if (cleanedMeridian.toLowerCase().includes(cleanChinese.toLowerCase())) {
|
||||||
|
return cleanedMeridian;
|
||||||
|
}
|
||||||
|
return `${cleanedMeridian} (${cleanChinese})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleanedMeridian || cleanChinese || "Point";
|
||||||
|
}
|
||||||
|
|
||||||
|
function PointAccordionCard({
|
||||||
|
item,
|
||||||
|
defaultExpanded,
|
||||||
|
moduleCode,
|
||||||
|
pointsCatalogMap,
|
||||||
|
}: PointItemProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [expanded, setExpanded] = useState(defaultExpanded);
|
||||||
|
|
||||||
|
const meridian = asString(item.meridian).trim();
|
||||||
|
const chineseName = asString(item.chinese_name).trim();
|
||||||
|
const element = asString(item.element).trim();
|
||||||
|
const caution = asString(item.caution).trim();
|
||||||
|
const cautionList = asStringArray(item.caution);
|
||||||
|
|
||||||
|
const actions = asStringArray(item.actions);
|
||||||
|
const indications = asStringArray(item.indications);
|
||||||
|
|
||||||
|
// Format header title: e.g. "Stomach (Chongyang)", "Lung (Taiyuan)"
|
||||||
|
const title = useMemo(() => {
|
||||||
|
return sanitizeMeridianHeading(meridian, chineseName);
|
||||||
|
}, [meridian, chineseName]);
|
||||||
|
|
||||||
|
// Resolve point reference for linkable button
|
||||||
|
const rawPoint = asRecord(item.point);
|
||||||
|
const directRef = parseNavigableContentReference(item.point);
|
||||||
|
|
||||||
|
// Extract candidate point codes/labels: e.g. "LU 9", "LU-9"
|
||||||
|
const pointLabel =
|
||||||
|
directRef?.label?.trim() ||
|
||||||
|
asString(rawPoint.label).trim() ||
|
||||||
|
(rawPoint.target && typeof rawPoint.target === "object"
|
||||||
|
? asString((rawPoint.target as Record<string, unknown>).source_code).trim()
|
||||||
|
: "") ||
|
||||||
|
"";
|
||||||
|
|
||||||
|
// Construct button display label: e.g. "LU-9 (Taiyuan)" or "LU 9 (Taiyuan)"
|
||||||
|
const pointButtonLabel = useMemo(() => {
|
||||||
|
const baseCode = pointLabel || "Point Details";
|
||||||
|
if (chineseName && !baseCode.toLowerCase().includes(chineseName.toLowerCase())) {
|
||||||
|
return `${baseCode} (${chineseName})`;
|
||||||
|
}
|
||||||
|
return baseCode;
|
||||||
|
}, [pointLabel, chineseName]);
|
||||||
|
|
||||||
|
// Resolve navigation destination
|
||||||
|
const navigateToPoint = () => {
|
||||||
|
if (directRef) {
|
||||||
|
router.push(buildContentReferenceRoute(directRef) as never);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rawPoint.target && typeof rawPoint.target === "object") {
|
||||||
|
const target = rawPoint.target as Record<string, unknown>;
|
||||||
|
const targetModule = asString(target.module_code).trim() || moduleCode || "m0001";
|
||||||
|
const targetTemplate = asString(target.template_code).trim() || "m0001_ct0003";
|
||||||
|
const contentId = asString(target.content_id).trim();
|
||||||
|
const sourceCode = asString(target.source_code).trim();
|
||||||
|
|
||||||
|
if (contentId) {
|
||||||
|
router.push(
|
||||||
|
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(contentId)}` as never,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: match by catalog map (from m0001_ct0003) using sourceCode or label
|
||||||
|
if (pointsCatalogMap && sourceCode) {
|
||||||
|
const found =
|
||||||
|
pointsCatalogMap.get(sourceCode.toLowerCase()) ||
|
||||||
|
pointsCatalogMap.get(sourceCode.replace(/[- ]/g, "").toLowerCase());
|
||||||
|
if (found) {
|
||||||
|
router.push(
|
||||||
|
`/modules/${encodeURIComponent(targetModule)}/${encodeURIComponent(targetTemplate)}/${encodeURIComponent(found.contentId)}` as never,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Secondary fallback matching by pointLabel in catalog
|
||||||
|
if (pointsCatalogMap && pointLabel) {
|
||||||
|
const found =
|
||||||
|
pointsCatalogMap.get(pointLabel.toLowerCase()) ||
|
||||||
|
pointsCatalogMap.get(pointLabel.replace(/[- ]/g, "").toLowerCase());
|
||||||
|
if (found) {
|
||||||
|
router.push(
|
||||||
|
`/modules/${encodeURIComponent(moduleCode || "m0001")}/m0001_ct0003/${encodeURIComponent(found.contentId)}` as never,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggle = () => {
|
||||||
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
||||||
|
setExpanded((prev) => !prev);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.card}>
|
||||||
|
{/* Accordion Header */}
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityState={{ expanded }}
|
||||||
|
accessibilityLabel={`${expanded ? "Collapse" : "Expand"} ${title}`}
|
||||||
|
onPress={toggle}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.cardHeader,
|
||||||
|
expanded && styles.cardHeaderExpanded,
|
||||||
|
pressed && styles.pressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<View style={styles.headerLeft}>
|
||||||
|
<View style={styles.headerAccent} />
|
||||||
|
<Text style={styles.headerTitle} numberOfLines={2}>
|
||||||
|
{title}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.headerRight}>
|
||||||
|
{element ? (
|
||||||
|
<View style={styles.elementBadge}>
|
||||||
|
<Text style={styles.elementBadgeText}>{element}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
<View style={styles.chevron}>
|
||||||
|
<Ionicons
|
||||||
|
name={expanded ? "chevron-up" : "chevron-down"}
|
||||||
|
size={moderateScale(16)}
|
||||||
|
color={Colors.primary}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
{/* Accordion Body (Expanded State) */}
|
||||||
|
{expanded ? (
|
||||||
|
<View style={styles.cardBody}>
|
||||||
|
{/* Actions */}
|
||||||
|
{actions.length > 0 ? (
|
||||||
|
<View style={styles.sectionRow}>
|
||||||
|
<Text style={styles.sectionLabel}>ACTIONS</Text>
|
||||||
|
{actions.length === 1 ? (
|
||||||
|
<Text style={styles.sectionValue}>{actions[0]}</Text>
|
||||||
|
) : (
|
||||||
|
<BulletList items={actions} />
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Indications */}
|
||||||
|
{indications.length > 0 ? (
|
||||||
|
<View style={styles.sectionRow}>
|
||||||
|
<Text style={styles.sectionLabel}>INDICATIONS</Text>
|
||||||
|
<BulletList items={indications} />
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Caution (same UI as Actions and Indications) */}
|
||||||
|
{caution ? (
|
||||||
|
<View style={styles.sectionRow}>
|
||||||
|
<Text style={styles.sectionLabel}>CAUTION</Text>
|
||||||
|
{cautionList.length > 1 ? (
|
||||||
|
<BulletList items={cautionList} />
|
||||||
|
) : (
|
||||||
|
<Text style={styles.sectionValue}>{caution}</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Linkable Point Button (matching standard ReferenceChipList styling) */}
|
||||||
|
{pointLabel ? (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="link"
|
||||||
|
accessibilityLabel={`View point ${pointButtonLabel}`}
|
||||||
|
onPress={navigateToPoint}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.pointLinkButton,
|
||||||
|
pressed && styles.pressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Text style={styles.pointLinkLabel}>{pointButtonLabel}</Text>
|
||||||
|
<Ionicons
|
||||||
|
name="chevron-forward"
|
||||||
|
size={moderateScale(14)}
|
||||||
|
color={Colors.primaryDark}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function YuanSourceDetailRenderer({
|
||||||
|
moduleCode = "m0001",
|
||||||
|
content,
|
||||||
|
data,
|
||||||
|
definitions,
|
||||||
|
presentationAttributes,
|
||||||
|
}: DetailRendererProps) {
|
||||||
|
const accordionDefaultExpanded = useSettingsStore(
|
||||||
|
(state) => state.accordionDefaultExpanded,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fetch points from m0001_ct0003 for robust ID navigation fallback
|
||||||
|
const { data: pointsCatalog } = useModuleTemplateContentDetailsQuery({
|
||||||
|
module_code: moduleCode || "m0001",
|
||||||
|
template_code: "m0001_ct0003",
|
||||||
|
});
|
||||||
|
|
||||||
|
const pointsCatalogMap = useMemo(() => {
|
||||||
|
const map = new Map<string, { contentId: string; title: string }>();
|
||||||
|
if (pointsCatalog?.items) {
|
||||||
|
for (const item of pointsCatalog.items) {
|
||||||
|
const id = item.content.id;
|
||||||
|
const title = item.content.title;
|
||||||
|
const code = asString(item.data.code).trim().toLowerCase();
|
||||||
|
const name = asString(item.data.name).trim().toLowerCase();
|
||||||
|
if (code) {
|
||||||
|
map.set(code, { contentId: id, title });
|
||||||
|
map.set(code.replace(/[- ]/g, ""), { contentId: id, title });
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
map.set(name, { contentId: id, title });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [pointsCatalog]);
|
||||||
|
|
||||||
|
const rawTitle =
|
||||||
|
asString(data.title) || asString(data.name) || content.title || "Yuan Source";
|
||||||
|
const altNames = asStringArray(data.alt_name);
|
||||||
|
const descriptionParagraphs = asStringArray(data.description);
|
||||||
|
const points = asRecordArray(data.points);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
contentContainerStyle={styles.container}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
>
|
||||||
|
{/* Screen Title & Subtitle */}
|
||||||
|
<Hero
|
||||||
|
title={rawTitle}
|
||||||
|
subtitle={altNames.length > 0 ? altNames.join(" · ") : undefined}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Visual images (if any assigned) */}
|
||||||
|
<Images data={data} />
|
||||||
|
|
||||||
|
{/* Overview Section */}
|
||||||
|
{descriptionParagraphs.length > 0 ? (
|
||||||
|
<OverviewCard
|
||||||
|
title="Overview"
|
||||||
|
paragraphs={descriptionParagraphs}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Points Accordion List */}
|
||||||
|
{points.length > 0 ? (
|
||||||
|
<View style={styles.pointsList}>
|
||||||
|
{points.map((pointItem, index) => (
|
||||||
|
<PointAccordionCard
|
||||||
|
key={index}
|
||||||
|
item={pointItem}
|
||||||
|
defaultExpanded={accordionDefaultExpanded}
|
||||||
|
moduleCode={moduleCode}
|
||||||
|
pointsCatalogMap={pointsCatalogMap}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Generic content link attributes (excluding points already rendered above) */}
|
||||||
|
<ContentLinkAttributeSections
|
||||||
|
data={data}
|
||||||
|
definitions={definitions}
|
||||||
|
presentationAttributes={presentationAttributes}
|
||||||
|
excludeAttributeKeys={["points", "m0001_ct0009.points"]}
|
||||||
|
/>
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
paddingHorizontal: moderateScale(16),
|
||||||
|
paddingTop: verticalScale(14),
|
||||||
|
paddingBottom: verticalScale(40),
|
||||||
|
gap: verticalScale(14),
|
||||||
|
},
|
||||||
|
pointsList: {
|
||||||
|
gap: verticalScale(12),
|
||||||
|
},
|
||||||
|
card: {
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
borderRadius: moderateScale(16),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2E8F0",
|
||||||
|
overflow: "hidden",
|
||||||
|
},
|
||||||
|
cardHeader: {
|
||||||
|
minHeight: verticalScale(54),
|
||||||
|
paddingHorizontal: moderateScale(14),
|
||||||
|
paddingVertical: verticalScale(12),
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
gap: moderateScale(10),
|
||||||
|
},
|
||||||
|
cardHeaderExpanded: {
|
||||||
|
backgroundColor: "#F0F7F3",
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: "#E2E8F0",
|
||||||
|
},
|
||||||
|
pressed: {
|
||||||
|
opacity: 0.75,
|
||||||
|
},
|
||||||
|
headerLeft: {
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: moderateScale(10),
|
||||||
|
},
|
||||||
|
headerAccent: {
|
||||||
|
width: moderateScale(4),
|
||||||
|
height: verticalScale(22),
|
||||||
|
borderRadius: moderateScale(2),
|
||||||
|
backgroundColor: Colors.primary,
|
||||||
|
},
|
||||||
|
headerTitle: {
|
||||||
|
flex: 1,
|
||||||
|
fontSize: moderateScale(15),
|
||||||
|
lineHeight: moderateScale(21),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#1E293B",
|
||||||
|
},
|
||||||
|
headerRight: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: moderateScale(8),
|
||||||
|
},
|
||||||
|
elementBadge: {
|
||||||
|
paddingHorizontal: moderateScale(9),
|
||||||
|
paddingVertical: verticalScale(3),
|
||||||
|
borderRadius: moderateScale(10),
|
||||||
|
backgroundColor: "#E8F5E9",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#C6E4CE",
|
||||||
|
},
|
||||||
|
elementBadgeText: {
|
||||||
|
fontSize: 11,
|
||||||
|
lineHeight: 16,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: "#285A44",
|
||||||
|
},
|
||||||
|
chevron: {
|
||||||
|
width: moderateScale(28),
|
||||||
|
height: moderateScale(28),
|
||||||
|
borderRadius: moderateScale(14),
|
||||||
|
backgroundColor: "#FFFFFFB8",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2E8F0",
|
||||||
|
},
|
||||||
|
cardBody: {
|
||||||
|
paddingHorizontal: moderateScale(16),
|
||||||
|
paddingTop: verticalScale(14),
|
||||||
|
paddingBottom: verticalScale(16),
|
||||||
|
gap: verticalScale(12),
|
||||||
|
backgroundColor: "#FFFFFF",
|
||||||
|
},
|
||||||
|
sectionRow: {
|
||||||
|
gap: verticalScale(6),
|
||||||
|
paddingBottom: verticalScale(10),
|
||||||
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
|
borderBottomColor: "#E8ECEF",
|
||||||
|
},
|
||||||
|
sectionLabel: {
|
||||||
|
fontSize: 12,
|
||||||
|
lineHeight: 17,
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#597064",
|
||||||
|
letterSpacing: 0.15,
|
||||||
|
},
|
||||||
|
sectionValue: {
|
||||||
|
fontSize: 16,
|
||||||
|
lineHeight: 25,
|
||||||
|
color: "#334155",
|
||||||
|
},
|
||||||
|
pointLinkButton: {
|
||||||
|
alignSelf: "flex-start",
|
||||||
|
minHeight: verticalScale(34),
|
||||||
|
paddingHorizontal: moderateScale(12),
|
||||||
|
paddingVertical: verticalScale(6),
|
||||||
|
borderRadius: Radius.full,
|
||||||
|
backgroundColor: "#E8F5E9",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#CDE5D0",
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: moderateScale(6),
|
||||||
|
marginTop: verticalScale(6),
|
||||||
|
},
|
||||||
|
pointLinkLabel: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
lineHeight: moderateScale(18),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.primaryDark,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import { ObjectSections } from "../shared/ObjectSections";
|
||||||
import { RecordCards } from "../shared/RecordCards";
|
import { RecordCards } from "../shared/RecordCards";
|
||||||
import { RecordTable } from "../shared/RecordTable";
|
import { RecordTable } from "../shared/RecordTable";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
|
import { useRelationalContentMedia } from "../../media/ContentMediaContext";
|
||||||
|
import { ContentMediaGallery } from "../../media/ContentMediaGallery";
|
||||||
|
|
||||||
export const PointCodes = ({ data }: { data: Record<string, unknown> }) => (
|
export const PointCodes = ({ data }: { data: Record<string, unknown> }) => (
|
||||||
<SectionCard title="Points"><ChipList items={asStringArray(data.point_codes)} /></SectionCard>
|
<SectionCard title="Points"><ChipList items={asStringArray(data.point_codes)} /></SectionCard>
|
||||||
|
|
@ -23,9 +25,36 @@ export const DescriptionList = ({ data }: { data: Record<string, unknown> }) =>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Images = ({ data }: { data: Record<string, unknown> }) => (
|
const extractCategoryImages = (data: Record<string, unknown>): Record<string, unknown>[] => {
|
||||||
<ImageGallery images={asRecordArray(data.images)} />
|
const images = asRecordArray(data.images);
|
||||||
);
|
if (images.length > 0) return images;
|
||||||
|
|
||||||
|
const single = asRecord(data.default_image || data.image);
|
||||||
|
if (Object.keys(single).length > 0) {
|
||||||
|
return [single];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Images = ({ data }: { data: Record<string, unknown> }) => {
|
||||||
|
const directImages = extractCategoryImages(data);
|
||||||
|
const relationalMedia = useRelationalContentMedia();
|
||||||
|
|
||||||
|
// If direct images are explicitly defined in category data attributes, display them
|
||||||
|
if (directImages.length > 0) {
|
||||||
|
return <ImageGallery images={directImages} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If direct media was assigned directly to this category (e.g. primary image in CMS)
|
||||||
|
const directMedia = relationalMedia.filter((m) => m.media_role === "primary");
|
||||||
|
if (directMedia.length > 0) {
|
||||||
|
return <ContentMediaGallery media={directMedia} title="Visual Reference" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not show inherited media from referenced points/meridians for categories without direct images
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
export const ObjectCard = ({ title, value }: { title: string; value: unknown }) => {
|
export const ObjectCard = ({ title, value }: { title: string; value: unknown }) => {
|
||||||
const obj = asRecord(value);
|
const obj = asRecord(value);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import type { AttributeDefinitionResponse } from "../../types/content.types";
|
||||||
|
|
||||||
export function asString(value: unknown): string {
|
export function asString(value: unknown): string {
|
||||||
if (typeof value === "string") return value;
|
if (typeof value === "string") return value;
|
||||||
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
||||||
|
|
@ -54,3 +56,53 @@ export function formatPatternTitle(value: string): string {
|
||||||
return value.replace(/\bLung(?:es|s)['’]/gi, "Lung's");
|
return value.replace(/\bLung(?:es|s)['’]/gi, "Lung's");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indexes template attribute definitions (and nested children) by code so
|
||||||
|
* renderers can display exact template labels and casing without hardcoding.
|
||||||
|
*/
|
||||||
|
export function buildDefinitionLabelMap(
|
||||||
|
attributes?: readonly AttributeDefinitionResponse[] | null,
|
||||||
|
): Map<string, string> {
|
||||||
|
const map = new Map<string, string>();
|
||||||
|
if (!attributes) return map;
|
||||||
|
|
||||||
|
const visit = (attrs: readonly AttributeDefinitionResponse[], prefix?: string) => {
|
||||||
|
for (const attr of attrs) {
|
||||||
|
const code = attr.code?.trim();
|
||||||
|
const label = attr.label?.trim();
|
||||||
|
if (code && label) {
|
||||||
|
map.set(code, label);
|
||||||
|
map.set(code.toLowerCase(), label);
|
||||||
|
if (prefix) {
|
||||||
|
map.set(`${prefix}.${code}`, label);
|
||||||
|
map.set(`${prefix}.${code}`.toLowerCase(), label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Array.isArray(attr.children) && attr.children.length > 0) {
|
||||||
|
visit(attr.children, code || prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
visit(attributes);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the exact template label when defined, falling back to a provided label or humanized key.
|
||||||
|
*/
|
||||||
|
export function resolveAttributeLabel(
|
||||||
|
code: string,
|
||||||
|
labelMap?: ReadonlyMap<string, string>,
|
||||||
|
fallback?: string,
|
||||||
|
): string {
|
||||||
|
const trimmed = code.trim();
|
||||||
|
const fromMap =
|
||||||
|
labelMap?.get(trimmed) || labelMap?.get(trimmed.toLowerCase());
|
||||||
|
if (fromMap && fromMap.trim().length > 0) {
|
||||||
|
return fromMap.trim();
|
||||||
|
}
|
||||||
|
return fallback ?? humanizeKey(trimmed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { Colors } from "@/theme";
|
||||||
import type { CollectionRendererProps } from "../../types/renderer.types";
|
import type { CollectionRendererProps } from "../../types/renderer.types";
|
||||||
|
|
||||||
export function CollectionScaffold(
|
export function CollectionScaffold(
|
||||||
props: CollectionRendererProps & { header?: React.ReactNode },
|
props: CollectionRendererProps & { header?: React.ReactNode; countLabel?: string },
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
|
|
@ -30,7 +30,7 @@ export function CollectionScaffold(
|
||||||
<>
|
<>
|
||||||
{props.header}
|
{props.header}
|
||||||
<Text style={styles.resultCount} accessibilityLiveRegion="polite">
|
<Text style={styles.resultCount} accessibilityLiveRegion="polite">
|
||||||
{props.total} {props.total === 1 ? "result" : "results"}
|
{props.countLabel ?? `${props.total} ${props.total === 1 ? "result" : "results"}`}
|
||||||
</Text>
|
</Text>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
@ -86,8 +86,7 @@ const styles = StyleSheet.create({
|
||||||
fontSize: moderateScale(12),
|
fontSize: moderateScale(12),
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.2,
|
||||||
letterSpacing: 1,
|
|
||||||
marginBottom: verticalScale(8),
|
marginBottom: verticalScale(8),
|
||||||
marginLeft: moderateScale(4),
|
marginLeft: moderateScale(4),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,6 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,26 @@ import { asString } from "../helpers/value";
|
||||||
|
|
||||||
import type { ContentMediaItem } from "../../types/media.types";
|
import type { ContentMediaItem } from "../../types/media.types";
|
||||||
|
|
||||||
|
const getImagePath = (item: Record<string, unknown>): string => {
|
||||||
|
return asString(
|
||||||
|
item.image_path || item.url || item.image_url || item.uri || item.path
|
||||||
|
).trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getImageName = (item: Record<string, unknown>): string => {
|
||||||
|
return asString(item.image_name || item.name || item.title || item.caption).trim();
|
||||||
|
};
|
||||||
|
|
||||||
export function ImageGallery({ images }: { images: Record<string, unknown>[] }) {
|
export function ImageGallery({ images }: { images: Record<string, unknown>[] }) {
|
||||||
const relationalMedia = useRelationalContentMedia();
|
const relationalMedia = useRelationalContentMedia();
|
||||||
|
|
||||||
if (relationalMedia.length > 0) {
|
const visible = images.filter((item) => getImagePath(item).length > 0);
|
||||||
return <ContentMediaGallery media={relationalMedia} title="Visual Reference" />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const visible = images.filter((item) => asString(item.image_path).trim().length > 0);
|
|
||||||
if (!visible.length) return null;
|
|
||||||
|
|
||||||
|
// Explicit direct images passed via props take priority over relational media
|
||||||
|
if (visible.length > 0) {
|
||||||
const fallbackMedia: ContentMediaItem[] = visible.map((item, index) => {
|
const fallbackMedia: ContentMediaItem[] = visible.map((item, index) => {
|
||||||
const path = asString(item.image_path).trim();
|
const path = getImagePath(item);
|
||||||
const name = asString(item.image_name).trim();
|
const name = getImageName(item);
|
||||||
return {
|
return {
|
||||||
id: `${path}-${index}`,
|
id: `${path}-${index}`,
|
||||||
media_asset_id: `${path}-${index}`,
|
media_asset_id: `${path}-${index}`,
|
||||||
|
|
@ -40,6 +47,14 @@ export function ImageGallery({ images }: { images: Record<string, unknown>[] })
|
||||||
return <ContentMediaGallery media={fallbackMedia} title="Visual Reference" />;
|
return <ContentMediaGallery media={fallbackMedia} title="Visual Reference" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback to relational content media when no direct images are provided
|
||||||
|
if (relationalMedia.length > 0) {
|
||||||
|
return <ContentMediaGallery media={relationalMedia} title="Visual Reference" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
root: { gap: 14 },
|
root: { gap: 14 },
|
||||||
item: { gap: 7 },
|
item: { gap: 7 },
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#597064",
|
color: "#597064",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.4,
|
|
||||||
},
|
},
|
||||||
value: { fontSize: 16, lineHeight: 25, color: "#334155" },
|
value: { fontSize: 16, lineHeight: 25, color: "#334155" },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ const styles = StyleSheet.create({
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
color: "#536F61",
|
color: "#536F61",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,7 @@ const styles = StyleSheet.create({
|
||||||
lineHeight: 17,
|
lineHeight: 17,
|
||||||
fontWeight: "700",
|
fontWeight: "700",
|
||||||
color: "#617468",
|
color: "#617468",
|
||||||
textTransform: "uppercase",
|
letterSpacing: 0.15,
|
||||||
letterSpacing: 0.35,
|
|
||||||
},
|
},
|
||||||
value: { fontSize: 15, lineHeight: 23, color: "#334155" },
|
value: { fontSize: 15, lineHeight: 23, color: "#334155" },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ export interface ModuleResponse extends ModuleSummary {
|
||||||
release_version: string | null;
|
release_version: string | null;
|
||||||
expected_release_date: string | null;
|
expected_release_date: string | null;
|
||||||
release_notes: string | null;
|
release_notes: string | null;
|
||||||
|
plan_code?: string | null;
|
||||||
metadata: Record<string, unknown>;
|
metadata: Record<string, unknown>;
|
||||||
created_by: string | null;
|
created_by: string | null;
|
||||||
updated_by: string | null;
|
updated_by: string | null;
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ const MODULE_VISUALS: Record<string, ModuleVisualConfig> = {
|
||||||
icon: "body-outline",
|
icon: "body-outline",
|
||||||
color: "#8B5CF6",
|
color: "#8B5CF6",
|
||||||
isDefaultFree: false,
|
isDefaultFree: false,
|
||||||
planCode: "LIFETIME_ALL",
|
planCode: "THERAPEUTICS_EAR",
|
||||||
},
|
},
|
||||||
m0042: {
|
m0042: {
|
||||||
icon: "woman-outline",
|
icon: "woman-outline",
|
||||||
|
|
@ -224,6 +224,7 @@ export function toModuleIndexItem(module: ModuleResponse): ModuleIndexItem {
|
||||||
const visual = MODULE_VISUALS[module.code.toLowerCase()];
|
const visual = MODULE_VISUALS[module.code.toLowerCase()];
|
||||||
const metadataIcon = readMetadataString(module, "icon");
|
const metadataIcon = readMetadataString(module, "icon");
|
||||||
const metadataColor = readMetadataString(module, "color");
|
const metadataColor = readMetadataString(module, "color");
|
||||||
|
const apiPlanCode = asNonBlankString(module.plan_code);
|
||||||
const metadataPlanCode = readMetadataString(module, "plan_code");
|
const metadataPlanCode = readMetadataString(module, "plan_code");
|
||||||
const metadataIsDefaultFree = readMetadataBoolean(module, "is_default_free");
|
const metadataIsDefaultFree = readMetadataBoolean(module, "is_default_free");
|
||||||
|
|
||||||
|
|
@ -241,7 +242,7 @@ export function toModuleIndexItem(module: ModuleResponse): ModuleIndexItem {
|
||||||
icon: metadataIcon ?? visual?.icon ?? "folder-outline",
|
icon: metadataIcon ?? visual?.icon ?? "folder-outline",
|
||||||
color: metadataColor ?? visual?.color ?? "#4F46E5",
|
color: metadataColor ?? visual?.color ?? "#4F46E5",
|
||||||
isDefaultFree: metadataIsDefaultFree ?? visual?.isDefaultFree ?? false,
|
isDefaultFree: metadataIsDefaultFree ?? visual?.isDefaultFree ?? false,
|
||||||
planCode: metadataPlanCode ?? visual?.planCode ?? "",
|
planCode: apiPlanCode ?? metadataPlanCode ?? visual?.planCode ?? "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
Modal,
|
Modal,
|
||||||
Pressable,
|
Pressable,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
|
TextInput,
|
||||||
View,
|
View,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
|
@ -20,8 +21,8 @@ import FieldLabel from "@/components/forms/FieldLabel";
|
||||||
import PrimaryButton from "@/components/buttons/PrimaryButton";
|
import PrimaryButton from "@/components/buttons/PrimaryButton";
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
import {
|
import {
|
||||||
|
SORTED_COUNTRY_CODES,
|
||||||
getCountryRuleByName,
|
getCountryRuleByName,
|
||||||
updatePhoneDialCode,
|
|
||||||
validatePhoneNumber,
|
validatePhoneNumber,
|
||||||
isValidPhoneNumber,
|
isValidPhoneNumber,
|
||||||
parsePhoneNumber,
|
parsePhoneNumber,
|
||||||
|
|
@ -38,25 +39,6 @@ interface EditProfileFormProps {
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const COMMON_COUNTRIES = [
|
|
||||||
"Australia",
|
|
||||||
"Canada",
|
|
||||||
"France",
|
|
||||||
"Germany",
|
|
||||||
"India",
|
|
||||||
"Ireland",
|
|
||||||
"Malaysia",
|
|
||||||
"Netherlands",
|
|
||||||
"New Zealand",
|
|
||||||
"Singapore",
|
|
||||||
"South Africa",
|
|
||||||
"Spain",
|
|
||||||
"Switzerland",
|
|
||||||
"United Arab Emirates",
|
|
||||||
"United Kingdom",
|
|
||||||
"United States",
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function EditProfileForm({
|
export default function EditProfileForm({
|
||||||
initialName = "User Name",
|
initialName = "User Name",
|
||||||
initialEmail = "user@example.com",
|
initialEmail = "user@example.com",
|
||||||
|
|
@ -71,9 +53,21 @@ export default function EditProfileForm({
|
||||||
const [nameError, setNameError] = useState("");
|
const [nameError, setNameError] = useState("");
|
||||||
const [phoneError, setPhoneError] = useState("");
|
const [phoneError, setPhoneError] = useState("");
|
||||||
const [showCountryModal, setShowCountryModal] = useState(false);
|
const [showCountryModal, setShowCountryModal] = useState(false);
|
||||||
|
const [countrySearch, setCountrySearch] = useState("");
|
||||||
|
|
||||||
const activeRule = getCountryRuleByName(country);
|
const activeRule = getCountryRuleByName(country);
|
||||||
|
|
||||||
|
const filteredCountries = useMemo(() => {
|
||||||
|
const q = countrySearch.trim().toLowerCase();
|
||||||
|
if (!q) return SORTED_COUNTRY_CODES;
|
||||||
|
return SORTED_COUNTRY_CODES.filter(
|
||||||
|
(c) =>
|
||||||
|
c.country.toLowerCase().includes(q) ||
|
||||||
|
c.code.toLowerCase().includes(q) ||
|
||||||
|
c.label.toLowerCase().includes(q)
|
||||||
|
);
|
||||||
|
}, [countrySearch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFullName(initialName);
|
setFullName(initialName);
|
||||||
}, [initialName]);
|
}, [initialName]);
|
||||||
|
|
@ -105,12 +99,12 @@ export default function EditProfileForm({
|
||||||
|
|
||||||
const handleCountrySelect = (newCountry: string) => {
|
const handleCountrySelect = (newCountry: string) => {
|
||||||
if (newCountry !== country) {
|
if (newCountry !== country) {
|
||||||
const updatedPhone = updatePhoneDialCode(phone, country, newCountry);
|
setPhone("");
|
||||||
setPhone(updatedPhone);
|
|
||||||
setCountry(newCountry);
|
setCountry(newCountry);
|
||||||
if (phoneError) setPhoneError("");
|
if (phoneError) setPhoneError("");
|
||||||
}
|
}
|
||||||
setShowCountryModal(false);
|
setShowCountryModal(false);
|
||||||
|
setCountrySearch("");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
|
@ -220,18 +214,27 @@ export default function EditProfileForm({
|
||||||
visible={showCountryModal}
|
visible={showCountryModal}
|
||||||
transparent
|
transparent
|
||||||
animationType="slide"
|
animationType="slide"
|
||||||
onRequestClose={() => setShowCountryModal(false)}
|
onRequestClose={() => {
|
||||||
|
setShowCountryModal(false);
|
||||||
|
setCountrySearch("");
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Pressable
|
<Pressable
|
||||||
style={styles.modalOverlay}
|
style={styles.modalOverlay}
|
||||||
onPress={() => setShowCountryModal(false)}
|
onPress={() => {
|
||||||
|
setShowCountryModal(false);
|
||||||
|
setCountrySearch("");
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<View style={styles.modalSheet}>
|
<Pressable style={styles.modalSheet} onPress={() => {}}>
|
||||||
<View style={styles.modalHeader}>
|
<View style={styles.modalHeader}>
|
||||||
<Text style={styles.modalTitle}>Select Country</Text>
|
<Text style={styles.modalTitle}>Select Country</Text>
|
||||||
<Pressable
|
<Pressable
|
||||||
hitSlop={8}
|
hitSlop={8}
|
||||||
onPress={() => setShowCountryModal(false)}
|
onPress={() => {
|
||||||
|
setShowCountryModal(false);
|
||||||
|
setCountrySearch("");
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="close"
|
name="close"
|
||||||
|
|
@ -241,30 +244,69 @@ export default function EditProfileForm({
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{/* Country Search Bar */}
|
||||||
|
<View style={styles.modalSearchContainer}>
|
||||||
|
<Ionicons
|
||||||
|
name="search-outline"
|
||||||
|
size={moderateScale(17)}
|
||||||
|
color={Colors.textSecondary}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
value={countrySearch}
|
||||||
|
onChangeText={setCountrySearch}
|
||||||
|
placeholder="Search country or code..."
|
||||||
|
placeholderTextColor={Colors.textSecondary}
|
||||||
|
style={styles.modalSearchInput}
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
|
/>
|
||||||
|
{countrySearch.length > 0 && (
|
||||||
|
<Pressable
|
||||||
|
hitSlop={8}
|
||||||
|
onPress={() => setCountrySearch("")}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name="close-circle"
|
||||||
|
size={moderateScale(17)}
|
||||||
|
color={Colors.textSecondary}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
contentContainerStyle={styles.countryList}
|
contentContainerStyle={styles.countryList}
|
||||||
|
keyboardShouldPersistTaps="handled"
|
||||||
>
|
>
|
||||||
{COMMON_COUNTRIES.map((c) => {
|
{filteredCountries.length === 0 ? (
|
||||||
const isSelected = country === c;
|
<View style={styles.emptyContainer}>
|
||||||
|
<Text style={styles.emptyText}>No countries found</Text>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
filteredCountries.map((c) => {
|
||||||
|
const isSelected = country === c.country;
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={c}
|
key={c.iso2 + c.country}
|
||||||
style={({ pressed }) => [
|
style={({ pressed }) => [
|
||||||
styles.countryItem,
|
styles.countryItem,
|
||||||
isSelected && styles.countryItemSelected,
|
isSelected && styles.countryItemSelected,
|
||||||
pressed && styles.countryItemPressed,
|
pressed && styles.countryItemPressed,
|
||||||
]}
|
]}
|
||||||
onPress={() => handleCountrySelect(c)}
|
onPress={() => handleCountrySelect(c.country)}
|
||||||
>
|
>
|
||||||
|
<View style={styles.countryRow}>
|
||||||
|
<Text style={styles.countryDialCode}>{c.code}</Text>
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
styles.countryName,
|
styles.countryName,
|
||||||
isSelected && styles.countryNameSelected,
|
isSelected && styles.countryNameSelected,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{c}
|
{c.country}
|
||||||
</Text>
|
</Text>
|
||||||
|
</View>
|
||||||
{isSelected && (
|
{isSelected && (
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="checkmark"
|
name="checkmark"
|
||||||
|
|
@ -274,9 +316,10 @@ export default function EditProfileForm({
|
||||||
)}
|
)}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
);
|
);
|
||||||
})}
|
})
|
||||||
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
</Pressable>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</Modal>
|
</Modal>
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -334,6 +377,52 @@ const styles = StyleSheet.create({
|
||||||
color: Colors.textPrimary,
|
color: Colors.textPrimary,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
modalSearchContainer: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginHorizontal: scale(16),
|
||||||
|
marginTop: verticalScale(10),
|
||||||
|
marginBottom: verticalScale(4),
|
||||||
|
paddingHorizontal: scale(12),
|
||||||
|
paddingVertical: verticalScale(8),
|
||||||
|
backgroundColor: "#F8FAFC",
|
||||||
|
borderRadius: moderateScale(10),
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#E2E8F0",
|
||||||
|
gap: scale(8),
|
||||||
|
},
|
||||||
|
|
||||||
|
modalSearchInput: {
|
||||||
|
flex: 1,
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
color: Colors.textPrimary,
|
||||||
|
padding: 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
emptyContainer: {
|
||||||
|
paddingVertical: verticalScale(24),
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
|
||||||
|
emptyText: {
|
||||||
|
fontSize: moderateScale(14),
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
},
|
||||||
|
|
||||||
|
countryRow: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: scale(10),
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
|
||||||
|
countryDialCode: {
|
||||||
|
fontSize: moderateScale(13),
|
||||||
|
fontWeight: "700",
|
||||||
|
color: Colors.textSecondary,
|
||||||
|
minWidth: scale(46),
|
||||||
|
},
|
||||||
|
|
||||||
countryList: {
|
countryList: {
|
||||||
paddingHorizontal: scale(16),
|
paddingHorizontal: scale(16),
|
||||||
paddingTop: verticalScale(8),
|
paddingTop: verticalScale(8),
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,9 @@ export default function HomeScreen() {
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
|
void modulesQuery.refetch().catch((error) => console.warn("Unable to refresh modules:", error));
|
||||||
void refreshSession().catch((error) => console.warn("Unable to refresh session:", error));
|
void refreshSession().catch((error) => console.warn("Unable to refresh session:", error));
|
||||||
}, [refreshSession]),
|
}, [modulesQuery.refetch, refreshSession]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const unlockedModules = useMemo(() => {
|
const unlockedModules = useMemo(() => {
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,15 @@ export default function ModulesIndexScreen() {
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
isNavigatingRef.current = false;
|
isNavigatingRef.current = false;
|
||||||
|
void modulesQuery.refetch().catch((error) => {
|
||||||
|
console.warn("Unable to refresh modules:", error);
|
||||||
|
});
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
void refreshAccess().catch((error) => {
|
void refreshAccess().catch((error) => {
|
||||||
console.warn("Unable to refresh module access:", error);
|
console.warn("Unable to refresh module access:", error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [accessToken, refreshAccess]),
|
}, [accessToken, modulesQuery.refetch, refreshAccess]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Alert,
|
|
||||||
Platform,
|
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
View,
|
View,
|
||||||
|
|
@ -21,42 +19,23 @@ import ProfileHeader from "@/features/profile/components/ProfileHeader";
|
||||||
import ProfileAvatar from "@/features/profile/components/ProfileAvatar";
|
import ProfileAvatar from "@/features/profile/components/ProfileAvatar";
|
||||||
import ProfileOverviewCard from "@/features/profile/components/ProfileOverviewCard";
|
import ProfileOverviewCard from "@/features/profile/components/ProfileOverviewCard";
|
||||||
import LogoutButton from "@/features/settings/components/LogoutButton";
|
import LogoutButton from "@/features/settings/components/LogoutButton";
|
||||||
|
import LogoutConfirmModal from "@/components/LogoutConfirmModal";
|
||||||
import { useAuthStore } from "@/store/auth.store";
|
import { useAuthStore } from "@/store/auth.store";
|
||||||
|
|
||||||
export default function ProfileOverviewScreen() {
|
export default function ProfileOverviewScreen() {
|
||||||
const { user, accessToken, logout } = useAuthStore();
|
const { user, accessToken, logout } = useAuthStore();
|
||||||
|
const [logoutModalVisible, setLogoutModalVisible] = useState(false);
|
||||||
const displayName = user?.name || "User Name";
|
const displayName = user?.name || "User Name";
|
||||||
const displayEmail = user?.email || "user@example.com";
|
const displayEmail = user?.email || "user@example.com";
|
||||||
|
|
||||||
const handleLogout = () => {
|
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
|
setLogoutModalVisible(false);
|
||||||
logout();
|
logout();
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Platform.OS === "web") {
|
const handleLogout = () => {
|
||||||
const confirmed =
|
setLogoutModalVisible(true);
|
||||||
typeof window !== "undefined"
|
|
||||||
? window.confirm("Are you sure you want to log out?")
|
|
||||||
: true;
|
|
||||||
if (confirmed) {
|
|
||||||
doLogout();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Alert.alert(
|
|
||||||
"Log Out",
|
|
||||||
"Are you sure you want to log out of Acupedia?",
|
|
||||||
[
|
|
||||||
{ text: "Cancel", style: "cancel" },
|
|
||||||
{
|
|
||||||
text: "Log Out",
|
|
||||||
style: "destructive",
|
|
||||||
onPress: doLogout,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{ cancelable: true }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
|
|
@ -125,6 +104,12 @@ export default function ProfileOverviewScreen() {
|
||||||
<LogoutButton onPress={handleLogout} />
|
<LogoutButton onPress={handleLogout} />
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
<LogoutConfirmModal
|
||||||
|
visible={logoutModalVisible}
|
||||||
|
onCancel={() => setLogoutModalVisible(false)}
|
||||||
|
onConfirm={doLogout}
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Alert,
|
|
||||||
Platform,
|
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
View,
|
View,
|
||||||
|
|
@ -14,6 +12,7 @@ import { Colors } from "@/theme";
|
||||||
import SettingsHeader from "@/features/settings/components/SettingsHeader";
|
import SettingsHeader from "@/features/settings/components/SettingsHeader";
|
||||||
import SettingsSection from "@/features/settings/components/SettingsSection";
|
import SettingsSection from "@/features/settings/components/SettingsSection";
|
||||||
import LogoutButton from "@/features/settings/components/LogoutButton";
|
import LogoutButton from "@/features/settings/components/LogoutButton";
|
||||||
|
import LogoutConfirmModal from "@/components/LogoutConfirmModal";
|
||||||
import {
|
import {
|
||||||
ACCOUNT_SETTINGS,
|
ACCOUNT_SETTINGS,
|
||||||
PREFERENCE_SETTINGS,
|
PREFERENCE_SETTINGS,
|
||||||
|
|
@ -28,6 +27,7 @@ import EnvironmentSelectorModal from "@/components/EnvironmentSelectorModal";
|
||||||
|
|
||||||
export default function SettingsScreen() {
|
export default function SettingsScreen() {
|
||||||
const [envModalVisible, setEnvModalVisible] = useState(false);
|
const [envModalVisible, setEnvModalVisible] = useState(false);
|
||||||
|
const [logoutModalVisible, setLogoutModalVisible] = useState(false);
|
||||||
const activeConfig = useEnvironmentStore((state) => state.getActiveConfig());
|
const activeConfig = useEnvironmentStore((state) => state.getActiveConfig());
|
||||||
const user = useAuthStore((state) => state.user);
|
const user = useAuthStore((state) => state.user);
|
||||||
const logout = useAuthStore((state) => state.logout);
|
const logout = useAuthStore((state) => state.logout);
|
||||||
|
|
@ -87,35 +87,14 @@ export default function SettingsScreen() {
|
||||||
: []),
|
: []),
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleLogout = () => {
|
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
|
setLogoutModalVisible(false);
|
||||||
logout();
|
logout();
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Platform.OS === "web") {
|
const handleLogout = () => {
|
||||||
const confirmed =
|
setLogoutModalVisible(true);
|
||||||
typeof window !== "undefined"
|
|
||||||
? window.confirm("Are you sure you want to log out?")
|
|
||||||
: true;
|
|
||||||
if (confirmed) {
|
|
||||||
doLogout();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Alert.alert(
|
|
||||||
"Log Out",
|
|
||||||
"Are you sure you want to log out of Acupedia?",
|
|
||||||
[
|
|
||||||
{ text: "Cancel", style: "cancel" },
|
|
||||||
{
|
|
||||||
text: "Log Out",
|
|
||||||
style: "destructive",
|
|
||||||
onPress: doLogout,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{ cancelable: true }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -153,6 +132,12 @@ export default function SettingsScreen() {
|
||||||
onClose={() => setEnvModalVisible(false)}
|
onClose={() => setEnvModalVisible(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<LogoutConfirmModal
|
||||||
|
visible={logoutModalVisible}
|
||||||
|
onCancel={() => setLogoutModalVisible(false)}
|
||||||
|
onConfirm={doLogout}
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue