Merge pull request 'fix(gallery): resolve excess pagination dots and hide inherited point images in point categories (issue #125)' (#130) from fix/issue-125-pagination-dots into main
Reviewed-on: https://git.zedobject.local/AcuPedia/acupedia-mobile-ui/pulls/130 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
eee01a5211
|
|
@ -141,6 +141,21 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
|||
const [viewerIndex, setViewerIndex] = useState<number | null>(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;
|
||||
|
||||
const handleMomentumEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
|
|
@ -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 }) => (
|
||||
<Pressable
|
||||
|
|
@ -192,12 +213,16 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
|||
|
||||
{items.length > 1 ? (
|
||||
<View style={styles.dots} accessibilityElementsHidden>
|
||||
{items.map((item, index) => (
|
||||
{visibleDots.map(({ item, index }) => (
|
||||
<Pressable
|
||||
key={item.id}
|
||||
onPress={() => {
|
||||
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 },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<string, unknown> }) => (
|
||||
<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> }) => (
|
||||
<ImageGallery images={asRecordArray(data.images)} />
|
||||
);
|
||||
const extractCategoryImages = (data: Record<string, unknown>): Record<string, unknown>[] => {
|
||||
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 }) => {
|
||||
const obj = asRecord(value);
|
||||
|
|
|
|||
|
|
@ -7,37 +7,52 @@ import { asString } from "../helpers/value";
|
|||
|
||||
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>[] }) {
|
||||
const relationalMedia = useRelationalContentMedia();
|
||||
|
||||
const visible = images.filter((item) => getImagePath(item).length > 0);
|
||||
|
||||
// Explicit direct images passed via props take priority over relational media
|
||||
if (visible.length > 0) {
|
||||
const fallbackMedia: ContentMediaItem[] = visible.map((item, index) => {
|
||||
const path = getImagePath(item);
|
||||
const name = getImageName(item);
|
||||
return {
|
||||
id: `${path}-${index}`,
|
||||
media_asset_id: `${path}-${index}`,
|
||||
media_role: index === 0 ? "primary" : "gallery",
|
||||
usage_type: "visual_reference",
|
||||
sort_order: index,
|
||||
caption: name || null,
|
||||
alt_text: name || "Module image",
|
||||
mime_type: "image/jpeg",
|
||||
width: null,
|
||||
height: null,
|
||||
url: path,
|
||||
storage_key: null,
|
||||
requires_auth: false,
|
||||
};
|
||||
});
|
||||
|
||||
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" />;
|
||||
}
|
||||
|
||||
const visible = images.filter((item) => asString(item.image_path).trim().length > 0);
|
||||
if (!visible.length) return null;
|
||||
|
||||
const fallbackMedia: ContentMediaItem[] = visible.map((item, index) => {
|
||||
const path = asString(item.image_path).trim();
|
||||
const name = asString(item.image_name).trim();
|
||||
return {
|
||||
id: `${path}-${index}`,
|
||||
media_asset_id: `${path}-${index}`,
|
||||
media_role: index === 0 ? "primary" : "gallery",
|
||||
usage_type: "visual_reference",
|
||||
sort_order: index,
|
||||
caption: name || null,
|
||||
alt_text: name || "Module image",
|
||||
mime_type: "image/jpeg",
|
||||
width: null,
|
||||
height: null,
|
||||
url: path,
|
||||
storage_key: null,
|
||||
requires_auth: false,
|
||||
};
|
||||
});
|
||||
|
||||
return <ContentMediaGallery media={fallbackMedia} title="Visual Reference" />;
|
||||
return null;
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
|
|
|
|||
Loading…
Reference in New Issue