diff --git a/src/features/content/media/ContentMediaGallery.tsx b/src/features/content/media/ContentMediaGallery.tsx index 328e729..ea8ef2e 100644 --- a/src/features/content/media/ContentMediaGallery.tsx +++ b/src/features/content/media/ContentMediaGallery.tsx @@ -141,6 +141,21 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte const [viewerIndex, setViewerIndex] = useState(null); const listRef = useRef>(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; const handleMomentumEnd = (event: NativeSyntheticEvent) => { @@ -169,6 +184,12 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte offset: carouselWidth * index, index, })} + onScrollToIndexFailed={(info) => { + listRef.current?.scrollToOffset({ + offset: info.index * carouselWidth, + animated: true, + }); + }} onMomentumScrollEnd={handleMomentumEnd} renderItem={({ item, index }) => ( 1 ? ( - {items.map((item, index) => ( + {visibleDots.map(({ item, index }) => ( { setActiveIndex(index); - listRef.current?.scrollToIndex({ index, animated: true }); + try { + listRef.current?.scrollToIndex({ index, animated: true }); + } catch { + listRef.current?.scrollToOffset({ offset: index * carouselWidth, animated: true }); + } }} hitSlop={6} > @@ -254,7 +279,12 @@ const styles = StyleSheet.create({ }, zoomText: { color: Colors.white, fontSize: 12, fontWeight: "700" }, 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 }, dotActive: { width: 18, backgroundColor: Colors.primary }, }); diff --git a/src/features/content/renderers/details/categoryParts.tsx b/src/features/content/renderers/details/categoryParts.tsx index 863de06..f761f20 100644 --- a/src/features/content/renderers/details/categoryParts.tsx +++ b/src/features/content/renderers/details/categoryParts.tsx @@ -8,6 +8,8 @@ import { ObjectSections } from "../shared/ObjectSections"; import { RecordCards } from "../shared/RecordCards"; import { RecordTable } from "../shared/RecordTable"; import { SectionCard } from "../shared/SectionCard"; +import { useRelationalContentMedia } from "../../media/ContentMediaContext"; +import { ContentMediaGallery } from "../../media/ContentMediaGallery"; export const PointCodes = ({ data }: { data: Record }) => ( @@ -37,7 +39,21 @@ const extractCategoryImages = (data: Record): Record }) => { const directImages = extractCategoryImages(data); - return ; + const relationalMedia = useRelationalContentMedia(); + + // If direct images are explicitly defined in category data attributes, display them + if (directImages.length > 0) { + return ; + } + + // 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 ; + } + + // 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 }) => {