102 lines
3.0 KiB
TypeScript
102 lines
3.0 KiB
TypeScript
import React, { type PropsWithChildren, useState } from "react";
|
|
import { Pressable, StyleSheet, View } from "react-native";
|
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
import { router, useLocalSearchParams } from "expo-router";
|
|
|
|
import { Colors } from "@/theme";
|
|
import { ContentPageHeader } from "../../components/layout/ContentPageHeader";
|
|
import { useModuleDisplayName } from "../../hooks/use-module-display-name";
|
|
|
|
interface DetailPageShellProps extends PropsWithChildren {
|
|
title: string;
|
|
subtitle?: string;
|
|
onBack?: () => void;
|
|
}
|
|
|
|
export function DetailPageShell({ children, onBack }: DetailPageShellProps) {
|
|
const [isFavorite, setIsFavorite] = useState(false);
|
|
const { moduleCode } = useLocalSearchParams<{ moduleCode?: string }>();
|
|
const currentModuleCode = typeof moduleCode === "string" ? moduleCode : "";
|
|
const moduleDisplay = useModuleDisplayName(currentModuleCode);
|
|
|
|
const searchAction = currentModuleCode ? (
|
|
<Pressable
|
|
accessibilityRole="button"
|
|
accessibilityLabel={`Search within ${moduleDisplay.name}`}
|
|
hitSlop={10}
|
|
onPress={() =>
|
|
router.push(`/modules/${encodeURIComponent(currentModuleCode)}/search` as never)
|
|
}
|
|
style={({ pressed }) => [styles.iconButton, pressed && styles.pressed]}
|
|
>
|
|
<Ionicons name="search" size={22} color={Colors.primaryDark} />
|
|
</Pressable>
|
|
) : null;
|
|
|
|
const favoriteAction = (
|
|
<Pressable
|
|
accessibilityRole="button"
|
|
accessibilityLabel={isFavorite ? "Remove from favorites" : "Add to favorites"}
|
|
hitSlop={10}
|
|
onPress={() => setIsFavorite((value) => !value)}
|
|
style={({ pressed }) => [styles.iconButton, pressed && styles.pressed]}
|
|
>
|
|
<Ionicons
|
|
name={isFavorite ? "heart" : "heart-outline"}
|
|
size={22}
|
|
color={isFavorite ? Colors.error : Colors.textPrimary}
|
|
/>
|
|
</Pressable>
|
|
);
|
|
|
|
return (
|
|
<SafeAreaView style={styles.screen} edges={["top", "left", "right"]}>
|
|
<ContentPageHeader
|
|
title={moduleDisplay.name}
|
|
onBack={onBack}
|
|
onTitlePress={
|
|
currentModuleCode
|
|
? () => router.push(moduleDisplay.homeRoute as never)
|
|
: undefined
|
|
}
|
|
titleAccessibilityLabel={
|
|
currentModuleCode ? `Open ${moduleDisplay.name} home` : moduleDisplay.name
|
|
}
|
|
fallbackRoute={moduleDisplay.homeRoute}
|
|
right={
|
|
<View style={styles.actions}>
|
|
{searchAction}
|
|
{favoriteAction}
|
|
</View>
|
|
}
|
|
/>
|
|
<View style={styles.body}>{children}</View>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
screen: {
|
|
flex: 1,
|
|
backgroundColor: "#FFFFFF",
|
|
},
|
|
body: {
|
|
flex: 1,
|
|
backgroundColor: "#F6F8F7",
|
|
},
|
|
actions: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
},
|
|
iconButton: {
|
|
width: 36,
|
|
height: 40,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
},
|
|
pressed: {
|
|
opacity: 0.65,
|
|
},
|
|
});
|