- Admin calendar: "Ältere Alben übernehmen" lists albums named "Titel | TT.MM.JJJJ" without an event (preview, all preselected, optional category) and creates linked events in one transaction. Albums without a date suffix are never offered. - Editorials now see all past events; the past list is collapsible and a click in the month view opens it. - Release notes 2.4.1 seeded (migration 0010). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
4.6 KiB
TypeScript
122 lines
4.6 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo, useState, useTransition } from "react";
|
|
import { Badge, Button, Checkbox } from "@sakaniui/react";
|
|
import { IconDownload } from "@sakaniui/react/icons";
|
|
|
|
import { notifyResult } from "@/components/ui/feedback";
|
|
import { Card, FormSelect } from "@/components/ui/sakani";
|
|
import type { ImportableAlbum } from "@/modules/calendar/service";
|
|
|
|
import type { CalendarActionResult } from "./actions";
|
|
|
|
const dateFormat = new Intl.DateTimeFormat("de-DE", { dateStyle: "medium", timeZone: "UTC" });
|
|
|
|
/**
|
|
* Older Immich albums ("Titel | TT.MM.JJJJ") without an event: preview with
|
|
* everything preselected, untick what should stay out, pick a category.
|
|
*/
|
|
export function AlbumImport({
|
|
albums,
|
|
categories,
|
|
action,
|
|
}: Readonly<{
|
|
albums: ImportableAlbum[];
|
|
categories: Array<{ id: string; name: string }>;
|
|
action: (state: CalendarActionResult, formData: FormData) => Promise<CalendarActionResult>;
|
|
}>) {
|
|
const [open, setOpen] = useState(false);
|
|
const [excluded, setExcluded] = useState<ReadonlySet<string>>(new Set());
|
|
const [pending, startTransition] = useTransition();
|
|
const selected = useMemo(() => albums.filter((album) => !excluded.has(album.albumId)), [albums, excluded]);
|
|
|
|
const toggle = (albumId: string, checked: boolean) =>
|
|
setExcluded((previous) => {
|
|
const next = new Set(previous);
|
|
if (checked) next.delete(albumId);
|
|
else next.add(albumId);
|
|
return next;
|
|
});
|
|
|
|
const submit = (formData: FormData) => {
|
|
for (const album of selected) formData.append("albumId", album.albumId);
|
|
startTransition(async () => {
|
|
const result = await action({ ok: true, message: "" }, formData);
|
|
notifyResult(result);
|
|
if (result.ok) {
|
|
setOpen(false);
|
|
setExcluded(new Set());
|
|
}
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Card
|
|
description={
|
|
albums.length === 0
|
|
? "Alle Alben im Format „Titel | TT.MM.JJJJ“ haben bereits einen Termin."
|
|
: `${albums.length} ${albums.length === 1 ? "Album" : "Alben"} im Format „Titel | TT.MM.JJJJ“ ohne Termin gefunden. Titel und Datum werden aus dem Albumnamen übernommen.`
|
|
}
|
|
title="Ältere Alben übernehmen"
|
|
>
|
|
{albums.length > 0 && !open ? (
|
|
<div>
|
|
<Button leftIcon={<IconDownload size={16} />} onClick={() => setOpen(true)} type="button" variant="secondary">
|
|
Alben aus Immich anzeigen
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
|
|
{open ? (
|
|
<form action={submit} className="flex flex-col gap-4">
|
|
<div className="flex flex-wrap items-center gap-3 text-sm">
|
|
<Button onClick={() => setExcluded(new Set())} size="sm" type="button" variant="ghost">
|
|
Alle auswählen
|
|
</Button>
|
|
<Button
|
|
onClick={() => setExcluded(new Set(albums.map((album) => album.albumId)))}
|
|
size="sm"
|
|
type="button"
|
|
variant="ghost"
|
|
>
|
|
Keine
|
|
</Button>
|
|
<Badge variant="info">{selected.length} ausgewählt</Badge>
|
|
</div>
|
|
<ul className="flex max-h-96 flex-col divide-y divide-[var(--color-border-subtle)] overflow-y-auto rounded-[var(--radius-xl)] border border-[var(--color-border-subtle)]">
|
|
{albums.map((album) => (
|
|
<li className="flex items-center justify-between gap-4 px-3 py-2.5" key={album.albumId}>
|
|
<Checkbox
|
|
checked={!excluded.has(album.albumId)}
|
|
description={`${dateFormat.format(new Date(`${album.eventDate}T00:00:00Z`))} · ${album.assetCount} Fotos`}
|
|
disabled={pending}
|
|
label={album.title}
|
|
onChange={(event) => toggle(album.albumId, event.target.checked)}
|
|
/>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<div className="sm:max-w-xs">
|
|
<FormSelect
|
|
label="Kategorie für alle übernommenen Termine"
|
|
name="categoryId"
|
|
options={[
|
|
{ label: "Ohne Kategorie", value: "" },
|
|
...categories.map((category) => ({ label: category.name, value: category.id })),
|
|
]}
|
|
/>
|
|
</div>
|
|
<div className="flex flex-wrap gap-3">
|
|
<Button disabled={pending || selected.length === 0} loading={pending} type="submit">
|
|
{selected.length === 1 ? "1 Termin übernehmen" : `${selected.length} Termine übernehmen`}
|
|
</Button>
|
|
<Button disabled={pending} onClick={() => setOpen(false)} type="button" variant="ghost">
|
|
Abbrechen
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
) : null}
|
|
</Card>
|
|
);
|
|
}
|