mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 14:29:36 +02:00
feat: add primary image functionality to AdventureImage model and update related components
This commit is contained in:
parent
991efa8d08
commit
c6fa603a93
8 changed files with 112 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue