"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; }>) { const [open, setOpen] = useState(false); const [excluded, setExcluded] = useState>(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 ( {albums.length > 0 && !open ? (
) : null} {open ? (
{selected.length} ausgewählt
    {albums.map((album) => (
  • toggle(album.albumId, event.target.checked)} />
  • ))}
({ label: category.name, value: category.id })), ]} />
) : null}
); }