Release 2.4.1: import older Immich albums into the calendar

- 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>
This commit is contained in:
Leon TonhäuserandClaude Opus 5.5 committed 2026-12-01 00:35:36 +01:00
1 parent cba70310f9
commit 8748cc1098
16 files changed
+3025 -78

No files matched your search

+121
View File
@@ -0,0 +1,121 @@
"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>
);
}
+23
View File
@@ -46,6 +46,28 @@ export async function createCalendarEventAction(
};
}
/** Imports selected older Immich albums as calendar events. */
export async function importAlbumsAction(
_prevState: CalendarActionResult,
formData: FormData,
): Promise<CalendarActionResult> {
const principal = await requireAdmin(new Headers(await headers()));
const albumIds = formData.getAll("albumId").filter((value): value is string => typeof value === "string");
const categoryId = formData.get("categoryId");
try {
const { imported } = await calendarService.importAlbums({
albumIds,
categoryId: typeof categoryId === "string" && categoryId ? categoryId : null,
adminUserId: principal.userId,
});
revalidatePath("/admin/kalender");
revalidatePath("/redaktion/kalender");
return { ok: true, message: imported === 1 ? "1 Termin übernommen." : `${imported} Termine übernommen.` };
} catch (error) {
return { ok: false, message: calendarErrorMessage(error) };
}
}
export async function deleteCalendarEventAction(
_prevState: CalendarActionResult,
formData: FormData,
@@ -75,6 +97,7 @@ function calendarErrorMessage(error: unknown): string {
INVALID_EVENT_DATE: "Bitte wählen Sie ein gültiges Datum.",
INVALID_ALBUM: "Das gewählte Album existiert nicht mehr in Immich.",
INVALID_CATEGORY: "Die gewählte Kategorie existiert nicht mehr.",
NOTHING_TO_IMPORT: "Bitte mindestens ein Album auswählen, das noch keinen Termin hat.",
EVENT_NOT_FOUND: "Dieser Termin existiert nicht mehr.",
RESERVATION_NOT_FOUND: "Diese Vormerkung existiert nicht mehr.",
IMMICH_UNAVAILABLE: "Immich ist gerade nicht erreichbar. Bitte später erneut versuchen.",
+12 -2
View File
@@ -13,14 +13,16 @@ import { immichClient } from "@/modules/immich/client";
import { requireAdminPage } from "../access";
import { CalendarEventForm } from "./CalendarEventForm";
import { DeleteCalendarEventButton } from "./DeleteCalendarEventButton";
import { createCalendarEventAction, deleteCalendarEventAction } from "./actions";
import { AlbumImport } from "./AlbumImport";
import { createCalendarEventAction, deleteCalendarEventAction, importAlbumsAction } from "./actions";
export default async function AdminCalendarPage() {
await requireAdminPage();
const [{ events, immichUnavailable }, albums, categories] = await Promise.all([
const [{ events, immichUnavailable }, albums, categories, importable] = await Promise.all([
calendarService.listAdminEvents(),
immichClient.listAlbums().catch(() => []),
categoryService.listCategories(),
calendarService.listImportableAlbums(),
]);
const today = isoDateInBerlin(new Date());
@@ -43,6 +45,14 @@ export default async function AdminCalendarPage() {
defaultEventDate={today}
/>
{importable.immichUnavailable ? null : (
<AlbumImport
action={importAlbumsAction}
albums={importable.albums}
categories={categories.map((category) => ({ id: category.id, name: category.name }))}
/>
)}
{immichUnavailable ? (
<Alert
color="warning"