Compare commits
No commits in common. "2e75f7dde683985244572633e614ac4e89ca9bdf" and "8e56d5eb4f96fa7b6bfef379502188a60d6936d0" have entirely different histories.
2e75f7dde6
...
8e56d5eb4f
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
import React, { useCallback, useEffect, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
|
|
@ -23,8 +23,6 @@ import {
|
||||||
} from "@/features/modules/module-index";
|
} from "@/features/modules/module-index";
|
||||||
|
|
||||||
export default function LibraryScreen() {
|
export default function LibraryScreen() {
|
||||||
const isNavigatingRef = useRef(false);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
access,
|
access,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
|
@ -55,7 +53,6 @@ export default function LibraryScreen() {
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
isNavigatingRef.current = false;
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
@ -82,12 +79,6 @@ export default function LibraryScreen() {
|
||||||
|
|
||||||
const handleModulePress = useCallback(
|
const handleModulePress = useCallback(
|
||||||
(item: ModuleIndexItem) => {
|
(item: ModuleIndexItem) => {
|
||||||
if (isNavigatingRef.current) return;
|
|
||||||
isNavigatingRef.current = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
isNavigatingRef.current = false;
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
setLastViewedModule({
|
setLastViewedModule({
|
||||||
moduleId: item.module.id,
|
moduleId: item.module.id,
|
||||||
moduleCode: item.module.code,
|
moduleCode: item.module.code,
|
||||||
|
|
|
||||||
|
|
@ -80,16 +80,13 @@ export default function ForgotPasswordScreen() {
|
||||||
} else if (newPassword.length < 8) {
|
} else if (newPassword.length < 8) {
|
||||||
setPasswordError("Must be at least 8 characters");
|
setPasswordError("Must be at least 8 characters");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (/\s/.test(newPassword)) {
|
|
||||||
setPasswordError("Password must not contain spaces");
|
|
||||||
hasError = true;
|
|
||||||
} else if (!/[A-Z]/.test(newPassword)) {
|
} else if (!/[A-Z]/.test(newPassword)) {
|
||||||
setPasswordError("Must contain at least one uppercase letter");
|
setPasswordError("Must contain at least one uppercase letter");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (!/[0-9]/.test(newPassword)) {
|
} else if (!/[0-9]/.test(newPassword)) {
|
||||||
setPasswordError("Must contain at least one number");
|
setPasswordError("Must contain at least one number");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (!/[^A-Za-z0-9\s]/.test(newPassword)) {
|
} else if (!/[^A-Za-z0-9]/.test(newPassword)) {
|
||||||
setPasswordError("Must contain at least one special character");
|
setPasswordError("Must contain at least one special character");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,16 +45,13 @@ export default function ChangePasswordScreen() {
|
||||||
} 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;
|
||||||
} else if (/\s/.test(newPassword)) {
|
|
||||||
setNewError("Password must not contain spaces");
|
|
||||||
hasError = true;
|
|
||||||
} else if (!/[A-Z]/.test(newPassword)) {
|
} else if (!/[A-Z]/.test(newPassword)) {
|
||||||
setNewError("Must contain at least one uppercase letter");
|
setNewError("Must contain at least one uppercase letter");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (!/[0-9]/.test(newPassword)) {
|
} else if (!/[0-9]/.test(newPassword)) {
|
||||||
setNewError("Must contain at least one number");
|
setNewError("Must contain at least one number");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (!/[^A-Za-z0-9\s]/.test(newPassword)) {
|
} else if (!/[^A-Za-z0-9]/.test(newPassword)) {
|
||||||
setNewError("Must contain at least one special character");
|
setNewError("Must contain at least one special character");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,6 @@ export default function LoginForm({
|
||||||
if (!password) {
|
if (!password) {
|
||||||
setPasswordError("Password is required");
|
setPasswordError("Password is required");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (/\s/.test(password)) {
|
|
||||||
setPasswordError("Password must not contain spaces");
|
|
||||||
hasError = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasError) return;
|
if (hasError) return;
|
||||||
|
|
|
||||||
|
|
@ -63,16 +63,13 @@ export default function SignUpForm() {
|
||||||
} else if (password.length < 8) {
|
} else if (password.length < 8) {
|
||||||
setPasswordError("Password must be at least 8 characters");
|
setPasswordError("Password must be at least 8 characters");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (/\s/.test(password)) {
|
|
||||||
setPasswordError("Password must not contain spaces");
|
|
||||||
hasError = true;
|
|
||||||
} else if (!/[A-Z]/.test(password)) {
|
} else if (!/[A-Z]/.test(password)) {
|
||||||
setPasswordError("Password must contain at least one uppercase letter (A-Z)");
|
setPasswordError("Password must contain at least one uppercase letter (A-Z)");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (!/[0-9]/.test(password)) {
|
} else if (!/[0-9]/.test(password)) {
|
||||||
setPasswordError("Password must contain at least one number (0-9)");
|
setPasswordError("Password must contain at least one number (0-9)");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (!/[^A-Za-z0-9\s]/.test(password)) {
|
} else if (!/[^A-Za-z0-9]/.test(password)) {
|
||||||
setPasswordError("Password must contain at least one special character (!@#$)");
|
setPasswordError("Password must contain at least one special character (!@#$)");
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ export function ContentLink({
|
||||||
disabled = false,
|
disabled = false,
|
||||||
}: ContentLinkProps) {
|
}: ContentLinkProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const isNavigatingRef = React.useRef(false);
|
|
||||||
const label = reference.label?.trim() || defaultReferenceLabel(reference);
|
const label = reference.label?.trim() || defaultReferenceLabel(reference);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -42,12 +41,6 @@ export function ContentLink({
|
||||||
accessibilityState={{ disabled }}
|
accessibilityState={{ disabled }}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (isNavigatingRef.current) return;
|
|
||||||
isNavigatingRef.current = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
isNavigatingRef.current = false;
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
onPress?.(reference);
|
onPress?.(reference);
|
||||||
router.push(buildContentReferenceRoute(reference) as never);
|
router.push(buildContentReferenceRoute(reference) as never);
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,3 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { StyleSheet, TextInput, View } from "react-native";
|
import { TextInput, View } from "react-native";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
export function ContentSearchBar({value,onChangeText}:{value:string;onChangeText:(v:string)=>void}){return <View style={{padding:16}}><TextInput value={value} onChangeText={onChangeText} placeholder="Search..." autoCapitalize="none" autoCorrect={false} style={{borderWidth:1,borderRadius:10,padding:10}}/></View>}
|
||||||
import { Colors } from "@/theme";
|
|
||||||
|
|
||||||
export function ContentSearchBar({
|
|
||||||
value,
|
|
||||||
onChangeText,
|
|
||||||
}: {
|
|
||||||
value: string;
|
|
||||||
onChangeText: (v: string) => void;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<View style={styles.container}>
|
|
||||||
<View style={styles.searchBox}>
|
|
||||||
<Ionicons name="search" size={18} color={Colors.primaryDark} />
|
|
||||||
<TextInput
|
|
||||||
value={value}
|
|
||||||
onChangeText={onChangeText}
|
|
||||||
placeholder="Search…"
|
|
||||||
placeholderTextColor={Colors.textSecondary}
|
|
||||||
autoCapitalize="none"
|
|
||||||
autoCorrect={false}
|
|
||||||
style={styles.input}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
padding: 16,
|
|
||||||
},
|
|
||||||
searchBox: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 8,
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: Colors.border,
|
|
||||||
borderRadius: 10,
|
|
||||||
paddingHorizontal: 12,
|
|
||||||
backgroundColor: "#FAFAFA",
|
|
||||||
},
|
|
||||||
input: {
|
|
||||||
flex: 1,
|
|
||||||
paddingVertical: 10,
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.textPrimary,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,3 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { StyleSheet, TextInput, View } from "react-native";
|
import { TextInput, View } from "react-native";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
export function SearchHeader({value,onChangeText,placeholder="Search…"}:{value:string;onChangeText:(v:string)=>void;placeholder?:string}){ return <View style={{padding:12}}><TextInput value={value} onChangeText={onChangeText} placeholder={placeholder} autoCorrect={false} style={{borderWidth:1,borderRadius:10,paddingHorizontal:12,paddingVertical:10,fontSize:16}}/></View>; }
|
||||||
import { Colors } from "@/theme";
|
|
||||||
|
|
||||||
export function SearchHeader({
|
|
||||||
value,
|
|
||||||
onChangeText,
|
|
||||||
placeholder = "Search…",
|
|
||||||
}: {
|
|
||||||
value: string;
|
|
||||||
onChangeText: (v: string) => void;
|
|
||||||
placeholder?: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<View style={styles.container}>
|
|
||||||
<View style={styles.searchBox}>
|
|
||||||
<Ionicons name="search" size={18} color={Colors.primaryDark} />
|
|
||||||
<TextInput
|
|
||||||
value={value}
|
|
||||||
onChangeText={onChangeText}
|
|
||||||
placeholder={placeholder}
|
|
||||||
placeholderTextColor={Colors.textSecondary}
|
|
||||||
autoCorrect={false}
|
|
||||||
style={styles.input}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
padding: 12,
|
|
||||||
},
|
|
||||||
searchBox: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 8,
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: Colors.border,
|
|
||||||
borderRadius: 10,
|
|
||||||
paddingHorizontal: 12,
|
|
||||||
backgroundColor: "#FAFAFA",
|
|
||||||
},
|
|
||||||
input: {
|
|
||||||
flex: 1,
|
|
||||||
paddingVertical: 10,
|
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.textPrimary,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ function sortMedia(media: ContentMediaItem[]): ContentMediaItem[] {
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (a.media_role === "primary" && b.media_role !== "primary") return -1;
|
if (a.media_role === "primary" && b.media_role !== "primary") return -1;
|
||||||
if (b.media_role === "primary" && a.media_role !== "primary") return 1;
|
if (b.media_role === "primary" && a.media_role !== "primary") return 1;
|
||||||
return (a.sort_order ?? 0) - (b.sort_order ?? 0) || a.id.localeCompare(b.id);
|
return a.sort_order - b.sort_order || a.id.localeCompare(b.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,7 +232,7 @@ const styles = StyleSheet.create({
|
||||||
slide: { height: 290, alignItems: "center", justifyContent: "center" },
|
slide: { height: 290, alignItems: "center", justifyContent: "center" },
|
||||||
image: { width: "100%", height: "100%", backgroundColor: Colors.surface },
|
image: { width: "100%", height: "100%", backgroundColor: Colors.surface },
|
||||||
loadingOverlay: {
|
loadingOverlay: {
|
||||||
...(StyleSheet.absoluteFill as object),
|
...StyleSheet.absoluteFillObject,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
backgroundColor: Colors.surface,
|
backgroundColor: Colors.surface,
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,13 @@ import {
|
||||||
View,
|
View,
|
||||||
ViewToken,
|
ViewToken,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
||||||
import { SafeAreaView } from "react-native-safe-area-context";
|
import { SafeAreaView } from "react-native-safe-area-context";
|
||||||
|
|
||||||
import { useAuthStore } from "@/store/auth.store";
|
import { useAuthStore } from "@/store/auth.store";
|
||||||
import { Colors } from "@/theme/colors";
|
import { Colors } from "@/theme/colors";
|
||||||
import type { ContentMediaItem } from "../types/media.types";
|
import type { ContentMediaItem } from "../types/media.types";
|
||||||
import { mediaLabel } from "./media-source";
|
import { mediaLabel } from "./media-source";
|
||||||
import { ZoomableImage, type ZoomableImageHandle } from "./ZoomableImage";
|
import { ZoomableImage } from "./ZoomableImage";
|
||||||
|
|
||||||
interface FullScreenMediaViewerProps {
|
interface FullScreenMediaViewerProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
|
|
@ -33,7 +32,6 @@ export function FullScreenMediaViewer({
|
||||||
onClose,
|
onClose,
|
||||||
}: FullScreenMediaViewerProps) {
|
}: FullScreenMediaViewerProps) {
|
||||||
const listRef = useRef<FlatList<ContentMediaItem>>(null);
|
const listRef = useRef<FlatList<ContentMediaItem>>(null);
|
||||||
const imageRefs = useRef<Map<string, ZoomableImageHandle>>(new Map());
|
|
||||||
const { width, height } = useWindowDimensions();
|
const { width, height } = useWindowDimensions();
|
||||||
const accessToken = useAuthStore((state) => state.accessToken);
|
const accessToken = useAuthStore((state) => state.accessToken);
|
||||||
const [activeIndex, setActiveIndex] = useState(initialIndex);
|
const [activeIndex, setActiveIndex] = useState(initialIndex);
|
||||||
|
|
@ -63,24 +61,6 @@ export function FullScreenMediaViewer({
|
||||||
|
|
||||||
const active = images[activeIndex];
|
const active = images[activeIndex];
|
||||||
|
|
||||||
const handleZoomIn = () => {
|
|
||||||
if (active) {
|
|
||||||
imageRefs.current.get(active.id)?.zoomIn();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleZoomOut = () => {
|
|
||||||
if (active) {
|
|
||||||
imageRefs.current.get(active.id)?.zoomOut();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleResetZoom = () => {
|
|
||||||
if (active) {
|
|
||||||
imageRefs.current.get(active.id)?.resetZoom();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={visible}
|
visible={visible}
|
||||||
|
|
@ -89,108 +69,63 @@ export function FullScreenMediaViewer({
|
||||||
statusBarTranslucent
|
statusBarTranslucent
|
||||||
onRequestClose={onClose}
|
onRequestClose={onClose}
|
||||||
>
|
>
|
||||||
<GestureHandlerRootView style={styles.modalRoot}>
|
<SafeAreaView style={styles.root}>
|
||||||
<SafeAreaView style={styles.root}>
|
<View style={styles.toolbar}>
|
||||||
<View style={styles.toolbar}>
|
<Text style={styles.counter} accessibilityLiveRegion="polite">
|
||||||
<Text style={styles.counter} accessibilityLiveRegion="polite">
|
{activeIndex + 1} / {images.length}
|
||||||
{activeIndex + 1} / {images.length}
|
</Text>
|
||||||
</Text>
|
<Pressable
|
||||||
|
onPress={onClose}
|
||||||
|
hitSlop={16}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Close image viewer"
|
||||||
|
style={({ pressed }) => [styles.closeButton, pressed && styles.pressed]}
|
||||||
|
>
|
||||||
|
<Ionicons name="close" size={28} color={Colors.white} />
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
|
||||||
<View style={styles.controlsGroup}>
|
<FlatList
|
||||||
<Pressable
|
ref={listRef}
|
||||||
onPress={handleZoomOut}
|
data={images}
|
||||||
hitSlop={8}
|
horizontal
|
||||||
accessibilityRole="button"
|
pagingEnabled
|
||||||
accessibilityLabel="Zoom out"
|
scrollEnabled={!zoomed}
|
||||||
style={({ pressed }) => [styles.controlButton, pressed && styles.pressed]}
|
showsHorizontalScrollIndicator={false}
|
||||||
>
|
keyExtractor={(item) => item.id}
|
||||||
<Ionicons name="remove" size={20} color={Colors.white} />
|
initialScrollIndex={Math.min(initialIndex, Math.max(images.length - 1, 0))}
|
||||||
</Pressable>
|
getItemLayout={(_data, index) => ({ length: width, offset: width * index, index })}
|
||||||
|
onScrollToIndexFailed={(info) => {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
listRef.current?.scrollToOffset({ offset: info.index * width, animated: false });
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
viewabilityConfig={{ itemVisiblePercentThreshold: 60 }}
|
||||||
|
onViewableItemsChanged={onViewableItemsChanged}
|
||||||
|
renderItem={({ item, index }) => (
|
||||||
|
<ZoomableImage
|
||||||
|
item={item}
|
||||||
|
accessToken={accessToken}
|
||||||
|
width={width}
|
||||||
|
height={Math.max(height - 150, 320)}
|
||||||
|
active={index === activeIndex}
|
||||||
|
onZoomStateChange={index === activeIndex ? setZoomed : undefined}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Pressable
|
<View style={styles.footer}>
|
||||||
onPress={handleResetZoom}
|
<Text numberOfLines={2} style={styles.caption}>
|
||||||
hitSlop={8}
|
{mediaLabel(active, activeIndex)}
|
||||||
accessibilityRole="button"
|
</Text>
|
||||||
accessibilityLabel="Reset zoom"
|
<Text style={styles.hint}>Pinch or double-tap to zoom</Text>
|
||||||
style={({ pressed }) => [styles.controlButton, pressed && styles.pressed]}
|
</View>
|
||||||
>
|
</SafeAreaView>
|
||||||
<Ionicons name="refresh" size={16} color={Colors.white} />
|
|
||||||
</Pressable>
|
|
||||||
|
|
||||||
<Pressable
|
|
||||||
onPress={handleZoomIn}
|
|
||||||
hitSlop={8}
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel="Zoom in"
|
|
||||||
style={({ pressed }) => [styles.controlButton, pressed && styles.pressed]}
|
|
||||||
>
|
|
||||||
<Ionicons name="add" size={20} color={Colors.white} />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<Pressable
|
|
||||||
onPress={onClose}
|
|
||||||
hitSlop={16}
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel="Close image viewer"
|
|
||||||
style={({ pressed }) => [styles.closeButton, pressed && styles.pressed]}
|
|
||||||
>
|
|
||||||
<Ionicons name="close" size={26} color={Colors.white} />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<FlatList
|
|
||||||
ref={listRef}
|
|
||||||
data={images}
|
|
||||||
horizontal
|
|
||||||
pagingEnabled
|
|
||||||
scrollEnabled={!zoomed}
|
|
||||||
showsHorizontalScrollIndicator={false}
|
|
||||||
keyExtractor={(item) => item.id}
|
|
||||||
initialScrollIndex={Math.min(initialIndex, Math.max(images.length - 1, 0))}
|
|
||||||
getItemLayout={(_data, index) => ({ length: width, offset: width * index, index })}
|
|
||||||
onScrollToIndexFailed={(info) => {
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
listRef.current?.scrollToOffset({ offset: info.index * width, animated: false });
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
viewabilityConfig={{ itemVisiblePercentThreshold: 60 }}
|
|
||||||
onViewableItemsChanged={onViewableItemsChanged}
|
|
||||||
renderItem={({ item, index }) => (
|
|
||||||
<ZoomableImage
|
|
||||||
ref={(handle) => {
|
|
||||||
if (handle) {
|
|
||||||
imageRefs.current.set(item.id, handle);
|
|
||||||
} else {
|
|
||||||
imageRefs.current.delete(item.id);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
item={item}
|
|
||||||
accessToken={accessToken}
|
|
||||||
width={width}
|
|
||||||
height={Math.max(height - 150, 320)}
|
|
||||||
active={index === activeIndex}
|
|
||||||
onZoomStateChange={index === activeIndex ? setZoomed : undefined}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<View style={styles.footer}>
|
|
||||||
<Text numberOfLines={2} style={styles.caption}>
|
|
||||||
{mediaLabel(active, activeIndex)}
|
|
||||||
</Text>
|
|
||||||
<Text style={styles.hint}>
|
|
||||||
Pinch, double-tap, or use +/- to zoom · Drag to pan
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
</SafeAreaView>
|
|
||||||
</GestureHandlerRootView>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
modalRoot: { flex: 1, backgroundColor: Colors.black },
|
|
||||||
root: { flex: 1, backgroundColor: Colors.black },
|
root: { flex: 1, backgroundColor: Colors.black },
|
||||||
toolbar: {
|
toolbar: {
|
||||||
height: 56,
|
height: 56,
|
||||||
|
|
@ -201,21 +136,6 @@ const styles = StyleSheet.create({
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
},
|
},
|
||||||
counter: { color: Colors.white, fontSize: 15, fontWeight: "700" },
|
counter: { color: Colors.white, fontSize: 15, fontWeight: "700" },
|
||||||
controlsGroup: {
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
backgroundColor: "rgba(255,255,255,0.12)",
|
|
||||||
borderRadius: 20,
|
|
||||||
paddingHorizontal: 4,
|
|
||||||
gap: 4,
|
|
||||||
},
|
|
||||||
controlButton: {
|
|
||||||
width: 36,
|
|
||||||
height: 36,
|
|
||||||
borderRadius: 18,
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
},
|
|
||||||
closeButton: {
|
closeButton: {
|
||||||
width: 44,
|
width: 44,
|
||||||
height: 44,
|
height: 44,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,4 @@
|
||||||
import React, {
|
import React, { memo, useEffect, useMemo, useState } from "react";
|
||||||
forwardRef,
|
|
||||||
memo,
|
|
||||||
useEffect,
|
|
||||||
useImperativeHandle,
|
|
||||||
useMemo,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
|
import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
|
||||||
import { Image } from "expo-image";
|
import { Image } from "expo-image";
|
||||||
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
||||||
|
|
@ -23,13 +16,6 @@ import { buildMediaImageSourceFromValues } from "./media-source";
|
||||||
const MIN_SCALE = 1;
|
const MIN_SCALE = 1;
|
||||||
const MAX_SCALE = 4;
|
const MAX_SCALE = 4;
|
||||||
const DOUBLE_TAP_SCALE = 2.5;
|
const DOUBLE_TAP_SCALE = 2.5;
|
||||||
const SCALE_STEP = 0.75;
|
|
||||||
|
|
||||||
export interface ZoomableImageHandle {
|
|
||||||
zoomIn: () => void;
|
|
||||||
zoomOut: () => void;
|
|
||||||
resetZoom: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ZoomableImageProps {
|
interface ZoomableImageProps {
|
||||||
item: ContentMediaItem;
|
item: ContentMediaItem;
|
||||||
|
|
@ -45,216 +31,185 @@ function clamp(value: number, min: number, max: number): number {
|
||||||
return Math.min(Math.max(value, min), max);
|
return Math.min(Math.max(value, min), max);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ZoomableImage = memo(
|
export const ZoomableImage = memo(function ZoomableImage({
|
||||||
forwardRef<ZoomableImageHandle, ZoomableImageProps>(function ZoomableImage(
|
item,
|
||||||
{
|
accessToken,
|
||||||
item,
|
width,
|
||||||
accessToken,
|
height,
|
||||||
width,
|
active,
|
||||||
height,
|
onZoomStateChange,
|
||||||
active,
|
}: ZoomableImageProps) {
|
||||||
onZoomStateChange,
|
const scale = useSharedValue(1);
|
||||||
},
|
const savedScale = useSharedValue(1);
|
||||||
ref,
|
const translateX = useSharedValue(0);
|
||||||
) {
|
const translateY = useSharedValue(0);
|
||||||
const scale = useSharedValue(1);
|
const savedX = useSharedValue(0);
|
||||||
const savedScale = useSharedValue(1);
|
const savedY = useSharedValue(0);
|
||||||
const translateX = useSharedValue(0);
|
|
||||||
const translateY = useSharedValue(0);
|
|
||||||
const savedX = useSharedValue(0);
|
|
||||||
const savedY = useSharedValue(0);
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [failed, setFailed] = useState(false);
|
const [failed, setFailed] = useState(false);
|
||||||
|
const [isZoomed, setIsZoomed] = useState(false);
|
||||||
|
|
||||||
const source = useMemo(
|
const source = useMemo(
|
||||||
() =>
|
() =>
|
||||||
buildMediaImageSourceFromValues(
|
buildMediaImageSourceFromValues(
|
||||||
item.url,
|
item.url,
|
||||||
item.storage_key,
|
item.storage_key,
|
||||||
item.requires_auth,
|
item.requires_auth,
|
||||||
accessToken,
|
accessToken,
|
||||||
),
|
),
|
||||||
[item.url, item.storage_key, item.requires_auth, accessToken],
|
[item.url, item.storage_key, item.requires_auth, accessToken],
|
||||||
);
|
);
|
||||||
|
|
||||||
const sourceUri =
|
const sourceUri =
|
||||||
source && typeof source === "object" && !Array.isArray(source)
|
source && typeof source === "object" && !Array.isArray(source)
|
||||||
? source.uri ?? null
|
? source.uri ?? null
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFailed(false);
|
setFailed(false);
|
||||||
setLoading(Boolean(sourceUri));
|
setLoading(Boolean(sourceUri));
|
||||||
}, [sourceUri]);
|
}, [sourceUri]);
|
||||||
|
|
||||||
const notifyZoom = (zoomed: boolean) => {
|
const notifyZoom = (zoomed: boolean) => {
|
||||||
onZoomStateChange?.(zoomed);
|
setIsZoomed(zoomed);
|
||||||
};
|
onZoomStateChange?.(zoomed);
|
||||||
|
};
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
"worklet";
|
"worklet";
|
||||||
scale.value = withTiming(1, { duration: 250 });
|
scale.value = withTiming(1);
|
||||||
|
savedScale.value = 1;
|
||||||
|
translateX.value = withTiming(0);
|
||||||
|
translateY.value = withTiming(0);
|
||||||
|
savedX.value = 0;
|
||||||
|
savedY.value = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!active) {
|
||||||
|
scale.value = 1;
|
||||||
savedScale.value = 1;
|
savedScale.value = 1;
|
||||||
translateX.value = withTiming(0, { duration: 250 });
|
translateX.value = 0;
|
||||||
translateY.value = withTiming(0, { duration: 250 });
|
translateY.value = 0;
|
||||||
savedX.value = 0;
|
savedX.value = 0;
|
||||||
savedY.value = 0;
|
savedY.value = 0;
|
||||||
};
|
setIsZoomed(false);
|
||||||
|
onZoomStateChange?.(false);
|
||||||
useImperativeHandle(
|
|
||||||
ref,
|
|
||||||
() => ({
|
|
||||||
zoomIn: () => {
|
|
||||||
const next = Math.min(savedScale.value + SCALE_STEP, MAX_SCALE);
|
|
||||||
savedScale.value = next;
|
|
||||||
scale.value = withTiming(next, { duration: 250 });
|
|
||||||
notifyZoom(next > 1.01);
|
|
||||||
},
|
|
||||||
zoomOut: () => {
|
|
||||||
const next = Math.max(savedScale.value - SCALE_STEP, MIN_SCALE);
|
|
||||||
savedScale.value = next;
|
|
||||||
scale.value = withTiming(next, { duration: 250 });
|
|
||||||
if (next <= 1.01) {
|
|
||||||
translateX.value = withTiming(0, { duration: 250 });
|
|
||||||
translateY.value = withTiming(0, { duration: 250 });
|
|
||||||
savedX.value = 0;
|
|
||||||
savedY.value = 0;
|
|
||||||
notifyZoom(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
resetZoom: () => {
|
|
||||||
reset();
|
|
||||||
notifyZoom(false);
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!active) {
|
|
||||||
scale.value = 1;
|
|
||||||
savedScale.value = 1;
|
|
||||||
translateX.value = 0;
|
|
||||||
translateY.value = 0;
|
|
||||||
savedX.value = 0;
|
|
||||||
savedY.value = 0;
|
|
||||||
onZoomStateChange?.(false);
|
|
||||||
}
|
|
||||||
}, [active, onZoomStateChange, savedScale, savedX, savedY, scale, translateX, translateY]);
|
|
||||||
|
|
||||||
const pinch = Gesture.Pinch()
|
|
||||||
.onBegin(() => {
|
|
||||||
runOnJS(notifyZoom)(true);
|
|
||||||
})
|
|
||||||
.onUpdate((event) => {
|
|
||||||
scale.value = clamp(savedScale.value * event.scale, MIN_SCALE, MAX_SCALE);
|
|
||||||
})
|
|
||||||
.onEnd(() => {
|
|
||||||
savedScale.value = scale.value;
|
|
||||||
if (scale.value <= 1.01) {
|
|
||||||
reset();
|
|
||||||
runOnJS(notifyZoom)(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const pan = Gesture.Pan()
|
|
||||||
.minDistance(8)
|
|
||||||
.maxPointers(1)
|
|
||||||
.onUpdate((event) => {
|
|
||||||
if (scale.value <= 1.01) return;
|
|
||||||
const maxX = Math.max(0, ((scale.value - 1) * width) / 2);
|
|
||||||
const maxY = Math.max(0, ((scale.value - 1) * height) / 2);
|
|
||||||
translateX.value = clamp(savedX.value + event.translationX, -maxX, maxX);
|
|
||||||
translateY.value = clamp(savedY.value + event.translationY, -maxY, maxY);
|
|
||||||
})
|
|
||||||
.onEnd(() => {
|
|
||||||
savedX.value = translateX.value;
|
|
||||||
savedY.value = translateY.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
const doubleTap = Gesture.Tap()
|
|
||||||
.numberOfTaps(2)
|
|
||||||
.maxDuration(250)
|
|
||||||
.onEnd((_event, success) => {
|
|
||||||
if (!success) return;
|
|
||||||
if (scale.value > 1.01) {
|
|
||||||
reset();
|
|
||||||
runOnJS(notifyZoom)(false);
|
|
||||||
} else {
|
|
||||||
scale.value = withTiming(DOUBLE_TAP_SCALE, { duration: 250 });
|
|
||||||
savedScale.value = DOUBLE_TAP_SCALE;
|
|
||||||
runOnJS(notifyZoom)(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const gesture = Gesture.Exclusive(doubleTap, Gesture.Simultaneous(pinch, pan));
|
|
||||||
|
|
||||||
const animatedStyle = useAnimatedStyle(() => ({
|
|
||||||
transform: [
|
|
||||||
{ translateX: translateX.value },
|
|
||||||
{ translateY: translateY.value },
|
|
||||||
{ scale: scale.value },
|
|
||||||
],
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (!source) {
|
|
||||||
return (
|
|
||||||
<View style={[styles.frame, { width, height }]}>
|
|
||||||
<View style={styles.error}>
|
|
||||||
<Text style={styles.errorTitle}>Image unavailable</Text>
|
|
||||||
<Text style={styles.errorText}>No media URL is available for this image.</Text>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
}, [active, onZoomStateChange, savedScale, savedX, savedY, scale, translateX, translateY]);
|
||||||
|
|
||||||
|
const pinch = Gesture.Pinch()
|
||||||
|
.onBegin(() => {
|
||||||
|
runOnJS(notifyZoom)(true);
|
||||||
|
})
|
||||||
|
.onUpdate((event) => {
|
||||||
|
scale.value = clamp(savedScale.value * event.scale, MIN_SCALE, MAX_SCALE);
|
||||||
|
})
|
||||||
|
.onEnd(() => {
|
||||||
|
savedScale.value = scale.value;
|
||||||
|
if (scale.value <= 1.01) {
|
||||||
|
reset();
|
||||||
|
runOnJS(notifyZoom)(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const pan = Gesture.Pan()
|
||||||
|
.enabled(isZoomed)
|
||||||
|
.maxPointers(1)
|
||||||
|
.onUpdate((event) => {
|
||||||
|
if (scale.value <= 1) return;
|
||||||
|
const maxX = ((scale.value - 1) * width) / 2;
|
||||||
|
const maxY = ((scale.value - 1) * height) / 2;
|
||||||
|
translateX.value = clamp(savedX.value + event.translationX, -maxX, maxX);
|
||||||
|
translateY.value = clamp(savedY.value + event.translationY, -maxY, maxY);
|
||||||
|
})
|
||||||
|
.onEnd(() => {
|
||||||
|
savedX.value = translateX.value;
|
||||||
|
savedY.value = translateY.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
const doubleTap = Gesture.Tap()
|
||||||
|
.numberOfTaps(2)
|
||||||
|
.maxDuration(250)
|
||||||
|
.onEnd((_event, success) => {
|
||||||
|
if (!success) return;
|
||||||
|
if (scale.value > 1.01) {
|
||||||
|
reset();
|
||||||
|
runOnJS(notifyZoom)(false);
|
||||||
|
} else {
|
||||||
|
scale.value = withTiming(DOUBLE_TAP_SCALE);
|
||||||
|
savedScale.value = DOUBLE_TAP_SCALE;
|
||||||
|
runOnJS(notifyZoom)(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const gesture = Gesture.Race(doubleTap, Gesture.Simultaneous(pinch, pan));
|
||||||
|
|
||||||
|
const animatedStyle = useAnimatedStyle(() => ({
|
||||||
|
transform: [
|
||||||
|
{ translateX: translateX.value },
|
||||||
|
{ translateY: translateY.value },
|
||||||
|
{ scale: scale.value },
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!source) {
|
||||||
return (
|
return (
|
||||||
<View style={[styles.frame, { width, height }]}>
|
<View style={[styles.frame, { width, height }]}>
|
||||||
{loading && !failed ? (
|
<View style={styles.error}>
|
||||||
<View style={styles.loader} pointerEvents="none">
|
<Text style={styles.errorTitle}>Image unavailable</Text>
|
||||||
<ActivityIndicator size="large" color={Colors.white} />
|
<Text style={styles.errorText}>No media URL is available for this image.</Text>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
|
||||||
|
|
||||||
{failed ? (
|
|
||||||
<View style={styles.error}>
|
|
||||||
<Text style={styles.errorTitle}>Unable to load image</Text>
|
|
||||||
<Text style={styles.errorText}>Check your connection and try again.</Text>
|
|
||||||
</View>
|
|
||||||
) : (
|
|
||||||
<GestureDetector gesture={gesture}>
|
|
||||||
<Animated.View style={[styles.imageWrap, animatedStyle]}>
|
|
||||||
<Image
|
|
||||||
source={source}
|
|
||||||
contentFit="contain"
|
|
||||||
style={styles.image}
|
|
||||||
accessible
|
|
||||||
accessibilityRole="image"
|
|
||||||
accessibilityLabel={item.alt_text || item.caption || "Content image"}
|
|
||||||
onLoad={() => setLoading(false)}
|
|
||||||
onError={(error) => {
|
|
||||||
console.warn("Failed to load ZoomableImage:", source, error);
|
|
||||||
setLoading(false);
|
|
||||||
setFailed(true);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Animated.View>
|
|
||||||
</GestureDetector>
|
|
||||||
)}
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}),
|
}
|
||||||
(previous, next) =>
|
|
||||||
previous.item.id === next.item.id &&
|
return (
|
||||||
previous.item.url === next.item.url &&
|
<View style={[styles.frame, { width, height }]}>
|
||||||
previous.item.storage_key === next.item.storage_key &&
|
{loading && !failed ? (
|
||||||
previous.item.requires_auth === next.item.requires_auth &&
|
<View style={styles.loader} pointerEvents="none">
|
||||||
previous.accessToken === next.accessToken &&
|
<ActivityIndicator size="large" color={Colors.white} />
|
||||||
previous.width === next.width &&
|
</View>
|
||||||
previous.height === next.height &&
|
) : null}
|
||||||
previous.active === next.active &&
|
|
||||||
previous.onZoomStateChange === next.onZoomStateChange,
|
{failed ? (
|
||||||
|
<View style={styles.error}>
|
||||||
|
<Text style={styles.errorTitle}>Unable to load image</Text>
|
||||||
|
<Text style={styles.errorText}>Check your connection and try again.</Text>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<GestureDetector gesture={gesture}>
|
||||||
|
<Animated.View style={[styles.imageWrap, animatedStyle]}>
|
||||||
|
<Image
|
||||||
|
source={source}
|
||||||
|
contentFit="contain"
|
||||||
|
style={styles.image}
|
||||||
|
accessible
|
||||||
|
accessibilityRole="image"
|
||||||
|
accessibilityLabel={item.alt_text || item.caption || "Content image"}
|
||||||
|
onLoad={() => setLoading(false)}
|
||||||
|
onError={(error) => {
|
||||||
|
console.warn("Failed to load ZoomableImage:", source, error);
|
||||||
|
setLoading(false);
|
||||||
|
setFailed(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Animated.View>
|
||||||
|
</GestureDetector>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);;
|
||||||
|
}, (previous, next) =>
|
||||||
|
previous.item.id === next.item.id &&
|
||||||
|
previous.item.url === next.item.url &&
|
||||||
|
previous.item.storage_key === next.item.storage_key &&
|
||||||
|
previous.item.requires_auth === next.item.requires_auth &&
|
||||||
|
previous.accessToken === next.accessToken &&
|
||||||
|
previous.width === next.width &&
|
||||||
|
previous.height === next.height &&
|
||||||
|
previous.active === next.active &&
|
||||||
|
previous.onZoomStateChange === next.onZoomStateChange
|
||||||
);
|
);
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|
@ -267,7 +222,7 @@ const styles = StyleSheet.create({
|
||||||
imageWrap: { width: "100%", height: "100%" },
|
imageWrap: { width: "100%", height: "100%" },
|
||||||
image: { width: "100%", height: "100%" },
|
image: { width: "100%", height: "100%" },
|
||||||
loader: {
|
loader: {
|
||||||
...(StyleSheet.absoluteFill as object),
|
...StyleSheet.absoluteFillObject,
|
||||||
zIndex: 2,
|
zIndex: 2,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ export function mediaLabel(item: ContentMediaItem, index: number): string {
|
||||||
return (
|
return (
|
||||||
item.alt_text?.trim() ||
|
item.alt_text?.trim() ||
|
||||||
item.caption?.trim() ||
|
item.caption?.trim() ||
|
||||||
(item.usage_type ? item.usage_type.replace(/_/g, " ").trim() : "") ||
|
item.usage_type.replace(/_/g, " ").trim() ||
|
||||||
`Image ${index + 1}`
|
`Image ${index + 1}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ import { ContentMediaGallery } from "../../media/ContentMediaGallery";
|
||||||
import { useRelationalContentMedia } from "../../media/ContentMediaContext";
|
import { useRelationalContentMedia } from "../../media/ContentMediaContext";
|
||||||
import { asString } from "../helpers/value";
|
import { asString } from "../helpers/value";
|
||||||
|
|
||||||
import type { ContentMediaItem } from "../../types/media.types";
|
|
||||||
|
|
||||||
export function ImageGallery({ images }: { images: Record<string, unknown>[] }) {
|
export function ImageGallery({ images }: { images: Record<string, unknown>[] }) {
|
||||||
const relationalMedia = useRelationalContentMedia();
|
const relationalMedia = useRelationalContentMedia();
|
||||||
|
|
||||||
|
|
@ -17,27 +15,22 @@ export function ImageGallery({ images }: { images: Record<string, unknown>[] })
|
||||||
const visible = images.filter((item) => asString(item.image_path).trim().length > 0);
|
const visible = images.filter((item) => asString(item.image_path).trim().length > 0);
|
||||||
if (!visible.length) return null;
|
if (!visible.length) return null;
|
||||||
|
|
||||||
const fallbackMedia: ContentMediaItem[] = visible.map((item, index) => {
|
return (
|
||||||
const path = asString(item.image_path).trim();
|
<View style={styles.root}>
|
||||||
const name = asString(item.image_name).trim();
|
{visible.map((item, index) => {
|
||||||
return {
|
const path = asString(item.image_path);
|
||||||
id: `${path}-${index}`,
|
const name = asString(item.image_name);
|
||||||
media_asset_id: `${path}-${index}`,
|
return (
|
||||||
media_role: index === 0 ? "primary" : "gallery",
|
<View key={`${path}-${index}`} style={styles.item}>
|
||||||
usage_type: "visual_reference",
|
<View style={styles.imageFrame}>
|
||||||
sort_order: index,
|
<Image source={{ uri: path }} contentFit="contain" style={styles.image} />
|
||||||
caption: name || null,
|
</View>
|
||||||
alt_text: name || "Module image",
|
{name ? <Text style={styles.caption}>{name}</Text> : null}
|
||||||
mime_type: "image/jpeg",
|
</View>
|
||||||
width: null,
|
);
|
||||||
height: null,
|
})}
|
||||||
url: path,
|
</View>
|
||||||
storage_key: null,
|
);
|
||||||
requires_auth: false,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return <ContentMediaGallery media={fallbackMedia} title="Visual reference" />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function CollectionTemplateScreen({
|
||||||
}
|
}
|
||||||
style={({ pressed }) => [styles.iconButton, pressed && styles.pressed]}
|
style={({ pressed }) => [styles.iconButton, pressed && styles.pressed]}
|
||||||
>
|
>
|
||||||
<Ionicons name="search" size={22} color={Colors.primaryDark} />
|
<Ionicons name="search" size={21} color={Colors.textPrimary} />
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
||||||
{hasSort ? (
|
{hasSort ? (
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useCallback, useRef } from "react";
|
import React from "react";
|
||||||
import { useRouter, useFocusEffect } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
import { ScreenError, ScreenLoading } from "../components/ContentScreenState";
|
import { ScreenError, ScreenLoading } from "../components/ContentScreenState";
|
||||||
import { useTemplateContractQuery } from "../hooks/use-template-contract-query";
|
import { useTemplateContractQuery } from "../hooks/use-template-contract-query";
|
||||||
import { CollectionTemplateScreen } from "./CollectionTemplateScreen";
|
import { CollectionTemplateScreen } from "./CollectionTemplateScreen";
|
||||||
|
|
@ -27,13 +27,6 @@ export function TemplateScreen({
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const module = normalized(moduleCode);
|
const module = normalized(moduleCode);
|
||||||
const template = normalized(templateCode);
|
const template = normalized(templateCode);
|
||||||
const isNavigatingRef = useRef(false);
|
|
||||||
|
|
||||||
useFocusEffect(
|
|
||||||
useCallback(() => {
|
|
||||||
isNavigatingRef.current = false;
|
|
||||||
}, []),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!module || !template) {
|
if (!module || !template) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -52,12 +45,6 @@ export function TemplateScreen({
|
||||||
onOpenFilters={onOpenFilters}
|
onOpenFilters={onOpenFilters}
|
||||||
onOpenSort={onOpenSort}
|
onOpenSort={onOpenSort}
|
||||||
navigateToContent={(contentId) => {
|
navigateToContent={(contentId) => {
|
||||||
if (isNavigatingRef.current) return;
|
|
||||||
isNavigatingRef.current = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
isNavigatingRef.current = false;
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
router.push(
|
router.push(
|
||||||
`/modules/${encodeURIComponent(module)}/${encodeURIComponent(template)}/${encodeURIComponent(contentId)}` as never,
|
`/modules/${encodeURIComponent(module)}/${encodeURIComponent(template)}/${encodeURIComponent(contentId)}` as never,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export function FacetValueTypeaheadModal({ visible, facet, scope, activeFilters,
|
||||||
const apply = () => { if(!selected.size) return; onApply({ facet_code: facet.code, values:[...selected.keys()], value_mode:"any", display_values:[...selected.values()] }); close(); };
|
const apply = () => { if(!selected.size) return; onApply({ facet_code: facet.code, values:[...selected.keys()], value_mode:"any", display_values:[...selected.values()] }); close(); };
|
||||||
return <Modal visible={visible} animationType="slide" transparent onRequestClose={close}><View style={styles.overlay}><Pressable style={styles.scrim} onPress={close}/><View style={styles.sheet}>
|
return <Modal visible={visible} animationType="slide" transparent onRequestClose={close}><View style={styles.overlay}><Pressable style={styles.scrim} onPress={close}/><View style={styles.sheet}>
|
||||||
<View style={styles.header}><View><Text style={styles.title}>{facet.label}</Text><Text style={styles.subtitle}>Select {facet.allow_multiple_values ? "one or more values" : "a value"}</Text></View><Pressable onPress={close}><Ionicons name="close" size={22} color={Colors.textPrimary}/></Pressable></View>
|
<View style={styles.header}><View><Text style={styles.title}>{facet.label}</Text><Text style={styles.subtitle}>Select {facet.allow_multiple_values ? "one or more values" : "a value"}</Text></View><Pressable onPress={close}><Ionicons name="close" size={22} color={Colors.textPrimary}/></Pressable></View>
|
||||||
<View style={styles.search}><Ionicons name="search" size={18} color={Colors.primaryDark}/><TextInput value={query} onChangeText={setQuery} placeholder={`Search ${facet.label.toLowerCase()}…`} placeholderTextColor={Colors.textSecondary} style={styles.input}/></View>
|
<View style={styles.search}><Ionicons name="search" size={18} color={Colors.textSecondary}/><TextInput value={query} onChangeText={setQuery} placeholder={`Search ${facet.label.toLowerCase()}…`} placeholderTextColor={Colors.textSecondary} style={styles.input}/></View>
|
||||||
<ScrollView contentContainerStyle={styles.content}>{values.isLoading ? <ActivityIndicator color={Colors.primary}/> : values.data?.items.map((item) => { const active=selected.has(item.value_key); return <Pressable key={item.value_key} style={[styles.valueRow,active&&styles.valueRowActive]} onPress={() => toggle(item.value_key,item.label)}><View style={{flex:1}}><Text style={styles.valueLabel}>{item.label}</Text><Text style={styles.count}>{item.result_count} matching item{item.result_count===1?"":"s"}</Text></View><Ionicons name={active?"checkbox":"square-outline"} size={20} color={active?Colors.primary:Colors.textSecondary}/></Pressable>; })}</ScrollView>
|
<ScrollView contentContainerStyle={styles.content}>{values.isLoading ? <ActivityIndicator color={Colors.primary}/> : values.data?.items.map((item) => { const active=selected.has(item.value_key); return <Pressable key={item.value_key} style={[styles.valueRow,active&&styles.valueRowActive]} onPress={() => toggle(item.value_key,item.label)}><View style={{flex:1}}><Text style={styles.valueLabel}>{item.label}</Text><Text style={styles.count}>{item.result_count} matching item{item.result_count===1?"":"s"}</Text></View><Ionicons name={active?"checkbox":"square-outline"} size={20} color={active?Colors.primary:Colors.textSecondary}/></Pressable>; })}</ScrollView>
|
||||||
<View style={styles.footer}><Pressable onPress={close} style={styles.cancel}><Text style={styles.cancelText}>Cancel</Text></Pressable><Pressable onPress={apply} style={[styles.apply,!selected.size&&styles.disabled]} disabled={!selected.size}><Text style={styles.applyText}>Add {selected.size ? `(${selected.size})` : ""}</Text></Pressable></View>
|
<View style={styles.footer}><Pressable onPress={close} style={styles.cancel}><Text style={styles.cancelText}>Cancel</Text></Pressable><Pressable onPress={apply} style={[styles.apply,!selected.size&&styles.disabled]} disabled={!selected.size}><Text style={styles.applyText}>Add {selected.size ? `(${selected.size})` : ""}</Text></Pressable></View>
|
||||||
</View></View></Modal>;
|
</View></View></Modal>;
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,6 @@ export default function FacetedSearchScreen({
|
||||||
const [facetPickerVisible, setFacetPickerVisible] = useState(false);
|
const [facetPickerVisible, setFacetPickerVisible] = useState(false);
|
||||||
const [selectedFacet, setSelectedFacet] =
|
const [selectedFacet, setSelectedFacet] =
|
||||||
useState<SearchFacetDefinition | null>(null);
|
useState<SearchFacetDefinition | null>(null);
|
||||||
const [isSearchFocused, setIsSearchFocused] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isModuleMode || !normalizedModuleCode) return;
|
if (!isModuleMode || !normalizedModuleCode) return;
|
||||||
|
|
@ -177,22 +176,15 @@ export default function FacetedSearchScreen({
|
||||||
</Text>
|
</Text>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<View
|
<View style={styles.searchBox}>
|
||||||
style={[
|
|
||||||
styles.searchBox,
|
|
||||||
isSearchFocused && styles.searchBoxFocused,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="search"
|
name="search"
|
||||||
size={19}
|
size={19}
|
||||||
color={Colors.primaryDark}
|
color={Colors.textSecondary}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={query}
|
value={query}
|
||||||
onChangeText={setQuery}
|
onChangeText={setQuery}
|
||||||
onFocus={() => setIsSearchFocused(true)}
|
|
||||||
onBlur={() => setIsSearchFocused(false)}
|
|
||||||
placeholder={
|
placeholder={
|
||||||
isModuleMode
|
isModuleMode
|
||||||
? `Search within ${resolvedModuleName}…`
|
? `Search within ${resolvedModuleName}…`
|
||||||
|
|
@ -381,10 +373,6 @@ const styles = StyleSheet.create({
|
||||||
paddingHorizontal: 13,
|
paddingHorizontal: 13,
|
||||||
backgroundColor: "#FAFAFA",
|
backgroundColor: "#FAFAFA",
|
||||||
},
|
},
|
||||||
searchBoxFocused: {
|
|
||||||
borderColor: Colors.primary,
|
|
||||||
backgroundColor: "#FFFFFF",
|
|
||||||
},
|
|
||||||
input: {
|
input: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
minHeight: 46,
|
minHeight: 46,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
import React, { useCallback, useEffect, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
|
|
@ -24,7 +24,6 @@ import {
|
||||||
import type { LastViewedModule } from "@/store/auth.store";
|
import type { LastViewedModule } from "@/store/auth.store";
|
||||||
|
|
||||||
export default function HomeScreen() {
|
export default function HomeScreen() {
|
||||||
const isNavigatingRef = useRef(false);
|
|
||||||
const {
|
const {
|
||||||
user,
|
user,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
|
@ -95,19 +94,7 @@ export default function HomeScreen() {
|
||||||
return lastViewedModule;
|
return lastViewedModule;
|
||||||
}, [access, lastViewedModule, modules]);
|
}, [access, lastViewedModule, modules]);
|
||||||
|
|
||||||
useFocusEffect(
|
|
||||||
useCallback(() => {
|
|
||||||
isNavigatingRef.current = false;
|
|
||||||
}, []),
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleModulePress = useCallback((module: LastViewedModule) => {
|
const handleModulePress = useCallback((module: LastViewedModule) => {
|
||||||
if (isNavigatingRef.current) return;
|
|
||||||
isNavigatingRef.current = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
isNavigatingRef.current = false;
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
router.push(
|
router.push(
|
||||||
buildContentReferenceRoute({
|
buildContentReferenceRoute({
|
||||||
type: "template_ref",
|
type: "template_ref",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
import React, { useCallback, useEffect, useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
Platform,
|
Platform,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
|
|
@ -25,8 +25,6 @@ import {
|
||||||
} from "@/features/modules/module-index";
|
} from "@/features/modules/module-index";
|
||||||
|
|
||||||
export default function ModulesIndexScreen() {
|
export default function ModulesIndexScreen() {
|
||||||
const isNavigatingRef = useRef(false);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
access,
|
access,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
|
@ -75,7 +73,6 @@ export default function ModulesIndexScreen() {
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
isNavigatingRef.current = false;
|
|
||||||
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);
|
||||||
|
|
@ -105,12 +102,6 @@ export default function ModulesIndexScreen() {
|
||||||
|
|
||||||
const handleModulePress = useCallback(
|
const handleModulePress = useCallback(
|
||||||
(item: ModuleIndexItem) => {
|
(item: ModuleIndexItem) => {
|
||||||
if (isNavigatingRef.current) return;
|
|
||||||
isNavigatingRef.current = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
isNavigatingRef.current = false;
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
router.push("/register");
|
router.push("/register");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue