fix(gallery): resolve excess pagination dots and hide inherited point images in point categories (issue #125)
This commit is contained in:
parent
effed053b8
commit
8990f90132
|
|
@ -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);
|
||||||
listRef.current?.scrollToIndex({ index, animated: true });
|
try {
|
||||||
|
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 },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -37,7 +39,21 @@ const extractCategoryImages = (data: Record<string, unknown>): Record<string, un
|
||||||
|
|
||||||
export const Images = ({ data }: { data: Record<string, unknown> }) => {
|
export const Images = ({ data }: { data: Record<string, unknown> }) => {
|
||||||
const directImages = extractCategoryImages(data);
|
const directImages = extractCategoryImages(data);
|
||||||
return <ImageGallery images={directImages} />;
|
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 }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue