feat: add primary image functionality to AdventureImage model and update related components
This commit is contained in:
@@ -9,7 +9,11 @@
|
||||
let image_url: string | null = null;
|
||||
|
||||
$: adventure_images = adventures.flatMap((adventure) =>
|
||||
adventure.images.map((image) => ({ image: image.image, adventure: adventure }))
|
||||
adventure.images.map((image) => ({
|
||||
image: image.image,
|
||||
adventure: adventure,
|
||||
is_primary: image.is_primary
|
||||
}))
|
||||
);
|
||||
|
||||
$: {
|
||||
@@ -18,6 +22,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
// sort so that any image in adventure_images .is_primary is first
|
||||
adventure_images.sort((a, b) => {
|
||||
if (a.is_primary && !b.is_primary) {
|
||||
return -1;
|
||||
} else if (!a.is_primary && b.is_primary) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function changeSlide(direction: string) {
|
||||
if (direction === 'next' && currentSlide < adventure_images.length - 1) {
|
||||
currentSlide = currentSlide + 1;
|
||||
|
||||
Reference in New Issue
Block a user