Files
immich-redaktions-plugin/src/app/redaktion/alben/[albumId]/page.tsx
T
Leon TonhäuserandClaude a3ec068cac 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>
2026-08-11 13:36:46 +02:00

205 lines
7.1 KiB
TypeScript

import Link from "next/link";
import { notFound } from "next/navigation";
import { AlbumCatalogError, albumCatalog, PHOTO_PAGE_SIZE } from "@/modules/albums/catalog";
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 { lightboxService } from "@/modules/lightbox/service";
import { requireEditorial } from "../../access";
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<{
params: Promise<{ albumId: string }>;
searchParams: Promise<{ page?: string | string[]; suche?: string | string[]; format?: string | string[]; jahr?: string | string[] }>;
}>;
export default async function AlbumPage({ params, searchParams }: AlbumPageProps) {
const [{ albumId }, rawSearchParams, principal] = await Promise.all([
params,
searchParams,
requireEditorial(),
]);
const query = normalizedQuery(singleValue(rawSearchParams.suche));
const format = singleValue(rawSearchParams.format);
const jahr = singleValue(rawSearchParams.jahr);
const result = await loadAlbumPage({
editorialId: principal.editorialId,
albumId,
query,
page: singleValue(rawSearchParams.page),
format,
jahr,
});
if (result.unavailable) {
return <ImmichUnavailable />;
}
if (!result.album) {
notFound();
}
return (
<section className="editorial-section" aria-labelledby="album-title">
<PageHeader
kicker={`Bildarchiv · ${result.album.assetCount} freigegebene Fotos`}
title={result.album.albumName}
titleId="album-title"
>
<Link className="quiet-link" href="/redaktion/alben">
Alle Alben
</Link>
</PageHeader>
<AlbumSearchForm albumId={result.album.id} query={query} format={format} jahr={jahr} />
<p aria-live="polite" className="result-summary" role="status">
{formatCount(result.page.total, "Foto")} gefunden
</p>
<PhotoGallery
albumId={result.album.id}
albumName={result.album.albumName}
items={result.page.items}
downloadOptions={result.downloadOptions}
lightboxAssetIds={[...result.lightboxAssetIds]}
/>
<PhotoPagination
albumId={result.album.id}
currentPage={result.currentPage}
page={result.page}
query={query}
format={format}
jahr={jahr}
/>
</section>
);
}
function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; query: string; format?: string; jahr?: string; }) {
const currentYear = new Date().getFullYear();
const years = Array.from({ length: 10 }, (_, i) => currentYear - i);
return (
<form
action={`/redaktion/alben/${albumId}`}
className="album-search-form"
role="search"
aria-label={`Fotos in diesem Album durchsuchen`}
>
<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..."
aria-label="Suchbegriff"
/>
</div>
<div className="album-search-filters">
<label className="album-search-select">
<span>Format</span>
<select name="format" defaultValue={format || ""}>
<option value="">Alle Formate</option>
<option value="quer">Querformat</option>
<option value="hoch">Hochformat</option>
</select>
</label>
<label className="album-search-select">
<span>Jahr</span>
<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>
</div>
</form>
);
}
async function loadAlbumPage({
editorialId,
albumId,
query,
page,
format,
jahr,
}: {
editorialId: string;
albumId: string;
query: string;
page: string | undefined;
format?: string;
jahr?: string;
}) {
try {
const albums = await albumCatalog.getVisibleAlbums(editorialId);
const album = albums.find((candidate) => candidate.id === albumId);
if (!album) {
return { album: null, page: null, currentPage: 1, downloadOptions: undefined, lightboxAssetIds: new Set<string>(), unavailable: false as const };
}
const results = await albumCatalog.searchVisiblePhotos(editorialId, {
requestedAlbumId: album.id,
description: query,
page: 1,
size: ALBUM_FETCH_SIZE,
});
// Filter format + jahr across the full album set BEFORE paginating, so the
// total, the page slice, and the has-more-pages signal all reflect the
// active filters. The old code filtered a single 60-item page client-side,
// which silently dropped matching photos and reported the unfiltered total.
const filtered = filterPhotos(results.items, { format, jahr });
const { result: resultPage, currentPage } = paginatePhotos(filtered, page, PHOTO_PAGE_SIZE);
const downloadOptions = await loadEditorialDownloadOptions(
editorialId,
resultPage.items.map((asset) => asset.id),
);
const lightboxItems = await lightboxService.getLightboxItems(editorialId);
const lightboxAssetIds = new Set(lightboxItems.map((i) => i.assetId));
return { album, page: resultPage, currentPage, downloadOptions, lightboxAssetIds, unavailable: false as const };
} catch (error) {
if (error instanceof AlbumCatalogError && error.code === "IMMICH_UNAVAILABLE") {
return { album: null, page: null, currentPage: 1, downloadOptions: undefined, lightboxAssetIds: new Set<string>(), unavailable: true as const };
}
throw error;
}
}
function singleValue(value: string | string[] | undefined): string | undefined {
return typeof value === "string" ? value : undefined;
}
function normalizedQuery(value: string | undefined): string {
return (value ?? "").replace(/\s+/g, " ").trim().slice(0, 200);
}
function ImmichUnavailable() {
return (
<section className="editorial-section editorial-state" aria-labelledby="album-title">
<PageHeader
kicker="Bildarchiv"
title="Fotos momentan nicht erreichbar"
titleId="album-title"
>
<div className="flex flex-col gap-2 items-end">
<p role="status">Bitte laden Sie diese Seite in wenigen Minuten erneut.</p>
<Link className="quiet-link" href="/redaktion/alben">
Zurück zu den Alben
</Link>
</div>
</PageHeader>
</section>
);
}