From 5370ae020d895891c79c5d791d2dd531a605ceaf Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 26 Jun 2025 08:13:30 -0400 Subject: [PATCH] refactor: consolidate photo grid components into unified PhotoGrid - Create single PhotoGrid component with columns (1,2,3,auto) and masonry options - Remove 5 duplicate grid components - Update HorizontalScrollPhotoGrid to HorizontalPhotoScroll with Photo type - Add interactive test page for PhotoGrid - Update all pages to use new unified component - Use svelte-bricks for proper masonry layout - Single column always uses natural aspect ratios - Square thumbnails (object-fit: cover) for multi-column non-masonry layouts Co-Authored-By: Claude --- ...id.svelte => HorizontalPhotoScroll.svelte} | 42 ++- src/lib/components/MasonryPhotoGrid.svelte | 72 +---- src/lib/components/PhotoGrid.new.svelte | 246 -------------- src/lib/components/PhotoGrid.svelte | 304 ++++++++++++------ .../SingleColumnPhotoGrid.new.svelte | 13 - .../components/SingleColumnPhotoGrid.svelte | 64 +--- .../ThreeColumnPhotoGrid.new.svelte | 13 - .../components/ThreeColumnPhotoGrid.svelte | 282 +--------------- .../components/TwoColumnPhotoGrid.new.svelte | 13 - src/lib/components/TwoColumnPhotoGrid.svelte | 53 +-- src/routes/albums/[slug]/+page.svelte | 4 +- src/routes/photos/+page.svelte | 40 ++- src/routes/photos/+page.ts | 4 +- src/routes/test-grids/+page.svelte | 233 ++++++++++++++ 14 files changed, 512 insertions(+), 871 deletions(-) rename src/lib/components/{HorizontalScrollPhotoGrid.svelte => HorizontalPhotoScroll.svelte} (51%) delete mode 100644 src/lib/components/PhotoGrid.new.svelte delete mode 100644 src/lib/components/SingleColumnPhotoGrid.new.svelte delete mode 100644 src/lib/components/ThreeColumnPhotoGrid.new.svelte delete mode 100644 src/lib/components/TwoColumnPhotoGrid.new.svelte create mode 100644 src/routes/test-grids/+page.svelte diff --git a/src/lib/components/HorizontalScrollPhotoGrid.svelte b/src/lib/components/HorizontalPhotoScroll.svelte similarity index 51% rename from src/lib/components/HorizontalScrollPhotoGrid.svelte rename to src/lib/components/HorizontalPhotoScroll.svelte index a5468a9..f91fcbb 100644 --- a/src/lib/components/HorizontalScrollPhotoGrid.svelte +++ b/src/lib/components/HorizontalPhotoScroll.svelte @@ -1,32 +1,26 @@
- {#each photoItems as item} - {#if isAlbum(item)} - - {item.title} -

{item.title}

-
- {:else} - {@const mediaId = item.id.replace(/^(media|photo)-/, '')} - - {item.alt} - {#if item.caption} -

{item.caption}

- {/if} -
- {/if} + {#each photos as photo} + {@const mediaId = photo.id.replace(/^(media|photo)-/, '')} + + {photo.alt} + {#if showCaptions && photo.caption} +

{photo.caption}

+ {/if} +
{/each}
diff --git a/src/lib/components/MasonryPhotoGrid.svelte b/src/lib/components/MasonryPhotoGrid.svelte index a6d72c3..ce9a29f 100644 --- a/src/lib/components/MasonryPhotoGrid.svelte +++ b/src/lib/components/MasonryPhotoGrid.svelte @@ -1,69 +1,13 @@ - - -
- - {#snippet children({ item })} - - {/snippet} - -
- - + \ No newline at end of file diff --git a/src/lib/components/PhotoGrid.new.svelte b/src/lib/components/PhotoGrid.new.svelte deleted file mode 100644 index 24c801a..0000000 --- a/src/lib/components/PhotoGrid.new.svelte +++ /dev/null @@ -1,246 +0,0 @@ - - -
- {#if columns === 1 || columns === 2} - - {#each columnItems as columnPhotos, colIndex} -
- {#each columnPhotos as item} -
- - {#if showCaptions && !('photos' in item)} -

{item.caption || ''}

- {/if} -
- {/each} -
- {/each} - {:else if columns === 3} - -
- {#each processedItems() as { item, span, columnStart }} -
1} - style={columnStart ? `grid-column-start: ${columnStart};` : ''} - style:grid-column-end={span > 1 ? `span ${span}` : ''} - > - - {#if showCaptions && !('photos' in item)} -

{item.caption || ''}

- {/if} -
- {/each} -
- {:else} - -
- {#each photoItems as item} -
- - {#if showCaptions && !('photos' in item)} -

{item.caption || ''}

- {/if} -
- {/each} -
- {/if} -
- - \ No newline at end of file diff --git a/src/lib/components/PhotoGrid.svelte b/src/lib/components/PhotoGrid.svelte index da01c6a..7d6452e 100644 --- a/src/lib/components/PhotoGrid.svelte +++ b/src/lib/components/PhotoGrid.svelte @@ -1,122 +1,236 @@ -
- {#each photos as photo} -
- {#if onPhotoClick} - - {:else} - - {/if} + + +
+ {#if masonry && masonryConfig()} + {@const config = masonryConfig()} + + + {#snippet children({ item })} +
+ + {#if showCaptions} +

{item.caption || ''}

+ {/if} +
+ {/snippet} +
+ {:else if (columns === 1 || columns === 2 || columns === 3) && !masonry} + + {#each columnPhotos as column, colIndex} +
+ {#each column as photo} +
+ + {#if showCaptions} +

{photo.caption || ''}

+ {/if} +
+ {/each} +
+ {/each} + {:else} + +
+ {#each photos as photo} +
+ + {#if showCaptions} +

{photo.caption || ''}

+ {/if} +
+ {/each}
- {/each} + {/if}
+ \ No newline at end of file diff --git a/src/lib/components/SingleColumnPhotoGrid.new.svelte b/src/lib/components/SingleColumnPhotoGrid.new.svelte deleted file mode 100644 index 8dde6b1..0000000 --- a/src/lib/components/SingleColumnPhotoGrid.new.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - - \ No newline at end of file diff --git a/src/lib/components/SingleColumnPhotoGrid.svelte b/src/lib/components/SingleColumnPhotoGrid.svelte index 803126f..f06ba47 100644 --- a/src/lib/components/SingleColumnPhotoGrid.svelte +++ b/src/lib/components/SingleColumnPhotoGrid.svelte @@ -1,60 +1,12 @@ -
- {#each photoItems as item} -
- - {#if !isAlbum(item) && item.caption} -
-

{item.caption}

-
- {/if} -
- {/each} -
- - + \ No newline at end of file diff --git a/src/lib/components/ThreeColumnPhotoGrid.new.svelte b/src/lib/components/ThreeColumnPhotoGrid.new.svelte deleted file mode 100644 index cf4608c..0000000 --- a/src/lib/components/ThreeColumnPhotoGrid.new.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - - \ No newline at end of file diff --git a/src/lib/components/ThreeColumnPhotoGrid.svelte b/src/lib/components/ThreeColumnPhotoGrid.svelte index 1f804fb..ad2df82 100644 --- a/src/lib/components/ThreeColumnPhotoGrid.svelte +++ b/src/lib/components/ThreeColumnPhotoGrid.svelte @@ -1,282 +1,12 @@ -
- {#each gridItems as { item, spanFull }} - - {/each} -
- - + \ No newline at end of file diff --git a/src/lib/components/TwoColumnPhotoGrid.new.svelte b/src/lib/components/TwoColumnPhotoGrid.new.svelte deleted file mode 100644 index fe027bb..0000000 --- a/src/lib/components/TwoColumnPhotoGrid.new.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - - \ No newline at end of file diff --git a/src/lib/components/TwoColumnPhotoGrid.svelte b/src/lib/components/TwoColumnPhotoGrid.svelte index 4f25e38..5be9155 100644 --- a/src/lib/components/TwoColumnPhotoGrid.svelte +++ b/src/lib/components/TwoColumnPhotoGrid.svelte @@ -1,51 +1,12 @@ -
-
- {#each column1 as item} - - {/each} -
-
- {#each column2 as item} - - {/each} -
-
- - + \ No newline at end of file diff --git a/src/routes/albums/[slug]/+page.svelte b/src/routes/albums/[slug]/+page.svelte index adf2ee8..9171dbd 100644 --- a/src/routes/albums/[slug]/+page.svelte +++ b/src/routes/albums/[slug]/+page.svelte @@ -1,6 +1,6 @@ + +
+

PhotoGrid Component Test

+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ {``} +
+ +
+ +
+
+ + \ No newline at end of file