feat: redesign photo overview (masonry + lightbox) and fix hoch/quer search

The album search could not distinguish portrait from landscape: the format
filter ran client-side over a single 60-item page and relied on exifInfo that
Immich never returned (no withExif flag), so the orientation guard fell
through and every photo matched every filter. Pagination links also dropped
format/jahr on the next page.

- immich/client: send withExif: true on /search/metadata so
  exifImageWidth/Height are populated for orientation filtering and masonry
  aspect ratios.
- albums/filter (new): filter + paginate across the full fetched set so total,
  page slice and has-more-pages stay consistent with active filters; both the
  album detail and the cross-album search pages use it.
- albums/photo-gallery (new client component): masonry grid with native
  EXIF aspect ratios (object-fit: cover, no more 3:2 letterboxing), hover
  overlay with filename/date + merken/lizenzieren/vergrößern, and a
  full-screen lightbox with keyboard nav (Esc/arrow keys).
- catalog-content: drop the old PhotoContactSheet; keep AlbumContactSheet and
  thread format/jahr through PhotoPagination links.
- Album detail search form restyled to the editorial design system (sharp ink
  borders) instead of the shadcn rounded card.
- Tests: filter.test.ts covers the orientation/year/pagination logic;
  catalog-content.test.tsx updated to the gallery + lightbox structure;
  immich client test expects withExif: true.

Skipped: global search form still uses shadcn styling (visually inconsistent
but functionally fixed); albums > 1000 photos lose tail items (noted with a
ponytail ceiling comment).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-11 13:36:46 +02:00
1 parent b81cd7c3e2
commit a3ec068cac
11 files changed
+949 -267

No files matched your search

+386 -28
View File
@@ -569,40 +569,25 @@ a {
text-underline-offset: 0.2em; text-underline-offset: 0.2em;
} }
.album-contact-sheet, .album-contact-sheet {
.photo-contact-sheet {
display: grid; display: grid;
gap: clamp(1.25rem, 2.25vw, 2.5rem); gap: clamp(1.25rem, 2.25vw, 2.5rem);
padding: 0; padding: 0;
list-style: none; list-style: none;
}
.album-contact-sheet {
grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
} }
.photo-contact-sheet {
grid-template-columns: repeat(auto-fill, minmax(min(100%, 13.5rem), 1fr));
}
.contact-sheet-link { .contact-sheet-link {
display: block; display: block;
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
} }
.album-contact-frame, .album-contact-frame {
.photo-contact-frame {
margin: 0; margin: 0;
background: var(--contact-sheet); background: var(--contact-sheet);
}
.album-contact-frame {
border: 1px solid var(--ink); border: 1px solid var(--ink);
} overflow: hidden;
.photo-contact-frame {
border-top: 1px solid var(--ink);
} }
.contact-sheet-image, .contact-sheet-image,
@@ -615,10 +600,6 @@ a {
transition: transform 150ms ease-out; transition: transform 150ms ease-out;
} }
.photo-contact-frame .contact-sheet-image {
aspect-ratio: 3 / 2;
}
.missing-contact-image { .missing-contact-image {
display: grid; display: grid;
place-items: center; place-items: center;
@@ -633,11 +614,6 @@ a {
transform: scale(1.015); transform: scale(1.015);
} }
.album-contact-frame,
.photo-contact-frame {
overflow: hidden;
}
.contact-strip { .contact-strip {
display: flex; display: flex;
align-items: baseline; align-items: baseline;
@@ -662,6 +638,191 @@ a {
white-space: nowrap; white-space: nowrap;
} }
/* --- Photo overview: masonry grid + hover overlay + lightbox --------------
Replaces the old contact-sheet (forced 3:2 tiles, object-fit: contain,
permanent monospace caption strips). Each photo keeps its native aspect
ratio via an inline `aspect-ratio` set from EXIF dimensions; the grid uses
CSS columns for a dense masonry layout. Captions and actions appear on
hover/focus, and a full-screen lightbox opens on click. */
.photo-gallery {
columns: 4 17rem;
column-gap: clamp(0.75rem, 1.5vw, 1.25rem);
padding: 0;
list-style: none;
}
@media (max-width: 64rem) {
.photo-gallery { columns: 3 14rem; }
}
@media (max-width: 48rem) {
.photo-gallery { columns: 2 9rem; }
}
.photo-tile {
break-inside: avoid;
margin: 0 0 clamp(0.75rem, 1.5vw, 1.25rem);
}
.photo-tile-frame {
position: relative;
margin: 0;
overflow: hidden;
background: var(--contact-sheet);
}
.photo-tile-trigger {
display: block;
width: 100%;
margin: 0;
padding: 0;
border: 0;
background: var(--contact-sheet);
cursor: zoom-in;
line-height: 0;
}
.photo-tile-image {
display: block;
width: 100%;
height: auto;
min-height: 6rem;
object-fit: cover;
background: var(--contact-sheet);
transition: transform 200ms ease-out;
}
.photo-tile-trigger:hover .photo-tile-image,
.photo-tile-trigger:focus-visible .photo-tile-image {
transform: scale(1.02);
}
.photo-tile-overlay {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
justify-content: flex-end;
gap: 0.5rem;
padding: 0.75rem;
background: linear-gradient(
to top,
rgb(0 0 0 / 78%) 0%,
rgb(0 0 0 / 38%) 40%,
rgb(0 0 0 / 0%) 70%
);
opacity: 0;
transition: opacity 160ms ease-out;
pointer-events: none; /* let clicks reach the image; buttons re-enable below */
}
.photo-tile-frame:hover .photo-tile-overlay,
.photo-tile-frame:focus-within .photo-tile-overlay {
opacity: 1;
}
.photo-tile-caption {
display: flex;
flex-direction: column;
gap: 0.125rem;
color: #fff;
}
.photo-tile-name {
font-size: 0.8rem;
font-weight: 600;
letter-spacing: 0.01em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.photo-tile-album {
font-size: 0.65rem;
letter-spacing: 0.06em;
text-transform: uppercase;
opacity: 0.8;
}
.photo-tile-date {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
font-size: 0.625rem;
letter-spacing: 0.03em;
opacity: 0.85;
}
.photo-tile-actions {
display: flex;
align-items: center;
gap: 0.5rem;
pointer-events: auto;
}
/* Compact the full-width `.download-trigger` so it fits in the overlay row. */
.photo-tile-actions .download-trigger,
.lightbox-actions .download-trigger {
width: auto;
min-height: 2rem;
padding: 0 0.75rem;
border: 1px solid #fff;
border-top: 1px solid #fff;
background: rgb(255 255 255 / 12%);
color: #fff;
backdrop-filter: blur(4px);
}
.photo-tile-actions .download-trigger:hover,
.lightbox-actions .download-trigger:hover {
background: #fff;
color: var(--ink);
}
/* Base icon-button shape for the merken toggle (no base style existed). */
.lightbox-toggle-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2.5rem;
height: 2.5rem;
padding: 0;
border: 1px solid var(--ink);
border-radius: 0;
background: var(--paper);
color: var(--ink);
cursor: pointer;
}
.lightbox-toggle-btn:hover {
background: var(--ink);
color: var(--paper);
}
.lightbox-toggle-btn.in-lightbox {
background: var(--ink);
color: var(--paper);
}
.lightbox-toggle-btn:disabled {
opacity: 0.6;
cursor: progress;
}
/* Recolor the lightbox toggle for dark overlays. */
.photo-tile-actions .lightbox-toggle-btn,
.lightbox-actions .lightbox-toggle-btn {
width: 2rem;
height: 2rem;
color: #fff;
background: rgb(255 255 255 / 12%);
border: 1px solid #fff;
backdrop-filter: blur(4px);
}
.photo-tile-actions .lightbox-toggle-btn:hover,
.lightbox-actions .lightbox-toggle-btn:hover {
background: #fff;
color: var(--ink);
}
.photo-search { .photo-search {
display: grid; display: grid;
gap: 0.55rem; gap: 0.55rem;
@@ -736,6 +897,201 @@ a {
font-weight: 650; font-weight: 650;
} }
/* Album search form — editorial styling (sharp ink borders, paper ground),
aligned with the portal's browsing surface instead of the shadcn rounded
card used elsewhere. */
.album-search-form {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 1rem;
margin: 0 0 1.5rem;
padding: 1rem;
border: 1px solid var(--ink);
background: var(--paper);
}
.album-search-input {
flex: 1 1 20rem;
display: flex;
flex-direction: column;
gap: 0.35rem;
}
.album-search-label {
font-size: 0.65rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--metadata);
}
.album-search-input input[type="search"] {
width: 100%;
min-height: 2.75rem;
padding: 0.5rem 0.75rem;
border: 1px solid var(--ink);
border-radius: 0;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 0.95rem;
}
.album-search-filters {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 1rem;
}
.album-search-select {
display: flex;
flex-direction: column;
gap: 0.35rem;
font-size: 0.65rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--metadata);
}
.album-search-select select {
min-height: 2.75rem;
padding: 0.5rem 0.75rem;
border: 1px solid var(--ink);
border-radius: 0;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 0.9rem;
text-transform: none;
letter-spacing: 0;
cursor: pointer;
}
.album-search-form button[type="submit"] {
min-height: 2.75rem;
padding: 0 1.25rem;
border: 1px solid var(--ink);
border-radius: 0;
background: var(--ink);
color: var(--paper);
font: inherit;
font-size: 0.8125rem;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
}
.album-search-form button[type="submit"]:hover {
background: var(--graphite);
}
/* Full-screen photo lightbox. */
.photo-lightbox {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
grid-template-rows: 1fr auto;
align-items: center;
justify-items: center;
gap: 1rem;
padding: clamp(1rem, 4vw, 3rem);
background: rgb(0 0 0 / 92%);
backdrop-filter: blur(6px);
animation: lightbox-fade-in 160ms ease-out;
}
@keyframes lightbox-fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
.lightbox-figure {
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
max-height: 100%;
}
.lightbox-image {
max-height: 84vh;
max-width: 90vw;
width: auto;
height: auto;
object-fit: contain;
background: rgb(255 255 255 / 4%);
}
.lightbox-caption {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.75rem;
color: #fff;
text-align: center;
}
.lightbox-caption .photo-tile-name {
font-size: 0.9rem;
}
.lightbox-actions {
display: flex;
align-items: center;
gap: 0.75rem;
}
.lightbox-close {
position: absolute;
top: clamp(0.75rem, 2vw, 1.5rem);
right: clamp(0.75rem, 2vw, 1.5rem);
width: 2.5rem;
height: 2.5rem;
border: 1px solid #fff;
border-radius: 0;
background: rgb(255 255 255 / 12%);
color: #fff;
font-size: 1.1rem;
cursor: pointer;
}
.lightbox-close:hover {
background: #fff;
color: var(--ink);
}
.lightbox-nav {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 3rem;
height: 3rem;
border: 1px solid #fff;
border-radius: 0;
background: rgb(255 255 255 / 12%);
color: #fff;
font-size: 1.75rem;
line-height: 1;
cursor: pointer;
}
.lightbox-nav:hover {
background: #fff;
color: var(--ink);
}
.lightbox-prev { left: clamp(0.5rem, 2vw, 1.5rem); }
.lightbox-next { right: clamp(0.5rem, 2vw, 1.5rem); }
@media (max-width: 48rem) {
.lightbox-nav { width: 2.5rem; height: 2.5rem; font-size: 1.4rem; }
}
.editorial-section dl { .editorial-section dl {
display: grid; display: grid;
grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr); grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr);
@@ -796,7 +1152,9 @@ a {
} }
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
.contact-sheet-image { .contact-sheet-image,
.photo-tile-image,
.photo-tile-overlay {
transition: none; transition: none;
} }
} }
+69 -59
View File
@@ -1,14 +1,22 @@
import Link from "next/link"; import Link from "next/link";
import { notFound } from "next/navigation"; import { notFound } from "next/navigation";
import { AlbumCatalogError, albumCatalog, normalizePage } from "@/modules/albums/catalog"; import { AlbumCatalogError, albumCatalog, PHOTO_PAGE_SIZE } from "@/modules/albums/catalog";
import { PhotoContactSheet } from "@/modules/albums/catalog-content"; import { formatCount, PhotoPagination } from "@/modules/albums/catalog-content";
import { filterPhotos, paginatePhotos } from "@/modules/albums/filter";
import { PhotoGallery } from "@/modules/albums/photo-gallery";
import { loadEditorialDownloadOptions } from "@/modules/downloads/stream"; import { loadEditorialDownloadOptions } from "@/modules/downloads/stream";
import { lightboxService } from "@/modules/lightbox/service"; import { lightboxService } from "@/modules/lightbox/service";
import { requireEditorial } from "../../access"; import { requireEditorial } from "../../access";
import { PageHeader } from "@/components/ui/page-header"; import { PageHeader } from "@/components/ui/page-header";
// ponytail: fetch the whole album in one request so hoch/quer and jahr filters
// can be applied across the full set before paginating, instead of over a
// single 60-item page. Ceiling: albums > 1000 photos lose tail items; raise
// here (and the Immich size cap) if a sport album ever exceeds it.
const ALBUM_FETCH_SIZE = 1000;
type AlbumPageProps = Readonly<{ type AlbumPageProps = Readonly<{
params: Promise<{ albumId: string }>; params: Promise<{ albumId: string }>;
searchParams: Promise<{ page?: string | string[]; suche?: string | string[]; format?: string | string[]; jahr?: string | string[] }>; searchParams: Promise<{ page?: string | string[]; suche?: string | string[]; format?: string | string[]; jahr?: string | string[] }>;
@@ -21,7 +29,6 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
requireEditorial(), requireEditorial(),
]); ]);
const query = normalizedQuery(singleValue(rawSearchParams.suche)); const query = normalizedQuery(singleValue(rawSearchParams.suche));
const currentPage = normalizePage(singleValue(rawSearchParams.page));
const format = singleValue(rawSearchParams.format); const format = singleValue(rawSearchParams.format);
const jahr = singleValue(rawSearchParams.jahr); const jahr = singleValue(rawSearchParams.jahr);
const result = await loadAlbumPage({ const result = await loadAlbumPage({
@@ -52,14 +59,23 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
</Link> </Link>
</PageHeader> </PageHeader>
<AlbumSearchForm albumId={result.album.id} query={query} format={format} jahr={jahr} /> <AlbumSearchForm albumId={result.album.id} query={query} format={format} jahr={jahr} />
<PhotoContactSheet <p aria-live="polite" className="result-summary" role="status">
{formatCount(result.page.total, "Foto")} gefunden
</p>
<PhotoGallery
albumId={result.album.id} albumId={result.album.id}
albumName={result.album.albumName} albumName={result.album.albumName}
currentPage={currentPage} items={result.page.items}
downloadOptions={result.downloadOptions} downloadOptions={result.downloadOptions}
lightboxAssetIds={[...result.lightboxAssetIds]}
/>
<PhotoPagination
albumId={result.album.id}
currentPage={result.currentPage}
page={result.page} page={result.page}
query={query} query={query}
lightboxAssetIds={result.lightboxAssetIds} format={format}
jahr={jahr}
/> />
</section> </section>
); );
@@ -70,29 +86,41 @@ function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; qu
const years = Array.from({ length: 10 }, (_, i) => currentYear - i); const years = Array.from({ length: 10 }, (_, i) => currentYear - i);
return ( return (
<form action={`/redaktion/alben/${albumId}`} className="global-search-form flex flex-wrap gap-4 items-center mb-8 bg-gray-50 p-4 rounded-xl border border-gray-200" role="search"> <form
<div className="flex-grow"> action={`/redaktion/alben/${albumId}`}
<input className="album-search-form"
type="search" role="search"
name="suche" aria-label={`Fotos in diesem Album durchsuchen`}
defaultValue={query} >
<div className="album-search-input">
<label className="album-search-label" htmlFor="album-search-suche">Suchbegriff</label>
<input
id="album-search-suche"
type="search"
name="suche"
defaultValue={query}
placeholder="Dieses Album durchsuchen..." placeholder="Dieses Album durchsuchen..."
aria-label="Dieses Album durchsuchen" aria-label="Suchbegriff"
className="w-full"
/> />
</div> </div>
<div className="flex gap-4"> <div className="album-search-filters">
<select name="format" defaultValue={format || ""} className="px-3 py-2 border border-gray-300 rounded-md"> <label className="album-search-select">
<option value="">Alle Formate</option> <span>Format</span>
<option value="quer">Querformat</option> <select name="format" defaultValue={format || ""}>
<option value="hoch">Hochformat</option> <option value="">Alle Formate</option>
</select> <option value="quer">Querformat</option>
<select name="jahr" defaultValue={jahr || ""} className="px-3 py-2 border border-gray-300 rounded-md"> <option value="hoch">Hochformat</option>
<option value="">Alle Jahre</option> </select>
{years.map(y => ( </label>
<option key={y} value={y.toString()}>{y}</option> <label className="album-search-select">
))} <span>Jahr</span>
</select> <select name="jahr" defaultValue={jahr || ""}>
<option value="">Alle Jahre</option>
{years.map((y) => (
<option key={y} value={y.toString()}>{y}</option>
))}
</select>
</label>
<button type="submit">Suchen</button> <button type="submit">Suchen</button>
</div> </div>
</form> </form>
@@ -118,50 +146,32 @@ async function loadAlbumPage({
const albums = await albumCatalog.getVisibleAlbums(editorialId); const albums = await albumCatalog.getVisibleAlbums(editorialId);
const album = albums.find((candidate) => candidate.id === albumId); const album = albums.find((candidate) => candidate.id === albumId);
if (!album) { if (!album) {
return { album: null, page: null, unavailable: false as const }; return { album: null, page: null, currentPage: 1, downloadOptions: undefined, lightboxAssetIds: new Set<string>(), unavailable: false as const };
} }
const results = await albumCatalog.searchVisiblePhotos(editorialId, { const results = await albumCatalog.searchVisiblePhotos(editorialId, {
requestedAlbumId: album.id, requestedAlbumId: album.id,
description: query, description: query,
page, page: 1,
size: ALBUM_FETCH_SIZE,
}); });
// Client-side filtering for format and year // Filter format + jahr across the full album set BEFORE paginating, so the
if (format || jahr) { // total, the page slice, and the has-more-pages signal all reflect the
results.items = results.items.filter(asset => { // active filters. The old code filtered a single 60-item page client-side,
let matches = true; // which silently dropped matching photos and reported the unfiltered total.
const filtered = filterPhotos(results.items, { format, jahr });
if (format) { const { result: resultPage, currentPage } = paginatePhotos(filtered, page, PHOTO_PAGE_SIZE);
const width = asset.exifInfo?.exifImageWidth ?? 0;
const height = asset.exifInfo?.exifImageHeight ?? 0;
if (width > 0 && height > 0) {
const isLandscape = width >= height;
if (format === 'quer' && !isLandscape) matches = false;
if (format === 'hoch' && isLandscape) matches = false;
}
}
if (jahr && matches) {
const dateStr = asset.localDateTime ?? asset.fileCreatedAt;
if (!dateStr || !dateStr.startsWith(jahr)) {
matches = false;
}
}
return matches;
});
}
const downloadOptions = await loadEditorialDownloadOptions( const downloadOptions = await loadEditorialDownloadOptions(
editorialId, editorialId,
results.items.map((asset) => asset.id), resultPage.items.map((asset) => asset.id),
); );
const lightboxItems = await lightboxService.getLightboxItems(editorialId); const lightboxItems = await lightboxService.getLightboxItems(editorialId);
const lightboxAssetIds = new Set(lightboxItems.map(i => i.assetId)); const lightboxAssetIds = new Set(lightboxItems.map((i) => i.assetId));
return { album, page: results, downloadOptions, lightboxAssetIds, unavailable: false as const }; return { album, page: resultPage, currentPage, downloadOptions, lightboxAssetIds, unavailable: false as const };
} catch (error) { } catch (error) {
if (error instanceof AlbumCatalogError && error.code === "IMMICH_UNAVAILABLE") { if (error instanceof AlbumCatalogError && error.code === "IMMICH_UNAVAILABLE") {
return { album: null, page: null, unavailable: true as const }; return { album: null, page: null, currentPage: 1, downloadOptions: undefined, lightboxAssetIds: new Set<string>(), unavailable: true as const };
} }
throw error; throw error;
} }
@@ -192,4 +202,4 @@ function ImmichUnavailable() {
</PageHeader> </PageHeader>
</section> </section>
); );
} }
+38 -43
View File
@@ -1,8 +1,9 @@
import { AlbumCatalogError, albumCatalog } from "@/modules/albums/catalog"; import { AlbumCatalogError, albumCatalog, PHOTO_PAGE_SIZE } from "@/modules/albums/catalog";
import { AlbumContactSheet, PhotoContactSheet } from "@/modules/albums/catalog-content"; import { AlbumContactSheet, formatCount } from "@/modules/albums/catalog-content";
import { filterPhotos, paginatePhotos, type InAppPage } from "@/modules/albums/filter";
import { PhotoGallery } from "@/modules/albums/photo-gallery";
import { loadEditorialDownloadOptions } from "@/modules/downloads/stream"; import { loadEditorialDownloadOptions } from "@/modules/downloads/stream";
import { lightboxService } from "@/modules/lightbox/service"; import { lightboxService } from "@/modules/lightbox/service";
import type { ImmichSearchPage } from "@/modules/immich/types";
import Link from "next/link"; import Link from "next/link";
import { PageHeader } from "@/components/ui/page-header"; import { PageHeader } from "@/components/ui/page-header";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
@@ -10,6 +11,10 @@ import { Button } from "@/components/ui/button";
import { requireEditorial } from "../access"; import { requireEditorial } from "../access";
// ponytail: same ceiling as the album detail page — cross-album search fetches
// up to 1000 matching photos, then filters/paginates in-app.
const SEARCH_FETCH_SIZE = 1000;
export default async function AlbumsPage({ searchParams }: { searchParams: Promise<{ suche?: string | string[]; page?: string | string[]; format?: string | string[]; jahr?: string | string[] }> }) { export default async function AlbumsPage({ searchParams }: { searchParams: Promise<{ suche?: string | string[]; page?: string | string[]; format?: string | string[]; jahr?: string | string[] }> }) {
const principal = await requireEditorial(); const principal = await requireEditorial();
const rawSearchParams = await searchParams; const rawSearchParams = await searchParams;
@@ -20,37 +25,16 @@ export default async function AlbumsPage({ searchParams }: { searchParams: Promi
if (query) { if (query) {
const results = await albumCatalog.searchVisiblePhotos(principal.editorialId, { const results = await albumCatalog.searchVisiblePhotos(principal.editorialId, {
description: query, description: query,
page: singleValue(rawSearchParams.page), page: 1,
size: SEARCH_FETCH_SIZE,
}); });
if (format || jahr) { const filtered = filterPhotos(results.items, { format, jahr });
results.items = results.items.filter(asset => { const { result: page, currentPage } = paginatePhotos(filtered, singleValue(rawSearchParams.page), PHOTO_PAGE_SIZE);
let matches = true;
if (format) {
const width = asset.exifInfo?.exifImageWidth ?? 0;
const height = asset.exifInfo?.exifImageHeight ?? 0;
if (width > 0 && height > 0) {
const isLandscape = width >= height;
if (format === 'quer' && !isLandscape) matches = false;
if (format === 'hoch' && isLandscape) matches = false;
}
}
if (jahr && matches) {
const dateStr = asset.localDateTime ?? asset.fileCreatedAt;
if (!dateStr || !dateStr.startsWith(jahr)) {
matches = false;
}
}
return matches;
});
}
const downloadOptions = await loadEditorialDownloadOptions( const downloadOptions = await loadEditorialDownloadOptions(
principal.editorialId, principal.editorialId,
results.items.map((asset) => asset.id), page.items.map((asset) => asset.id),
); );
const lightboxItems = await lightboxService.getLightboxItems(principal.editorialId); const lightboxItems = await lightboxService.getLightboxItems(principal.editorialId);
const lightboxAssetIds = new Set(lightboxItems.map(i => i.assetId)); const lightboxAssetIds = new Set(lightboxItems.map(i => i.assetId));
@@ -63,15 +47,17 @@ export default async function AlbumsPage({ searchParams }: { searchParams: Promi
titleId="albums-title" titleId="albums-title"
/> />
<GlobalSearchForm query={query} format={format} jahr={jahr} /> <GlobalSearchForm query={query} format={format} jahr={jahr} />
<PhotoContactSheet <p aria-live="polite" className="result-summary" role="status">
{formatCount(page.total, "Foto")} gefunden
</p>
<PhotoGallery
albumName="Alle Alben" albumName="Alle Alben"
items={page.items}
downloadOptions={downloadOptions} downloadOptions={downloadOptions}
page={results} lightboxAssetIds={[...lightboxAssetIds]}
query={query}
showAlbumName showAlbumName
lightboxAssetIds={lightboxAssetIds}
/> />
<GlobalSearchPagination page={results} query={query} /> <GlobalSearchPagination currentPage={currentPage} page={page} query={query} format={format} jahr={jahr} />
</div> </div>
); );
} }
@@ -133,23 +119,32 @@ function GlobalSearchForm({ query, format, jahr }: { query: string; format?: str
); );
} }
function GlobalSearchPagination({ page, query }: { page: ImmichSearchPage; query: string }) { function GlobalSearchPagination({ currentPage, page, query, format, jahr }: { currentPage: number; page: InAppPage; query: string; format?: string; jahr?: string }) {
if (page.previousPage === null && page.nextPage === null) { const hasPrev = currentPage > 1;
const hasNext = page.nextPage !== null;
if (!hasPrev && !hasNext) {
return null; return null;
} }
return ( return (
<nav aria-label="Suchergebnisseiten" className="flex justify-between items-center mt-8 pt-4 border-t border-border text-sm font-medium"> <nav aria-label="Suchergebnisseiten" className="flex justify-between items-center mt-8 pt-4 border-t border-border text-sm font-medium">
{page.previousPage === null ? <div /> : ( {hasPrev ? (
<Link className="text-primary-600 hover:underline" href={`/redaktion/alben?suche=${encodeURIComponent(query)}&page=${page.previousPage}`}>Vorherige Seite</Link> <Link className="text-primary-600 hover:underline" href={globalPageHref(currentPage - 1, query, format, jahr)}>Vorherige Seite</Link>
)} ) : <div />}
{page.nextPage === null ? <div /> : ( {hasNext ? (
<Link className="text-primary-600 hover:underline" href={`/redaktion/alben?suche=${encodeURIComponent(query)}&page=${page.nextPage}`}>Nächste Seite</Link> <Link className="text-primary-600 hover:underline" href={globalPageHref(currentPage + 1, query, format, jahr)}>Nächste Seite</Link>
)} ) : <div />}
</nav> </nav>
); );
} }
function globalPageHref(page: number, query: string, format?: string, jahr?: string): string {
const parameters = new URLSearchParams({ suche: query, page: String(page) });
if (format) parameters.set("format", format);
if (jahr) parameters.set("jahr", jahr);
return `/redaktion/alben?${parameters.toString()}`;
}
function singleValue(value: string | string[] | undefined): string | undefined { function singleValue(value: string | string[] | undefined): string | undefined {
return typeof value === "string" ? value : undefined; return typeof value === "string" ? value : undefined;
} }
+52 -47
View File
@@ -1,9 +1,10 @@
// @vitest-environment jsdom // @vitest-environment jsdom
import { cleanup, render, screen } from "@testing-library/react"; import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, expect, test } from "vitest"; import { afterEach, expect, test } from "vitest";
import { AlbumContactSheet, PhotoContactSheet } from "./catalog-content"; import { AlbumContactSheet } from "./catalog-content";
import { PhotoGallery } from "./photo-gallery";
afterEach(cleanup); afterEach(cleanup);
@@ -30,42 +31,27 @@ test("renders granted albums as labelled contact-sheet links", () => {
); );
}); });
test("renders a labelled photo search and descriptive contact-sheet metadata", () => { const photo = {
render( id: "asset-1",
<PhotoContactSheet type: "IMAGE" as const,
albumName="Heimspiel gegen Nord" originalFileName: "tor-des-sieges.jpg",
page={{ originalMimeType: "image/jpeg",
items: [ localDateTime: "2026-08-08T18:42:00.000Z",
{ fileCreatedAt: null,
id: "asset-1", albums: [{ id: "heimspiel" }],
type: "IMAGE", };
originalFileName: "tor-des-sieges.jpg",
originalMimeType: "image/jpeg",
localDateTime: "2026-08-08T18:42:00.000Z",
fileCreatedAt: null,
albums: [{ id: "heimspiel" }],
},
],
total: 1,
nextPage: null,
previousPage: null,
}}
query="Tor"
/>,
);
expect(screen.getByRole("search", { name: /fotos in heimspiel gegen nord durchsuchen/i })).not.toBeNull(); test("renders the gallery list labelled by album name", () => {
expect((screen.getByRole("searchbox", { name: /suchbegriff/i }) as HTMLInputElement).value).toBe("Tor"); render(<PhotoGallery albumName="Heimspiel gegen Nord" items={[photo]} />);
expect(screen.getByRole("list", { name: /fotos aus heimspiel gegen nord/i })).not.toBeNull();
expect(screen.getByAltText("tor-des-sieges.jpg").getAttribute("src")).toBe( expect(screen.getByAltText("tor-des-sieges.jpg").getAttribute("src")).toBe(
"/api/assets/asset-1/thumbnail", "/api/assets/asset-1/thumbnail",
); );
expect(screen.getByText("tor-des-sieges.jpg")).not.toBeNull();
expect(screen.getByText(/1 foto gefunden/i)).not.toBeNull();
}); });
test("renders the server-scoped download choices for a catalog photo", () => { test("renders the server-scoped download choices for a catalog photo", () => {
render( render(
<PhotoContactSheet <PhotoGallery
albumId="33333333-3333-4333-8333-333333333333" albumId="33333333-3333-4333-8333-333333333333"
albumName="Heimspiel gegen Nord" albumName="Heimspiel gegen Nord"
downloadOptions={{ downloadOptions={{
@@ -80,25 +66,44 @@ test("renders the server-scoped download choices for a catalog photo", () => {
], ],
}, },
}} }}
page={{ items={[
items: [ {
{ id: "22222222-2222-4222-8222-222222222222",
id: "22222222-2222-4222-8222-222222222222", type: "IMAGE",
type: "IMAGE", originalFileName: "tor.jpg",
originalFileName: "tor.jpg", originalMimeType: "image/jpeg",
originalMimeType: "image/jpeg", localDateTime: null,
localDateTime: null, fileCreatedAt: null,
fileCreatedAt: null, albums: [{ id: "33333333-3333-4333-8333-333333333333" }],
albums: [{ id: "33333333-3333-4333-8333-333333333333" }], },
}, ]}
],
total: 1,
nextPage: null,
previousPage: null,
}}
query=""
/>, />,
); );
expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull(); expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull();
}); });
test("opens a full-screen lightbox when a photo tile is clicked", () => {
render(
<PhotoGallery
albumName="Heimspiel gegen Nord"
items={[
{ ...photo, id: "a", originalFileName: "first.jpg" },
{ ...photo, id: "b", originalFileName: "second.jpg" },
]}
/>,
);
// No lightbox before clicking.
expect(screen.queryByRole("dialog")).toBeNull();
fireEvent.click(screen.getByRole("button", { name: /first\.jpg vergrößern/i }));
const dialog = screen.getByRole("dialog");
expect(dialog.getAttribute("aria-modal")).toBe("true");
// Lightbox image + tile image both carry the alt, so the dialog contains one.
expect(dialog.querySelector(".lightbox-image")?.getAttribute("alt")).toBe("first.jpg");
expect(screen.getByRole("button", { name: /nächstes bild/i })).not.toBeNull();
// No previous on the first photo.
expect(screen.queryByRole("button", { name: /vorheriges bild/i })).toBeNull();
});
+33 -89
View File
@@ -2,9 +2,6 @@
import Link from "next/link"; import Link from "next/link";
import { UsageDialog } from "@/components/download/usage-dialog";
import { LightboxToggleButton } from "@/app/redaktion/leuchtkasten/LightboxToggleButton";
import type { EditorialDownloadOptions } from "@/modules/downloads/stream";
import type { ImmichSearchPage } from "@/modules/immich/types"; import type { ImmichSearchPage } from "@/modules/immich/types";
import type { VisibleAlbum } from "./catalog"; import type { VisibleAlbum } from "./catalog";
@@ -41,89 +38,24 @@ export function AlbumContactSheet({ albums }: Readonly<{ albums: VisibleAlbum[]
); );
} }
export function PhotoContactSheet({ // Server-rendered pagination. Links thread every active filter (suche,
albumId, // format, jahr) so flipping pages does not silently drop them — that was the
albumName, // old bug: pageHref only carried `suche`, so "Nächste Seite" reset format/jahr.
currentPage = 1, export function PhotoPagination({
downloadOptions,
page,
query,
showAlbumName = false,
lightboxAssetIds,
}: Readonly<{
albumId?: string;
albumName: string;
currentPage?: number;
downloadOptions?: EditorialDownloadOptions;
page: ImmichSearchPage;
query: string;
showAlbumName?: boolean;
lightboxAssetIds?: Set<string>;
}>) {
return (
<>
<p aria-live="polite" className="result-summary" role="status">
{formatCount(page.total, "Foto")} gefunden
</p>
{page.items.length === 0 ? (
<p className="catalog-empty">Keine Fotos passen zu dieser Suche. Ändern Sie den Suchbegriff oder wählen Sie ein anderes Album.</p>
) : (
<ul className="photo-contact-sheet" aria-label={`Fotos aus ${albumName}`}>
{page.items.map((asset) => (
<li key={asset.id}>
<figure className="photo-contact-frame relative group">
<img
alt={asset.originalFileName}
className="contact-sheet-image"
height="600"
src={thumbnailUrl(asset.id)}
width="900"
/>
{lightboxAssetIds && (
<div className="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity">
<LightboxToggleButton assetId={asset.id} initialInLightbox={lightboxAssetIds.has(asset.id)} />
</div>
)}
<figcaption className="contact-strip">
<span className="contact-strip-name">{asset.originalFileName}</span>
{showAlbumName && (asset as any).albums && (asset as any).albums.length > 0 && (
<span className="contact-strip-album">{(asset as any).albums[0].albumName}</span>
)}
<span>{formatDate(asset.localDateTime ?? asset.fileCreatedAt)}</span>
</figcaption>
{(albumId ?? asset.albums?.[0]?.id) && downloadOptions ? (
<UsageDialog
albumId={albumId ?? (asset.albums?.[0]?.id as string)}
assetId={asset.id}
filename={asset.originalFileName}
newUsagePriceCents={downloadOptions.priceCents}
priorUsages={downloadOptions.priorUsagesByAsset[asset.id] ?? []}
/>
) : null}
</figure>
</li>
))}
</ul>
)}
{albumId ? (
<PhotoPagination albumId={albumId} currentPage={currentPage} page={page} query={query} />
) : null}
</>
);
}
// Immich v3 returns `nextPage` as an opaque cursor (or null), not the next
// page number, so links are derived from the current page number instead:
// previous = currentPage - 1, next = currentPage + 1. `nextPage !== null`
// is the authoritative has-more-pages signal.
function PhotoPagination({
albumId, albumId,
currentPage, currentPage,
page, page,
query, query,
}: Readonly<{ albumId: string; currentPage: number; page: ImmichSearchPage; query: string }>) { format,
jahr,
}: Readonly<{
albumId: string;
currentPage: number;
page: ImmichSearchPage;
query: string;
format?: string;
jahr?: string;
}>) {
const hasPrev = currentPage > 1; const hasPrev = currentPage > 1;
const hasNext = page.nextPage !== null; const hasNext = page.nextPage !== null;
if (!hasPrev && !hasNext) { if (!hasPrev && !hasNext) {
@@ -132,29 +64,41 @@ function PhotoPagination({
return ( return (
<nav aria-label="Suchergebnisseiten" className="photo-pagination"> <nav aria-label="Suchergebnisseiten" className="photo-pagination">
{hasPrev ? <Link href={pageHref(albumId, currentPage - 1, query)}>Vorherige Seite</Link> : null} {hasPrev ? <Link href={pageHref(albumId, currentPage - 1, query, format, jahr)}>Vorherige Seite</Link> : null}
{hasNext ? <Link href={pageHref(albumId, currentPage + 1, query)}>Nächste Seite</Link> : null} {hasNext ? <Link href={pageHref(albumId, currentPage + 1, query, format, jahr)}>Nächste Seite</Link> : null}
</nav> </nav>
); );
} }
function thumbnailUrl(assetId: string): string { export function thumbnailUrl(assetId: string): string {
return `/api/assets/${encodeURIComponent(assetId)}/thumbnail`; return `/api/assets/${encodeURIComponent(assetId)}/thumbnail`;
} }
function pageHref(albumId: string, page: number, query: string): string { export function pageHref(
albumId: string,
page: number,
query: string,
format?: string,
jahr?: string,
): string {
const parameters = new URLSearchParams({ page: String(page) }); const parameters = new URLSearchParams({ page: String(page) });
if (query) { if (query) {
parameters.set("suche", query); parameters.set("suche", query);
} }
if (format) {
parameters.set("format", format);
}
if (jahr) {
parameters.set("jahr", jahr);
}
return `/redaktion/alben/${encodeURIComponent(albumId)}?${parameters.toString()}`; return `/redaktion/alben/${encodeURIComponent(albumId)}?${parameters.toString()}`;
} }
function formatCount(count: number, noun: string): string { export function formatCount(count: number, noun: string): string {
return `${count} ${noun}${count === 1 ? "" : "s"}`; return `${count} ${noun}${count === 1 ? "" : "s"}`;
} }
function formatDate(value: string | null): string { export function formatDate(value: string | null): string {
if (!value) { if (!value) {
return "Ohne Zeitangabe"; return "Ohne Zeitangabe";
} }
@@ -164,4 +108,4 @@ function formatDate(value: string | null): string {
return "Ohne Zeitangabe"; return "Ohne Zeitangabe";
} }
return new Intl.DateTimeFormat("de-DE", { dateStyle: "medium" }).format(date); return new Intl.DateTimeFormat("de-DE", { dateStyle: "medium" }).format(date);
} }
+2 -1
View File
@@ -14,6 +14,7 @@ export type SearchVisiblePhotosInput = {
requestedAlbumId?: string; requestedAlbumId?: string;
description?: unknown; description?: unknown;
page?: unknown; page?: unknown;
size?: number;
}; };
export type AlbumCatalogDependencies = { export type AlbumCatalogDependencies = {
@@ -59,7 +60,7 @@ export function createAlbumCatalog({ grants, immich }: AlbumCatalogDependencies)
...(description === undefined ? {} : { description }), ...(description === undefined ? {} : { description }),
type: "IMAGE", type: "IMAGE",
page: normalizePage(input.page), page: normalizePage(input.page),
size: PHOTO_PAGE_SIZE, size: input.size ?? PHOTO_PAGE_SIZE,
}); });
} catch { } catch {
throw new AlbumCatalogError("IMMICH_UNAVAILABLE"); throw new AlbumCatalogError("IMMICH_UNAVAILABLE");
+88
View File
@@ -0,0 +1,88 @@
import { expect, test } from "vitest";
import { filterPhotos, matchesOrientation, matchesYear, paginatePhotos } from "./filter";
import type { ImmichAsset } from "@/modules/immich/types";
function photo(overrides: Partial<ImmichAsset> & { id: string }): ImmichAsset {
return {
id: overrides.id,
type: "IMAGE",
originalFileName: overrides.originalFileName ?? `${overrides.id}.jpg`,
originalMimeType: "image/jpeg",
localDateTime: overrides.localDateTime ?? null,
fileCreatedAt: overrides.fileCreatedAt ?? null,
albums: overrides.albums ?? [],
exifInfo: overrides.exifInfo ?? null,
};
}
test("matchesOrientation distinguishes landscape from portrait via EXIF dimensions", () => {
const landscape = photo({ id: "l", exifInfo: { exifImageWidth: 1600, exifImageHeight: 900 } });
const portrait = photo({ id: "p", exifInfo: { exifImageWidth: 900, exifImageHeight: 1600 } });
const square = photo({ id: "s", exifInfo: { exifImageWidth: 1000, exifImageHeight: 1000 } });
expect(matchesOrientation(landscape, "quer")).toBe(true);
expect(matchesOrientation(landscape, "hoch")).toBe(false);
expect(matchesOrientation(portrait, "quer")).toBe(false);
expect(matchesOrientation(portrait, "hoch")).toBe(true);
// width >= height counts as landscape, so square is "quer".
expect(matchesOrientation(square, "quer")).toBe(true);
});
test("matchesOrientation excludes assets with unknown dimensions instead of matching either format", () => {
const unknown = photo({ id: "u", exifInfo: null });
expect(matchesOrientation(unknown, "quer")).toBe(false);
expect(matchesOrientation(unknown, "hoch")).toBe(false);
});
test("matchesYear compares against localDateTime then fileCreatedAt", () => {
expect(matchesYear(photo({ id: "a", localDateTime: "2026-05-01T10:00:00.000Z" }), "2026")).toBe(true);
expect(matchesYear(photo({ id: "b", localDateTime: "2025-12-31T23:00:00.000Z" }), "2026")).toBe(false);
expect(matchesYear(photo({ id: "c", localDateTime: null, fileCreatedAt: "2026-01-01T00:00:00.000Z" }), "2026")).toBe(true);
expect(matchesYear(photo({ id: "d", localDateTime: null, fileCreatedAt: null }), "2026")).toBe(false);
});
test("filterPhotos applies format and jahr together across the full set", () => {
const items = [
photo({ id: "l26", originalFileName: "land26", localDateTime: "2026-03-01", exifInfo: { exifImageWidth: 2, exifImageHeight: 1 } }),
photo({ id: "p26", originalFileName: "port26", localDateTime: "2026-03-01", exifInfo: { exifImageWidth: 1, exifImageHeight: 2 } }),
photo({ id: "l25", originalFileName: "land25", localDateTime: "2025-03-01", exifInfo: { exifImageWidth: 2, exifImageHeight: 1 } }),
];
expect(filterPhotos(items, { format: "quer" }).map((p) => p.id)).toEqual(["l26", "l25"]);
expect(filterPhotos(items, { format: "hoch" }).map((p) => p.id)).toEqual(["p26"]);
expect(filterPhotos(items, { format: "quer", jahr: "2026" }).map((p) => p.id)).toEqual(["l26"]);
expect(filterPhotos(items, {})).toEqual(items);
});
test("paginatePhotos slices the filtered set and signals more pages", () => {
const items = Array.from({ length: 130 }, (_, i) => photo({ id: `p${i}` }));
const { result: page1, currentPage: c1 } = paginatePhotos(items, "1", 60);
expect(c1).toBe(1);
expect(page1.total).toBe(130);
expect(page1.items).toHaveLength(60);
expect(page1.nextPage).toBe(2);
expect(page1.previousPage).toBeNull();
const { result: page3, currentPage: c3 } = paginatePhotos(items, "3", 60);
expect(c3).toBe(3);
expect(page3.items).toHaveLength(10);
expect(page3.nextPage).toBeNull();
expect(page3.previousPage).toBe(2);
});
test("paginatePhotos clamps an out-of-range page to the last page", () => {
const items = Array.from({ length: 70 }, (_, i) => photo({ id: `p${i}` }));
const { result, currentPage } = paginatePhotos(items, "99", 60);
expect(currentPage).toBe(2);
expect(result.items).toHaveLength(10);
expect(result.nextPage).toBeNull();
});
test("paginatePhotos handles an empty set without dividing by zero", () => {
const { result, currentPage } = paginatePhotos([], "1", 60);
expect(currentPage).toBe(1);
expect(result.items).toEqual([]);
expect(result.nextPage).toBeNull();
expect(result.previousPage).toBeNull();
});
+71
View File
@@ -0,0 +1,71 @@
import type { ImmichAsset } from "@/modules/immich/types";
import { normalizePage } from "./catalog";
/**
* Filter + paginate a photo set in-app, used by the album detail and the
* cross-album search pages. Immich's `/search/metadata` paginates server-side
* and does not expose an orientation predicate, so hoch/quer and jahr filters
* are applied across the full fetched set before slicing the requested page.
* This keeps `total`, the page slice, and the has-more-pages signal consistent
* with the active filters — the old client-side filter on a single 60-item
* page silently dropped matching photos and reported the unfiltered total.
*/
export function matchesOrientation(asset: ImmichAsset, format: string): boolean {
const width = asset.exifInfo?.exifImageWidth ?? 0;
const height = asset.exifInfo?.exifImageHeight ?? 0;
// Unknown dimensions can't satisfy a format filter — exclude rather than
// show a portrait under "Querformat" (the original bug). `withExif: true`
// keeps this rare in practice.
if (width <= 0 || height <= 0) return false;
const isLandscape = width >= height;
return format === "quer" ? isLandscape : !isLandscape;
}
export function matchesYear(asset: ImmichAsset, jahr: string): boolean {
const value = asset.localDateTime ?? asset.fileCreatedAt;
return value !== null && value.startsWith(jahr);
}
export function filterPhotos(
items: ImmichAsset[],
filters: { format?: string; jahr?: string },
): ImmichAsset[] {
let filtered = items;
if (filters.format) {
filtered = filtered.filter((asset) => matchesOrientation(asset, filters.format!));
}
if (filters.jahr) {
filtered = filtered.filter((asset) => matchesYear(asset, filters.jahr!));
}
return filtered;
}
export type InAppPage = {
items: ImmichAsset[];
total: number;
nextPage: number | null;
previousPage: number | null;
};
export function paginatePhotos(
items: ImmichAsset[],
page: unknown,
pageSize: number,
): { result: InAppPage; currentPage: number } {
const total = items.length;
const totalPages = Math.max(1, Math.ceil(total / pageSize));
const currentPage = Math.min(normalizePage(page), totalPages);
const start = (currentPage - 1) * pageSize;
const pageItems = items.slice(start, start + pageSize);
return {
currentPage,
result: {
items: pageItems,
total,
nextPage: currentPage < totalPages ? currentPage + 1 : null,
previousPage: currentPage > 1 ? currentPage - 1 : null,
},
};
}
+204
View File
@@ -0,0 +1,204 @@
"use client";
/* eslint-disable @next/next/no-img-element */
import { useEffect, useState, type CSSProperties } from "react";
import { UsageDialog } from "@/components/download/usage-dialog";
import { LightboxToggleButton } from "@/app/redaktion/leuchtkasten/LightboxToggleButton";
import type { EditorialDownloadOptions } from "@/modules/downloads/stream";
import type { ImmichAsset } from "@/modules/immich/types";
import { formatDate, thumbnailUrl } from "./catalog-content";
type PhotoGalleryProps = Readonly<{
albumId?: string;
albumName: string;
items: ImmichAsset[];
downloadOptions?: EditorialDownloadOptions;
/** Pre-selected asset ids, passed as a plain array (Sets don't cross the RSC boundary). */
lightboxAssetIds?: string[];
showAlbumName?: boolean;
}>;
export function PhotoGallery({
albumId,
albumName,
items,
downloadOptions,
lightboxAssetIds,
showAlbumName,
}: PhotoGalleryProps) {
const [openIndex, setOpenIndex] = useState<number | null>(null);
const inLightbox = new Set(lightboxAssetIds);
// Keyboard nav + scroll lock while the lightbox is open. ponytail: a single
// window listener is enough; the lightbox is the only overlay in this view.
useEffect(() => {
if (openIndex === null) return;
function onKey(event: KeyboardEvent) {
if (event.key === "Escape") {
setOpenIndex(null);
} else if (event.key === "ArrowRight") {
setOpenIndex((i) => (i === null ? i : Math.min(i + 1, items.length - 1)));
} else if (event.key === "ArrowLeft") {
setOpenIndex((i) => (i === null ? i : Math.max(i - 1, 0)));
}
}
window.addEventListener("keydown", onKey);
const previousOverflow = document.body.style.overflow;
document.body.style.overflow = "hidden";
return () => {
window.removeEventListener("keydown", onKey);
document.body.style.overflow = previousOverflow;
};
}, [openIndex, items.length]);
if (items.length === 0) {
return (
<p className="catalog-empty">
Keine Fotos passen zu dieser Suche. Ändern Sie den Suchbegriff oder wählen Sie ein anderes Album.
</p>
);
}
return (
<>
<ul className="photo-gallery" aria-label={`Fotos aus ${albumName}`}>
{items.map((asset, index) => {
const activeAlbumId = albumId ?? (asset.albums?.[0]?.id as string | undefined);
return (
<li key={asset.id} className="photo-tile">
<figure className="photo-tile-frame">
<button
className="photo-tile-trigger"
type="button"
onClick={() => setOpenIndex(index)}
aria-label={`${asset.originalFileName} vergrößern`}
>
<img
alt={asset.originalFileName}
className="photo-tile-image"
loading="lazy"
src={thumbnailUrl(asset.id)}
style={aspectStyle(asset)}
/>
</button>
<div className="photo-tile-overlay">
<figcaption className="photo-tile-caption">
<span className="photo-tile-name">{asset.originalFileName}</span>
{showAlbumName ? renderAlbumName(asset) : null}
<span className="photo-tile-date">{formatDate(asset.localDateTime ?? asset.fileCreatedAt)}</span>
</figcaption>
<div className="photo-tile-actions">
<LightboxToggleButton assetId={asset.id} initialInLightbox={inLightbox.has(asset.id)} />
{activeAlbumId && downloadOptions ? (
<UsageDialog
albumId={activeAlbumId}
assetId={asset.id}
filename={asset.originalFileName}
newUsagePriceCents={downloadOptions.priceCents}
priorUsages={downloadOptions.priorUsagesByAsset[asset.id] ?? []}
/>
) : null}
</div>
</div>
</figure>
</li>
);
})}
</ul>
{openIndex !== null ? (
<PhotoLightbox
asset={items[openIndex]}
albumId={albumId}
downloadOptions={downloadOptions}
inLightbox={inLightbox.has(items[openIndex].id)}
hasPrev={openIndex > 0}
hasNext={openIndex < items.length - 1}
onClose={() => setOpenIndex(null)}
onPrev={() => setOpenIndex((i) => Math.max((i ?? 0) - 1, 0))}
onNext={() => setOpenIndex((i) => Math.min((i ?? 0) + 1, items.length - 1))}
/>
) : null}
</>
);
}
type PhotoLightboxProps = Readonly<{
asset: ImmichAsset;
albumId?: string;
downloadOptions?: EditorialDownloadOptions;
inLightbox: boolean;
hasPrev: boolean;
hasNext: boolean;
onClose: () => void;
onPrev: () => void;
onNext: () => void;
}>;
function PhotoLightbox({
asset,
albumId,
downloadOptions,
inLightbox,
hasPrev,
hasNext,
onClose,
onPrev,
onNext,
}: PhotoLightboxProps) {
const activeAlbumId = albumId ?? (asset.albums?.[0]?.id as string | undefined);
return (
<div className="photo-lightbox" role="dialog" aria-modal="true" aria-label={asset.originalFileName}>
<button className="lightbox-close" type="button" onClick={onClose} aria-label="Schließen">
✕
</button>
{hasPrev ? (
<button className="lightbox-nav lightbox-prev" type="button" onClick={onPrev} aria-label="Vorheriges Bild">
‹
</button>
) : null}
{hasNext ? (
<button className="lightbox-nav lightbox-next" type="button" onClick={onNext} aria-label="Nächstes Bild">
›
</button>
) : null}
<figure className="lightbox-figure">
<img alt={asset.originalFileName} className="lightbox-image" src={thumbnailUrl(asset.id)} />
<figcaption className="lightbox-caption">
<span className="photo-tile-name">{asset.originalFileName}</span>
<span className="photo-tile-date">{formatDate(asset.localDateTime ?? asset.fileCreatedAt)}</span>
</figcaption>
</figure>
<div className="lightbox-actions">
<LightboxToggleButton assetId={asset.id} initialInLightbox={inLightbox} />
{activeAlbumId && downloadOptions ? (
<UsageDialog
albumId={activeAlbumId}
assetId={asset.id}
filename={asset.originalFileName}
newUsagePriceCents={downloadOptions.priceCents}
priorUsages={downloadOptions.priorUsagesByAsset[asset.id] ?? []}
/>
) : null}
</div>
</div>
);
}
function aspectStyle(asset: ImmichAsset): CSSProperties {
const width = asset.exifInfo?.exifImageWidth ?? 0;
const height = asset.exifInfo?.exifImageHeight ?? 0;
return width > 0 && height > 0 ? { aspectRatio: `${width} / ${height}` } : {};
}
// `ImmichAsset.albums` is typed as `{ id }[]` but the `/search/metadata`
// response (parsed with `.passthrough()`) also carries `albumName`, which the
// cross-album search view surfaces. Read it via an unknown cast so the typed
// contract stays honest while still rendering the field when Immich sends it.
function renderAlbumName(asset: ImmichAsset) {
const first = (asset as unknown as { albums?: Array<{ albumName?: string }> }).albums?.[0];
return first?.albumName ? <span className="photo-tile-album">{first.albumName}</span> : null;
}
+1
View File
@@ -98,6 +98,7 @@ test("forces IMAGE and authorized album IDs in metadata search", async () => {
type: "IMAGE", type: "IMAGE",
page: 1, page: 1,
size: 60, size: 60,
withExif: true,
}); });
return HttpResponse.json(immichMetadataSearchResponse); return HttpResponse.json(immichMetadataSearchResponse);
}), }),
+5
View File
@@ -369,6 +369,11 @@ export function createImmichClient({
type: "IMAGE", type: "IMAGE",
page: input.page, page: input.page,
size: input.size, size: input.size,
// Required so exifImageWidth/exifImageHeight are populated — the
// album page filters by orientation (hoch/quer) and lays out the
// masonry grid from each asset's native aspect ratio. Without it
// Immich returns exifInfo as null and both break.
withExif: true,
}), }),
}, },
metadataSearchSchema.transform(({ assets }) => ({ metadataSearchSchema.transform(({ assets }) => ({