From 0354b798d340fc56b4131656d03fceccdbd40bc6 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 2 Jun 2025 10:23:35 -0700 Subject: [PATCH] Fine-tuning slideshow --- src/lib/components/DynamicPostContent.svelte | 75 ++-- src/lib/components/ImagePost.svelte | 191 +---------- src/lib/components/Slideshow.svelte | 319 ++++++++++++++++++ src/lib/components/UniverseAlbumCard.svelte | 63 ++-- .../api/posts/by-slug/[slug]/+server.ts | 13 +- src/routes/api/universe/+server.ts | 10 +- 6 files changed, 419 insertions(+), 252 deletions(-) create mode 100644 src/lib/components/Slideshow.svelte diff --git a/src/lib/components/DynamicPostContent.svelte b/src/lib/components/DynamicPostContent.svelte index dcefdfa..7c3afc7 100644 --- a/src/lib/components/DynamicPostContent.svelte +++ b/src/lib/components/DynamicPostContent.svelte @@ -1,5 +1,6 @@ -{#if images.length === 1} - - - - -{:else if images.length > 1} - -
- - - -
- {#each Array(totalSlots) as _, index} - {#if index < images.length} - - {:else} - - {/if} - {/each} -
-
-{/if} + - - - diff --git a/src/lib/components/Slideshow.svelte b/src/lib/components/Slideshow.svelte new file mode 100644 index 0000000..be58c89 --- /dev/null +++ b/src/lib/components/Slideshow.svelte @@ -0,0 +1,319 @@ + + +{#if items.length === 1} + + +
openLightbox()}> + {items[0].alt + {#if items[0].caption} +
{items[0].caption}
+ {/if} +
+
+{:else if items.length > 1} + +
+ +
openLightbox()}> + {items[selectedIndex].alt + {#if items[selectedIndex].caption} +
{items[selectedIndex].caption}
+ {/if} +
+
+ + {#if showThumbnails} +
+ {#each Array(totalSlots) as _, index} + {#if index < displayItems.length} + + {:else if index === displayItems.length && showMoreThumbnail} + + {#if items[displayItems.length]} + View all photos + {:else if items[items.length - 1]} + View all photos + {/if} +
+ +{remainingCount} +
+
+ {:else} + + {/if} + {/each} +
+ {/if} +
+{/if} + + + + \ No newline at end of file diff --git a/src/lib/components/UniverseAlbumCard.svelte b/src/lib/components/UniverseAlbumCard.svelte index fdfbc0b..ff411a6 100644 --- a/src/lib/components/UniverseAlbumCard.svelte +++ b/src/lib/components/UniverseAlbumCard.svelte @@ -1,5 +1,6 @@
@@ -23,16 +43,17 @@ - {#if album.coverPhoto} -
- {album.coverPhoto.caption 0} +
+ 1} + maxThumbnails={6} + totalCount={album.photosCount} + showMoreLink="/photos/{album.slug}" /> -
- {album.photosCount || 0} photo{(album.photosCount || 0) !== 1 ? 's' : ''} -
{/if} @@ -108,32 +129,10 @@ font-weight: 400; } - .album-cover { + .album-slideshow { position: relative; width: 100%; - height: 200px; - border-radius: $unit; - overflow: hidden; margin-bottom: $unit-3x; - background: $grey-95; - - img { - width: 100%; - height: 100%; - object-fit: cover; - } - - .photo-count-overlay { - position: absolute; - bottom: $unit; - right: $unit; - background: rgba(0, 0, 0, 0.8); - color: white; - padding: $unit-half $unit-2x; - border-radius: 50px; - font-size: 0.75rem; - font-weight: 500; - } } .album-info { diff --git a/src/routes/api/posts/by-slug/[slug]/+server.ts b/src/routes/api/posts/by-slug/[slug]/+server.ts index bf32b65..738cf44 100644 --- a/src/routes/api/posts/by-slug/[slug]/+server.ts +++ b/src/routes/api/posts/by-slug/[slug]/+server.ts @@ -20,7 +20,18 @@ export const GET: RequestHandler = async (event) => { id: true, slug: true, title: true, - description: true + description: true, + photos: { + orderBy: { displayOrder: 'asc' }, + select: { + id: true, + url: true, + thumbnailUrl: true, + caption: true, + width: true, + height: true + } + } } }, photo: { diff --git a/src/routes/api/universe/+server.ts b/src/routes/api/universe/+server.ts index f652fd4..85edc61 100644 --- a/src/routes/api/universe/+server.ts +++ b/src/routes/api/universe/+server.ts @@ -25,6 +25,7 @@ export interface UniverseItem { date?: string photosCount?: number coverPhoto?: any + photos?: any[] } // GET /api/universe - Get mixed feed of published posts and albums @@ -74,13 +75,15 @@ export const GET: RequestHandler = async (event) => { select: { photos: true } }, photos: { - take: 1, + take: 6, // Fetch enough for 5 thumbnails + 1 background orderBy: { displayOrder: 'asc' }, select: { id: true, url: true, thumbnailUrl: true, - caption: true + caption: true, + width: true, + height: true } } }, @@ -114,7 +117,8 @@ export const GET: RequestHandler = async (event) => { location: album.location || undefined, date: album.date?.toISOString(), photosCount: album._count.photos, - coverPhoto: album.photos[0] || null, + coverPhoto: album.photos[0] || null, // Keep for backward compatibility + photos: album.photos, // Add all photos for slideshow publishedAt: album.createdAt.toISOString(), // Albums use createdAt as publishedAt createdAt: album.createdAt.toISOString() }))