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

+38 -43
View File
@@ -1,8 +1,9 @@
import { AlbumCatalogError, albumCatalog } from "@/modules/albums/catalog";
import { AlbumContactSheet, PhotoContactSheet } from "@/modules/albums/catalog-content";
import { AlbumCatalogError, albumCatalog, PHOTO_PAGE_SIZE } from "@/modules/albums/catalog";
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 { lightboxService } from "@/modules/lightbox/service";
import type { ImmichSearchPage } from "@/modules/immich/types";
import Link from "next/link";
import { PageHeader } from "@/components/ui/page-header";
import { Input } from "@/components/ui/input";
@@ -10,6 +11,10 @@ import { Button } from "@/components/ui/button";
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[] }> }) {
const principal = await requireEditorial();
const rawSearchParams = await searchParams;
@@ -20,37 +25,16 @@ export default async function AlbumsPage({ searchParams }: { searchParams: Promi
if (query) {
const results = await albumCatalog.searchVisiblePhotos(principal.editorialId, {
description: query,
page: singleValue(rawSearchParams.page),
page: 1,
size: SEARCH_FETCH_SIZE,
});
if (format || jahr) {
results.items = results.items.filter(asset => {
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 filtered = filterPhotos(results.items, { format, jahr });
const { result: page, currentPage } = paginatePhotos(filtered, singleValue(rawSearchParams.page), PHOTO_PAGE_SIZE);
const downloadOptions = await loadEditorialDownloadOptions(
principal.editorialId,
results.items.map((asset) => asset.id),
page.items.map((asset) => asset.id),
);
const lightboxItems = await lightboxService.getLightboxItems(principal.editorialId);
const lightboxAssetIds = new Set(lightboxItems.map(i => i.assetId));
@@ -63,15 +47,17 @@ export default async function AlbumsPage({ searchParams }: { searchParams: Promi
titleId="albums-title"
/>
<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"
items={page.items}
downloadOptions={downloadOptions}
page={results}
query={query}
lightboxAssetIds={[...lightboxAssetIds]}
showAlbumName
lightboxAssetIds={lightboxAssetIds}
/>
<GlobalSearchPagination page={results} query={query} />
<GlobalSearchPagination currentPage={currentPage} page={page} query={query} format={format} jahr={jahr} />
</div>
);
}
@@ -133,23 +119,32 @@ function GlobalSearchForm({ query, format, jahr }: { query: string; format?: str
);
}
function GlobalSearchPagination({ page, query }: { page: ImmichSearchPage; query: string }) {
if (page.previousPage === null && page.nextPage === null) {
function GlobalSearchPagination({ currentPage, page, query, format, jahr }: { currentPage: number; page: InAppPage; query: string; format?: string; jahr?: string }) {
const hasPrev = currentPage > 1;
const hasNext = page.nextPage !== null;
if (!hasPrev && !hasNext) {
return null;
}
return (
<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 /> : (
<Link className="text-primary-600 hover:underline" href={`/redaktion/alben?suche=${encodeURIComponent(query)}&page=${page.previousPage}`}>Vorherige Seite</Link>
)}
{page.nextPage === null ? <div /> : (
<Link className="text-primary-600 hover:underline" href={`/redaktion/alben?suche=${encodeURIComponent(query)}&page=${page.nextPage}`}>Nächste Seite</Link>
)}
{hasPrev ? (
<Link className="text-primary-600 hover:underline" href={globalPageHref(currentPage - 1, query, format, jahr)}>Vorherige Seite</Link>
) : <div />}
{hasNext ? (
<Link className="text-primary-600 hover:underline" href={globalPageHref(currentPage + 1, query, format, jahr)}>Nächste Seite</Link>
) : <div />}
</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 {
return typeof value === "string" ? value : undefined;
}