gynec-changes #104

Merged
amit merged 2 commits from gynec-changes into main 2026-11-02 10:54:02 +00:00
2 changed files with 22 additions and 75 deletions

View File

@ -47,41 +47,9 @@ function normalizePointCode(raw: string): string {
return code;
}
function renderExplanationParts(
text: string,
onPointPress: (code: string) => void,
) {
const pointRegex = /\b([A-Za-z]{1,4}-\d{1,2})\b/g;
const parts: React.ReactNode[] = [];
let lastIndex = 0;
let match: RegExpExecArray | null;
while ((match = pointRegex.exec(text)) !== null) {
if (match.index > lastIndex) {
parts.push(text.substring(lastIndex, match.index));
}
const ptCode = match[1];
parts.push(
<Text
key={`pt-${match.index}`}
accessibilityRole="button"
onPress={() => onPointPress(ptCode)}
style={accordionStyles.pointTextLink}
>
{ptCode}
</Text>
);
lastIndex = match.index + match[0].length;
}
if (lastIndex < text.length) {
parts.push(text.substring(lastIndex));
}
return parts.length > 0 ? parts : text;
}
export function PatternAccordionCardRenderer({
item,
onPress,
}: CollectionItemRendererProps) {
const router = useRouter();
const [expanded, setExpanded] = useState(false);
@ -340,9 +308,7 @@ export function PatternAccordionCardRenderer({
{explanations.map((exp, idx) => (
<View key={idx} style={accordionStyles.explanationRow}>
<View style={accordionStyles.explanationDot} />
<Text style={accordionStyles.explanationText}>
{renderExplanationParts(exp, handlePointPress)}
</Text>
<Text style={accordionStyles.explanationText}>{exp}</Text>
</View>
))}
</View>
@ -359,22 +325,6 @@ export function PatternAccordionCardRenderer({
</View>
) : null}
{/* Optional link to navigate to full detail screen */}
{onPress ? (
<Pressable
accessibilityRole="button"
onPress={onPress}
style={({ pressed }) => [
accordionStyles.viewFullDetailBtn,
pressed && accordionStyles.pressed,
]}
>
<Text style={accordionStyles.viewFullDetailText}>
View Full Details
</Text>
<Ionicons name="arrow-forward" size={14} color={greenTone.accent} />
</Pressable>
) : null}
</>
)}
</View>
@ -393,7 +343,7 @@ export function ModuleCatalogCardRenderer({
// If this item points to a pattern content item, render inline accordion
if (isContentRef) {
return <PatternAccordionCardRenderer item={item} onPress={onPress} />;
return <PatternAccordionCardRenderer item={item} />;
}
const rawTitle = asString(attributes.name) || item.title;
@ -422,12 +372,23 @@ export function ModuleCatalogCardRenderer({
const cleanTitle = humanizeKey(title);
const label = rawLabel ? humanizeKey(rawLabel) : null;
const count = asNumber(attributes.content_count);
const itemCode = asString(attributes.code).toLowerCase().trim();
const rawTitleLower = rawTitle.toLowerCase().trim();
const isClickable =
count !== 0 &&
!["diseases_after_childbirth", "other"].includes(itemCode) &&
!["diseases after childbirth", "other"].includes(rawTitleLower);
return (
<Pressable
accessibilityRole="button"
onPress={onPress}
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
accessibilityRole={isClickable ? "button" : undefined}
disabled={!isClickable}
onPress={isClickable ? onPress : undefined}
style={({ pressed }) => [
styles.row,
isClickable && pressed && styles.pressed,
]}
>
<View style={styles.iconWrapper}>
<Ionicons name="book-outline" size={22} color={Colors.primary} />
@ -443,10 +404,12 @@ export function ModuleCatalogCardRenderer({
</View>
<ContentCountBadge
count={asNumber(attributes.content_count)}
count={count}
label={asString(attributes.content_label)}
/>
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
{isClickable ? (
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
) : null}
</Pressable>
);
}
@ -626,11 +589,6 @@ const accordionStyles = StyleSheet.create({
fontWeight: "700",
color: "#35664E",
},
pointTextLink: {
color: "#285A44",
fontWeight: "700",
textDecorationLine: "underline",
},
methodContainer: {
marginTop: verticalScale(4),
flexDirection: "row",
@ -697,18 +655,6 @@ const accordionStyles = StyleSheet.create({
fontWeight: "600",
color: "#35664E",
},
viewFullDetailBtn: {
flexDirection: "row",
alignItems: "center",
justifyContent: "flex-end",
gap: moderateScale(6),
paddingTop: verticalScale(6),
},
viewFullDetailText: {
fontSize: moderateScale(13),
fontWeight: "600",
color: greenTone.accent,
},
});
const styles = StyleSheet.create({

View File

@ -41,5 +41,6 @@ export function asRecordArray(value: unknown): Record<string, unknown>[] {
export function humanizeKey(value: string): string {
return value
.replace(/[_-]/g, " ")
.replace(/\b\w/g, (letter) => letter.toUpperCase());
.replace(/\b\w/g, (letter) => letter.toUpperCase())
.replace(/(['’‘ʼ])s\b/gi, (match) => match[0] + "s");
}