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:
1 parent
b81cd7c3e2
commit
a3ec068cac
11 files changed
+949
-267
No files matched your search
@@ -1,14 +1,22 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AlbumCatalogError, albumCatalog, normalizePage } from "@/modules/albums/catalog";
|
||||
import { PhotoContactSheet } from "@/modules/albums/catalog-content";
|
||||
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[] }>;
|
||||
@@ -21,7 +29,6 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
|
||||
requireEditorial(),
|
||||
]);
|
||||
const query = normalizedQuery(singleValue(rawSearchParams.suche));
|
||||
const currentPage = normalizePage(singleValue(rawSearchParams.page));
|
||||
const format = singleValue(rawSearchParams.format);
|
||||
const jahr = singleValue(rawSearchParams.jahr);
|
||||
const result = await loadAlbumPage({
|
||||
@@ -52,14 +59,23 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
|
||||
</Link>
|
||||
</PageHeader>
|
||||
<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}
|
||||
albumName={result.album.albumName}
|
||||
currentPage={currentPage}
|
||||
items={result.page.items}
|
||||
downloadOptions={result.downloadOptions}
|
||||
lightboxAssetIds={[...result.lightboxAssetIds]}
|
||||
/>
|
||||
<PhotoPagination
|
||||
albumId={result.album.id}
|
||||
currentPage={result.currentPage}
|
||||
page={result.page}
|
||||
query={query}
|
||||
lightboxAssetIds={result.lightboxAssetIds}
|
||||
format={format}
|
||||
jahr={jahr}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
@@ -70,29 +86,41 @@ function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; qu
|
||||
const years = Array.from({ length: 10 }, (_, i) => currentYear - i);
|
||||
|
||||
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">
|
||||
<div className="flex-grow">
|
||||
<input
|
||||
type="search"
|
||||
name="suche"
|
||||
defaultValue={query}
|
||||
<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="Dieses Album durchsuchen"
|
||||
className="w-full"
|
||||
aria-label="Suchbegriff"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-4">
|
||||
<select name="format" defaultValue={format || ""} className="px-3 py-2 border border-gray-300 rounded-md">
|
||||
<option value="">Alle Formate</option>
|
||||
<option value="quer">Querformat</option>
|
||||
<option value="hoch">Hochformat</option>
|
||||
</select>
|
||||
<select name="jahr" defaultValue={jahr || ""} className="px-3 py-2 border border-gray-300 rounded-md">
|
||||
<option value="">Alle Jahre</option>
|
||||
{years.map(y => (
|
||||
<option key={y} value={y.toString()}>{y}</option>
|
||||
))}
|
||||
</select>
|
||||
<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>
|
||||
@@ -118,50 +146,32 @@ async function loadAlbumPage({
|
||||
const albums = await albumCatalog.getVisibleAlbums(editorialId);
|
||||
const album = albums.find((candidate) => candidate.id === albumId);
|
||||
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, {
|
||||
requestedAlbumId: album.id,
|
||||
description: query,
|
||||
page,
|
||||
page: 1,
|
||||
size: ALBUM_FETCH_SIZE,
|
||||
});
|
||||
|
||||
// Client-side filtering for format and year
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
// 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,
|
||||
results.items.map((asset) => asset.id),
|
||||
resultPage.items.map((asset) => asset.id),
|
||||
);
|
||||
const lightboxItems = await lightboxService.getLightboxItems(editorialId);
|
||||
const lightboxAssetIds = new Set(lightboxItems.map(i => i.assetId));
|
||||
return { album, page: results, downloadOptions, lightboxAssetIds, unavailable: false as const };
|
||||
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, unavailable: true as const };
|
||||
return { album: null, page: null, currentPage: 1, downloadOptions: undefined, lightboxAssetIds: new Set<string>(), unavailable: true as const };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@@ -192,4 +202,4 @@ function ImmichUnavailable() {
|
||||
</PageHeader>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user