fix(gallery): resolve excess pagination dots and hide inherited point images in point categories (issue #125) #130

Merged
amit merged 4 commits from fix/issue-125-pagination-dots into main 2026-11-19 04:55:48 +00:00
3 changed files with 104 additions and 30 deletions

View File

@ -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 },
}); });

View File

@ -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);

View File

@ -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 },