96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
import Image from "next/image";
|
|
import Link from "next/link";
|
|
import { eq } from "drizzle-orm";
|
|
import { notFound } from "next/navigation";
|
|
|
|
import { db } from "@/db/client";
|
|
import { editorialAccounts } from "@/db/schema";
|
|
import { albumGrantService } from "@/modules/albums/grants";
|
|
|
|
import { grantAlbumAction, revokeAlbumAction } from "./actions";
|
|
import { loadAssignableAlbums } from "./page-content";
|
|
|
|
export default async function EditorialAlbumsPage({
|
|
params,
|
|
}: Readonly<{ params: Promise<{ id: string }> }>) {
|
|
const { id } = await params;
|
|
const [editorial] = await db
|
|
.select({ id: editorialAccounts.id, name: editorialAccounts.name })
|
|
.from(editorialAccounts)
|
|
.where(eq(editorialAccounts.id, id))
|
|
.limit(1);
|
|
if (!editorial) {
|
|
notFound();
|
|
}
|
|
|
|
const albumResult = await loadAssignableAlbums(editorial.id, albumGrantService);
|
|
|
|
if (albumResult.unavailable) {
|
|
return (
|
|
<section className="content-section" aria-labelledby="albums-title">
|
|
<p className="eyebrow">Redaktion · Albumrechte</p>
|
|
<h1 id="albums-title">Alben für {editorial.name}</h1>
|
|
<p role="status">
|
|
Die Immich-Alben sind momentan nicht erreichbar. Bereits bestehende Zuweisungen bleiben
|
|
unverändert.
|
|
</p>
|
|
<p>
|
|
<Link href={`/admin/redaktionen/${editorial.id}`}>Zurück zur Redaktion</Link>
|
|
</p>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<section className="content-section" aria-labelledby="albums-title">
|
|
<p className="eyebrow">Redaktion · Albumrechte</p>
|
|
<h1 id="albums-title">Alben für {editorial.name}</h1>
|
|
<p>
|
|
Nur Alben, die der technische Immich-Zugang lesen kann, lassen sich zuweisen.
|
|
</p>
|
|
<p>
|
|
<Link href={`/admin/redaktionen/${editorial.id}`}>Zurück zur Redaktion</Link>
|
|
</p>
|
|
|
|
{albumResult.albums.length === 0 ? (
|
|
<p>Derzeit sind keine zuweisbaren Alben vorhanden.</p>
|
|
) : (
|
|
<ul aria-label="Zuweisbare Immich-Alben">
|
|
{albumResult.albums.map((album) => {
|
|
const action = album.isGranted ? revokeAlbumAction : grantAlbumAction;
|
|
return (
|
|
<li key={album.id}>
|
|
<article aria-labelledby={`album-${album.id}`}>
|
|
{album.albumThumbnailAssetId ? (
|
|
<Image
|
|
alt={`Titelbild von ${album.albumName}`}
|
|
height={120}
|
|
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail?albumId=${encodeURIComponent(album.id)}`}
|
|
width={160}
|
|
/>
|
|
) : (
|
|
<div aria-label="Kein Albumcover verfügbar" role="img">
|
|
Kein Cover
|
|
</div>
|
|
)}
|
|
<h2 id={`album-${album.id}`}>{album.albumName}</h2>
|
|
<p>{album.assetCount} Fotos</p>
|
|
<p>
|
|
Status: <strong>{album.isGranted ? "Zugewiesen" : "Nicht zugewiesen"}</strong>
|
|
</p>
|
|
<form action={action.bind(null, editorial.id)}>
|
|
<input name="immichAlbumId" type="hidden" value={album.id} />
|
|
<button type="submit">
|
|
{album.isGranted ? "Zuweisung aufheben" : "Album zuweisen"}
|
|
</button>
|
|
</form>
|
|
</article>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|