Three production bugs on redaktionen.leon-tonhaeuser.de: 1. Download 404 (POST /api/download-intents → 404). getAlbum requested ?withoutAssets=true, so album.assets was always empty and the usages membership check (album.assets.some(id)) always failed → ASSET_NOT_IN_ALBUM → 404. Same root cause broke bulk-download's assetToGrantedAlbum map. Removed withoutAssets so consumers that authorize via album.assets get the real list; grants/thumbnail consumers ignore the extra data. 2. _next/image 400 on thumbnail proxy. next/image's optimizer choked on the watermarked streaming thumbnail response. Thumbnails are already server-resized to 800px, so the optimizer added nothing — switched leuchtkasten + admin AlbumGrid to plain <img>, matching photo-gallery. 3. Cross-album search "finds nothing". Immich albumIds is AND across albums (PR #18985): one /search/metadata call with all granted ids requires the asset to be in EVERY album, so single-album photos never match. Album- internal search passed one id so it worked. Fan out per granted album and merge; callers already paginate in-app. Also drop the jahr filter from the album-internal search form (unnecessary within a single album); backend still honors a jahr query param. Co-Authored-By: Claude <noreply@anthropic.com>
162 lines
6.1 KiB
TypeScript
162 lines
6.1 KiB
TypeScript
"use client";
|
|
|
|
/* eslint-disable @next/next/no-img-element */
|
|
|
|
import { useState, useTransition } from "react";
|
|
|
|
import type { AlbumActionResult } from "./actions";
|
|
|
|
type AlbumGridAction = (
|
|
editorialId: string,
|
|
_prevState: AlbumActionResult,
|
|
formData: FormData,
|
|
) => Promise<AlbumActionResult>;
|
|
|
|
type AlbumGridProps = {
|
|
albums: Array<{
|
|
id: string;
|
|
albumName: string;
|
|
albumThumbnailAssetId: string | null;
|
|
assetCount: number;
|
|
isGranted: boolean;
|
|
}>;
|
|
editorialId: string;
|
|
grantAction: AlbumGridAction;
|
|
revokeAction: AlbumGridAction;
|
|
notifyAction: AlbumGridAction;
|
|
};
|
|
|
|
type AlbumCardProps = {
|
|
album: AlbumGridProps["albums"][number];
|
|
editorialId: string;
|
|
grantAction: AlbumGridAction;
|
|
revokeAction: AlbumGridAction;
|
|
notifyAction: AlbumGridAction;
|
|
};
|
|
|
|
function AlbumCard({ album, editorialId, grantAction, revokeAction, notifyAction }: AlbumCardProps) {
|
|
const [isPending, startTransition] = useTransition();
|
|
const [notifyStatus, setNotifyStatus] = useState<"idle" | "pending" | "success" | "error">("idle");
|
|
|
|
const handleAction = (formData: FormData) => {
|
|
startTransition(async () => {
|
|
const initial: AlbumActionResult = { ok: true, message: "" };
|
|
if (album.isGranted) {
|
|
await revokeAction(editorialId, initial, formData);
|
|
} else {
|
|
await grantAction(editorialId, initial, formData);
|
|
}
|
|
});
|
|
};
|
|
|
|
return (
|
|
<li className={`flex flex-col bg-white border ${album.isGranted ? 'border-green-500 shadow-md ring-1 ring-green-500' : 'border-gray-200'} rounded-xl overflow-hidden transition-all duration-300 hover:shadow-lg`} data-granted={album.isGranted}>
|
|
<div className="relative aspect-[3/2] bg-gray-100 overflow-hidden">
|
|
{album.albumThumbnailAssetId ? (
|
|
<img
|
|
className="w-full h-full object-contain transition-transform duration-500 hover:scale-105"
|
|
alt={`Titelbild von ${album.albumName}`}
|
|
loading="lazy"
|
|
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail?albumId=${encodeURIComponent(album.id)}`}
|
|
/>
|
|
) : (
|
|
<div aria-label="Kein Albumcover verfügbar" className="w-full h-full flex items-center justify-center text-gray-400 text-xs uppercase tracking-widest" role="img">
|
|
Kein Cover
|
|
</div>
|
|
)}
|
|
{album.isGranted && (
|
|
<div className="absolute top-2 right-2 bg-green-500 text-white text-xs font-bold px-2 py-1 rounded-full shadow-sm">
|
|
Zugewiesen
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="p-4 flex flex-col flex-grow">
|
|
<h2 className="text-base font-bold text-gray-900 mb-1 truncate" id={`album-${album.id}`} title={album.albumName}>
|
|
{album.albumName}
|
|
</h2>
|
|
<p className="text-sm text-gray-500 mb-4">{album.assetCount} Fotos</p>
|
|
<div className="mt-auto space-y-2">
|
|
<form action={handleAction}>
|
|
<input name="immichAlbumId" type="hidden" value={album.id} />
|
|
<button
|
|
type="submit"
|
|
className={`w-full py-2 px-4 rounded-lg font-semibold text-sm transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-offset-1 ${
|
|
album.isGranted
|
|
? "bg-red-50 text-red-600 hover:bg-red-100 focus:ring-red-500 border border-red-200"
|
|
: "bg-gray-900 text-white hover:bg-gray-800 focus:ring-gray-900"
|
|
}`}
|
|
disabled={isPending}
|
|
>
|
|
{isPending ? "Wird verarbeitet..." : album.isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
|
|
</button>
|
|
</form>
|
|
|
|
{album.isGranted && (
|
|
<form action={(formData) => {
|
|
setNotifyStatus("pending");
|
|
notifyAction(editorialId, { ok: true, message: "" }, formData).then((res) => {
|
|
setNotifyStatus(res.ok ? "success" : "error");
|
|
setTimeout(() => setNotifyStatus("idle"), 3000);
|
|
});
|
|
}}>
|
|
<input name="albumName" type="hidden" value={album.albumName} />
|
|
<button
|
|
type="submit"
|
|
className={`w-full py-2 px-4 rounded-lg font-semibold text-sm transition-colors duration-200 border ${
|
|
notifyStatus === "success" ? "bg-green-50 text-green-700 border-green-200" :
|
|
notifyStatus === "error" ? "bg-red-50 text-red-700 border-red-200" :
|
|
"bg-white text-gray-700 hover:bg-gray-50 border-gray-200 focus:ring-2 focus:ring-gray-200 focus:outline-none"
|
|
}`}
|
|
disabled={notifyStatus === "pending" || notifyStatus === "success"}
|
|
>
|
|
{notifyStatus === "pending" ? "Wird gesendet..." :
|
|
notifyStatus === "success" ? "E-Mail gesendet!" :
|
|
notifyStatus === "error" ? "Fehler beim Senden" :
|
|
"Redaktion benachrichtigen"}
|
|
</button>
|
|
</form>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
export function AlbumGrid({ albums, editorialId, grantAction, revokeAction, notifyAction }: AlbumGridProps) {
|
|
const [search, setSearch] = useState("");
|
|
|
|
const filteredAlbums = albums.filter((album) =>
|
|
album.albumName.toLowerCase().includes(search.toLowerCase()),
|
|
);
|
|
|
|
return (
|
|
<div>
|
|
<input
|
|
type="search"
|
|
className="album-grid-search"
|
|
placeholder="Alben suchen..."
|
|
value={search}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
aria-label="Alben durchsuchen"
|
|
/>
|
|
|
|
{filteredAlbums.length === 0 ? (
|
|
<p>Keine Alben gefunden.</p>
|
|
) : (
|
|
<ul className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6" aria-label="Zuweisbare Immich-Alben">
|
|
{filteredAlbums.map((album) => (
|
|
<AlbumCard
|
|
key={album.id}
|
|
album={album}
|
|
editorialId={editorialId}
|
|
grantAction={grantAction}
|
|
revokeAction={revokeAction}
|
|
notifyAction={notifyAction}
|
|
/>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|