feat: Add flatrate billing model for editorial accounts

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 03:27:10 +02:00
1 parent 699580a6a0
commit 0b1ffdfdfc
39 files changed
+4900 -57

No files matched your search

@@ -0,0 +1,22 @@
"use client";
import { useState } from "react";
export function DownloadLightboxForm({ assetIds }: { assetIds: string[] }) {
const [loading, setLoading] = useState(false);
function handleBulkDownload() {
alert("Bulk-Download ist aktuell in Entwicklung. Bitte klicke auf die Bilder, um sie einzeln herunterzuladen.");
}
return (
<button
type="button"
onClick={handleBulkDownload}
disabled={loading || assetIds.length === 0}
className="primary-action m-0"
>
Alle herunterladen
</button>
);
}
@@ -0,0 +1,56 @@
"use client";
import { useState, useTransition } from "react";
import { toggleLightboxItem } from "./actions";
type LightboxToggleButtonProps = {
assetId: string;
initialInLightbox: boolean;
};
export function LightboxToggleButton({ assetId, initialInLightbox }: LightboxToggleButtonProps) {
const [isPending, startTransition] = useTransition();
const [inLightbox, setInLightbox] = useState(initialInLightbox);
function handleClick(e: React.MouseEvent) {
e.preventDefault(); // prevent navigation if wrapped in a link
e.stopPropagation();
// Optimistic update
setInLightbox(!inLightbox);
startTransition(async () => {
try {
const result = await toggleLightboxItem(assetId);
setInLightbox(result.isNowInLightbox);
} catch {
// Revert on error
setInLightbox(inLightbox);
}
});
}
return (
<button
type="button"
onClick={handleClick}
disabled={isPending}
className={`lightbox-toggle-btn ${inLightbox ? 'in-lightbox' : ''}`}
aria-label={inLightbox ? "Aus dem Merkzettel entfernen" : "Auf den Merkzettel"}
title={inLightbox ? "Aus dem Merkzettel entfernen" : "Auf den Merkzettel"}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill={inLightbox ? "currentColor" : "none"}
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="w-5 h-5"
>
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
</svg>
</button>
);
}
@@ -0,0 +1,38 @@
"use client";
import { useTransition } from "react";
import { removeLightboxItemAction } from "./actions";
export function RemoveLightboxItemButton({ assetId }: { assetId: string }) {
const [isPending, startTransition] = useTransition();
function handleRemove() {
startTransition(async () => {
await removeLightboxItemAction(assetId);
});
}
return (
<button
type="button"
onClick={handleRemove}
disabled={isPending}
className="p-1.5 bg-white rounded-full shadow hover:bg-gray-100 text-gray-500 hover:text-red-500 transition-colors"
title="Aus Merkzettel entfernen"
aria-label="Aus Merkzettel entfernen"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="w-4 h-4"
>
<path d="M18 6L6 18M6 6l12 12" />
</svg>
</button>
);
}
+31
View File
@@ -0,0 +1,31 @@
"use server";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
import { requireActiveEditorial } from "@/modules/auth/principal";
import { lightboxService } from "@/modules/lightbox/service";
export async function toggleLightboxItem(assetId: string) {
const principal = await requireActiveEditorial(new Headers(await headers()));
const isInLightbox = await lightboxService.isAssetInLightbox(principal.editorialId, assetId);
if (isInLightbox) {
await lightboxService.removeLightboxItem(principal.editorialId, assetId);
} else {
await lightboxService.addLightboxItem(principal.editorialId, assetId);
}
// Revalidate routes where lightbox state is shown
revalidatePath("/redaktion/alben/[id]", "page");
revalidatePath("/redaktion/leuchtkasten", "page");
return { success: true, isNowInLightbox: !isInLightbox };
}
export async function removeLightboxItemAction(assetId: string) {
const principal = await requireActiveEditorial(new Headers(await headers()));
await lightboxService.removeLightboxItem(principal.editorialId, assetId);
revalidatePath("/redaktion/leuchtkasten", "page");
revalidatePath("/redaktion/alben/[id]", "page");
return { success: true };
}
+71
View File
@@ -0,0 +1,71 @@
import { headers } from "next/headers";
import { requireActiveEditorial } from "@/modules/auth/principal";
import { lightboxService } from "@/modules/lightbox/service";
import { immichClient } from "@/modules/immich/client";
import Image from "next/image";
import Link from "next/link";
import { RemoveLightboxItemButton } from "./RemoveLightboxItemButton";
import { DownloadLightboxForm } from "./DownloadLightboxForm";
export default async function LightboxPage() {
const principal = await requireActiveEditorial(new Headers(await headers()));
const items = await lightboxService.getLightboxItems(principal.editorialId);
// Fetch asset details for all items in the lightbox
const assets = items.length > 0
? await immichClient.searchAssets({
assetIds: items.map(i => i.assetId)
})
: [];
const assetMap = new Map(assets.map(a => [a.id, a]));
return (
<section className="editorial-section">
<p className="editorial-kicker">Merkzettel</p>
<h1>Dein Leuchtkasten</h1>
{items.length === 0 ? (
<p className="mt-8 text-gray-500">Dein Leuchtkasten ist leer.</p>
) : (
<>
<div className="flex justify-between items-center mb-8">
<p className="text-sm text-gray-600">
{items.length} {items.length === 1 ? 'Bild' : 'Bilder'} gemerkt
</p>
<DownloadLightboxForm assetIds={items.map(i => i.assetId)} />
</div>
<ul className="photo-contact-sheet">
{items.map((item) => {
const asset = assetMap.get(item.assetId);
if (!asset) return null;
return (
<li key={item.assetId} className="photo-contact-frame relative group">
<Link href={`/redaktion/nutzungen/neu?assetId=${item.assetId}`} className="contact-sheet-link">
<Image
alt={asset.originalFileName}
className="contact-sheet-image"
height={200}
src={`/api/assets/${encodeURIComponent(item.assetId)}/thumbnail`}
width={300}
/>
<div className="contact-strip">
<span className="contact-strip-name" title={asset.originalFileName}>
{asset.originalFileName}
</span>
</div>
</Link>
<div className="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity">
<RemoveLightboxItemButton assetId={item.assetId} />
</div>
</li>
);
})}
</ul>
</>
)}
</section>
);
}