Compare commits
No commits in common. "eee01a5211cd52e1a892757563bcda35f0edf50a" and "e24e235d187d3ef1d7428b2312ccadf3f89a37f7" have entirely different histories.
eee01a5211
...
e24e235d18
|
|
@ -141,21 +141,6 @@ 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>) => {
|
||||||
|
|
@ -184,12 +169,6 @@ 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
|
||||||
|
|
@ -213,16 +192,12 @@ export function ContentMediaGallery({ media, title = "Visual Reference" }: Conte
|
||||||
|
|
||||||
{items.length > 1 ? (
|
{items.length > 1 ? (
|
||||||
<View style={styles.dots} accessibilityElementsHidden>
|
<View style={styles.dots} accessibilityElementsHidden>
|
||||||
{visibleDots.map(({ item, index }) => (
|
{items.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}
|
||||||
>
|
>
|
||||||
|
|
@ -279,12 +254,7 @@ 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: {
|
dots: { flexDirection: "row", flexWrap: "wrap", justifyContent: "center", gap: 7 },
|
||||||
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,8 +8,6 @@ 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>
|
||||||
|
|
@ -25,36 +23,9 @@ export const DescriptionList = ({ data }: { data: Record<string, unknown> }) =>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractCategoryImages = (data: Record<string, unknown>): Record<string, unknown>[] => {
|
export const Images = ({ data }: { data: Record<string, unknown> }) => (
|
||||||
const images = asRecordArray(data.images);
|
<ImageGallery 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);
|
||||||
|
|
|
||||||
|
|
@ -7,52 +7,37 @@ 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();
|
||||||
|
|
||||||
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) {
|
if (relationalMedia.length > 0) {
|
||||||
return <ContentMediaGallery media={relationalMedia} title="Visual Reference" />;
|
return <ContentMediaGallery media={relationalMedia} title="Visual Reference" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
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" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue