diff --git a/src/app/globals.css b/src/app/globals.css index 6dfd273..68ac83d 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -569,40 +569,25 @@ a { text-underline-offset: 0.2em; } -.album-contact-sheet, -.photo-contact-sheet { +.album-contact-sheet { display: grid; gap: clamp(1.25rem, 2.25vw, 2.5rem); padding: 0; list-style: none; -} - -.album-contact-sheet { 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 { display: block; color: inherit; text-decoration: none; } -.album-contact-frame, -.photo-contact-frame { +.album-contact-frame { margin: 0; background: var(--contact-sheet); -} - -.album-contact-frame { border: 1px solid var(--ink); -} - -.photo-contact-frame { - border-top: 1px solid var(--ink); + overflow: hidden; } .contact-sheet-image, @@ -615,10 +600,6 @@ a { transition: transform 150ms ease-out; } -.photo-contact-frame .contact-sheet-image { - aspect-ratio: 3 / 2; -} - .missing-contact-image { display: grid; place-items: center; @@ -633,11 +614,6 @@ a { transform: scale(1.015); } -.album-contact-frame, -.photo-contact-frame { - overflow: hidden; -} - .contact-strip { display: flex; align-items: baseline; @@ -662,6 +638,191 @@ a { 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 { display: grid; gap: 0.55rem; @@ -736,6 +897,201 @@ a { 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 { display: grid; grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr); @@ -796,7 +1152,9 @@ a { } @media (prefers-reduced-motion: reduce) { - .contact-sheet-image { + .contact-sheet-image, + .photo-tile-image, + .photo-tile-overlay { transition: none; } } diff --git a/src/app/redaktion/alben/[albumId]/page.tsx b/src/app/redaktion/alben/[albumId]/page.tsx index 4bf18e4..63bb4d5 100644 --- a/src/app/redaktion/alben/[albumId]/page.tsx +++ b/src/app/redaktion/alben/[albumId]/page.tsx @@ -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 - + {formatCount(result.page.total, "Foto")} gefunden +

+ + ); @@ -70,29 +86,41 @@ function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; qu const years = Array.from({ length: 10 }, (_, i) => currentYear - i); return ( -
-
- +
+ +
-
- - +
+ +
@@ -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(), 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(), unavailable: true as const }; } throw error; } @@ -192,4 +202,4 @@ function ImmichUnavailable() { ); -} +} \ No newline at end of file diff --git a/src/app/redaktion/alben/page.tsx b/src/app/redaktion/alben/page.tsx index fb74bfe..589df6a 100644 --- a/src/app/redaktion/alben/page.tsx +++ b/src/app/redaktion/alben/page.tsx @@ -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" /> - + {formatCount(page.total, "Foto")} gefunden +

+ - +
); } @@ -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 ( ); } +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; } diff --git a/src/modules/albums/catalog-content.test.tsx b/src/modules/albums/catalog-content.test.tsx index d14398a..887ce28 100644 --- a/src/modules/albums/catalog-content.test.tsx +++ b/src/modules/albums/catalog-content.test.tsx @@ -1,9 +1,10 @@ // @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 { AlbumContactSheet, PhotoContactSheet } from "./catalog-content"; +import { AlbumContactSheet } from "./catalog-content"; +import { PhotoGallery } from "./photo-gallery"; 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", () => { - render( - , - ); +const photo = { + id: "asset-1", + type: "IMAGE" as const, + originalFileName: "tor-des-sieges.jpg", + originalMimeType: "image/jpeg", + localDateTime: "2026-08-08T18:42:00.000Z", + fileCreatedAt: null, + albums: [{ id: "heimspiel" }], +}; - expect(screen.getByRole("search", { name: /fotos in heimspiel gegen nord durchsuchen/i })).not.toBeNull(); - expect((screen.getByRole("searchbox", { name: /suchbegriff/i }) as HTMLInputElement).value).toBe("Tor"); +test("renders the gallery list labelled by album name", () => { + render(); + expect(screen.getByRole("list", { name: /fotos aus heimspiel gegen nord/i })).not.toBeNull(); expect(screen.getByAltText("tor-des-sieges.jpg").getAttribute("src")).toBe( "/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", () => { render( - { ], }, }} - page={{ - items: [ - { - id: "22222222-2222-4222-8222-222222222222", - type: "IMAGE", - originalFileName: "tor.jpg", - originalMimeType: "image/jpeg", - localDateTime: null, - fileCreatedAt: null, - albums: [{ id: "33333333-3333-4333-8333-333333333333" }], - }, - ], - total: 1, - nextPage: null, - previousPage: null, - }} - query="" + items={[ + { + id: "22222222-2222-4222-8222-222222222222", + type: "IMAGE", + originalFileName: "tor.jpg", + originalMimeType: "image/jpeg", + localDateTime: null, + fileCreatedAt: null, + albums: [{ id: "33333333-3333-4333-8333-333333333333" }], + }, + ]} />, ); expect(screen.getByRole("button", { name: /original laden/i })).not.toBeNull(); }); + +test("opens a full-screen lightbox when a photo tile is clicked", () => { + render( + , + ); + + // 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(); +}); \ No newline at end of file diff --git a/src/modules/albums/catalog-content.tsx b/src/modules/albums/catalog-content.tsx index 109dd83..52e2695 100644 --- a/src/modules/albums/catalog-content.tsx +++ b/src/modules/albums/catalog-content.tsx @@ -2,9 +2,6 @@ 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 { VisibleAlbum } from "./catalog"; @@ -41,89 +38,24 @@ export function AlbumContactSheet({ albums }: Readonly<{ albums: VisibleAlbum[] ); } -export function PhotoContactSheet({ - albumId, - albumName, - currentPage = 1, - downloadOptions, - page, - query, - showAlbumName = false, - lightboxAssetIds, -}: Readonly<{ - albumId?: string; - albumName: string; - currentPage?: number; - downloadOptions?: EditorialDownloadOptions; - page: ImmichSearchPage; - query: string; - showAlbumName?: boolean; - lightboxAssetIds?: Set; -}>) { - return ( - <> -

- {formatCount(page.total, "Foto")} gefunden -

- - {page.items.length === 0 ? ( -

Keine Fotos passen zu dieser Suche. Ändern Sie den Suchbegriff oder wählen Sie ein anderes Album.

- ) : ( -
    - {page.items.map((asset) => ( -
  • -
    - {asset.originalFileName} - {lightboxAssetIds && ( -
    - -
    - )} -
    - {asset.originalFileName} - {showAlbumName && (asset as any).albums && (asset as any).albums.length > 0 && ( - {(asset as any).albums[0].albumName} - )} - {formatDate(asset.localDateTime ?? asset.fileCreatedAt)} -
    - {(albumId ?? asset.albums?.[0]?.id) && downloadOptions ? ( - - ) : null} -
    -
  • - ))} -
- )} - - {albumId ? ( - - ) : 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({ +// Server-rendered pagination. Links thread every active filter (suche, +// format, jahr) so flipping pages does not silently drop them — that was the +// old bug: pageHref only carried `suche`, so "Nächste Seite" reset format/jahr. +export function PhotoPagination({ albumId, currentPage, page, 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 hasNext = page.nextPage !== null; if (!hasPrev && !hasNext) { @@ -132,29 +64,41 @@ function PhotoPagination({ return ( ); } -function thumbnailUrl(assetId: string): string { +export function thumbnailUrl(assetId: string): string { 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) }); if (query) { parameters.set("suche", query); } + if (format) { + parameters.set("format", format); + } + if (jahr) { + parameters.set("jahr", jahr); + } 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"}`; } -function formatDate(value: string | null): string { +export function formatDate(value: string | null): string { if (!value) { return "Ohne Zeitangabe"; } @@ -164,4 +108,4 @@ function formatDate(value: string | null): string { return "Ohne Zeitangabe"; } return new Intl.DateTimeFormat("de-DE", { dateStyle: "medium" }).format(date); -} +} \ No newline at end of file diff --git a/src/modules/albums/catalog.ts b/src/modules/albums/catalog.ts index 43077b5..5f07a44 100644 --- a/src/modules/albums/catalog.ts +++ b/src/modules/albums/catalog.ts @@ -14,6 +14,7 @@ export type SearchVisiblePhotosInput = { requestedAlbumId?: string; description?: unknown; page?: unknown; + size?: number; }; export type AlbumCatalogDependencies = { @@ -59,7 +60,7 @@ export function createAlbumCatalog({ grants, immich }: AlbumCatalogDependencies) ...(description === undefined ? {} : { description }), type: "IMAGE", page: normalizePage(input.page), - size: PHOTO_PAGE_SIZE, + size: input.size ?? PHOTO_PAGE_SIZE, }); } catch { throw new AlbumCatalogError("IMMICH_UNAVAILABLE"); diff --git a/src/modules/albums/filter.test.ts b/src/modules/albums/filter.test.ts new file mode 100644 index 0000000..66b9ea4 --- /dev/null +++ b/src/modules/albums/filter.test.ts @@ -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 & { 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(); +}); \ No newline at end of file diff --git a/src/modules/albums/filter.ts b/src/modules/albums/filter.ts new file mode 100644 index 0000000..a160418 --- /dev/null +++ b/src/modules/albums/filter.ts @@ -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, + }, + }; +} \ No newline at end of file diff --git a/src/modules/albums/photo-gallery.tsx b/src/modules/albums/photo-gallery.tsx new file mode 100644 index 0000000..c0cc1cf --- /dev/null +++ b/src/modules/albums/photo-gallery.tsx @@ -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(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 ( +

+ Keine Fotos passen zu dieser Suche. Ändern Sie den Suchbegriff oder wählen Sie ein anderes Album. +

+ ); + } + + return ( + <> +
    + {items.map((asset, index) => { + const activeAlbumId = albumId ?? (asset.albums?.[0]?.id as string | undefined); + return ( +
  • +
    + +
    +
    + {asset.originalFileName} + {showAlbumName ? renderAlbumName(asset) : null} + {formatDate(asset.localDateTime ?? asset.fileCreatedAt)} +
    +
    + + {activeAlbumId && downloadOptions ? ( + + ) : null} +
    +
    +
    +
  • + ); + })} +
+ + {openIndex !== null ? ( + 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 ( +
+ + {hasPrev ? ( + + ) : null} + {hasNext ? ( + + ) : null} +
+ {asset.originalFileName} +
+ {asset.originalFileName} + {formatDate(asset.localDateTime ?? asset.fileCreatedAt)} +
+
+
+ + {activeAlbumId && downloadOptions ? ( + + ) : null} +
+
+ ); +} + +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 ? {first.albumName} : null; +} \ No newline at end of file diff --git a/src/modules/immich/client.test.ts b/src/modules/immich/client.test.ts index 87cd402..7699d01 100644 --- a/src/modules/immich/client.test.ts +++ b/src/modules/immich/client.test.ts @@ -98,6 +98,7 @@ test("forces IMAGE and authorized album IDs in metadata search", async () => { type: "IMAGE", page: 1, size: 60, + withExif: true, }); return HttpResponse.json(immichMetadataSearchResponse); }), diff --git a/src/modules/immich/client.ts b/src/modules/immich/client.ts index a6d28d4..2ae64e0 100644 --- a/src/modules/immich/client.ts +++ b/src/modules/immich/client.ts @@ -369,6 +369,11 @@ export function createImmichClient({ type: "IMAGE", page: input.page, 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 }) => ({