feat(board): Mehrfachauswahl fuer Status, Tags und Loeschen
Kaestchen auf jeder Karte, darunter eine Leiste am unteren Rand. Fest verankert, weil sie bei einer langen Liste oben laengst aus dem Blick gescrollt waere, waehrend man noch auswaehlt. Ein eigener Endpunkt statt vieler einzelner PATCHes: eine Transaktion statt zwanzig Rundgaengen, und der Verlauf bekommt je Projekt genau einen Eintrag statt eines Schwalls. Was der Filter ausblendet, faellt aus der Auswahl - sonst traefe eine Massenaenderung Projekte, die man gar nicht mehr vor Augen hat. Fremde IDs sammelt der Server wegen der Besitzerbedingung erst gar nicht ein und meldet sie als uebergangen. Das Kaestchen ist gedaempft, aber immer sichtbar. Erst beim Ueberfahren einzublenden waere auf einem Touchgeraet nicht erreichbar - und wer es nie sieht, weiss nicht, dass es die Auswahl gibt. Ansicht, Sortierung und Archivschalter ueberdauern nun das Neuladen. Wer sein Brett von Hand anordnet, will es beim naechsten Aufruf auch sehen. Der Suchbegriff bleibt aussen vor: eine Suche von gestern wiederherzustellen waere eher verwirrend. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Loader2, Star, Tag, Trash2, X } from "lucide-react";
|
||||
import type { ProjectStatus } from "@prisma/client";
|
||||
import { Popover } from "@/components/ui/Popover";
|
||||
import { STATUS_META, STATUS_ORDER } from "@/lib/status";
|
||||
import { cn, parseTags } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* Leiste fuer die Mehrfachauswahl. Erscheint erst, wenn etwas ausgewaehlt ist,
|
||||
* und liegt fest am unteren Rand – bei einer langen Liste waere sie oben
|
||||
* sonst laengst aus dem Blick gescrollt, waehrend man noch auswaehlt.
|
||||
*/
|
||||
export function BulkBar({
|
||||
ids,
|
||||
onDone,
|
||||
onClear,
|
||||
}: {
|
||||
ids: string[];
|
||||
onDone: () => void;
|
||||
onClear: () => void;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [statusOpen, setStatusOpen] = useState(false);
|
||||
const [tagsOpen, setTagsOpen] = useState(false);
|
||||
const [tagInput, setTagInput] = useState("");
|
||||
const statusRef = useRef<HTMLButtonElement>(null);
|
||||
const tagsRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
async function apply(body: Record<string, unknown>) {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch("/api/projects/bulk", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ ids, ...body }),
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(payload.error ?? "Das hat nicht geklappt.");
|
||||
onDone();
|
||||
router.refresh();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof Error ? caught.message : String(caught));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
setStatusOpen(false);
|
||||
setTagsOpen(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
if (
|
||||
!window.confirm(
|
||||
`${ids.length} Projekt${ids.length === 1 ? "" : "e"} mit allen Notizen und Aufgaben ` +
|
||||
"unwiderruflich loeschen?",
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await apply({ action: "delete" });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="pointer-events-none fixed inset-x-0 bottom-4 z-[90] flex justify-center px-4">
|
||||
<div className="popover pointer-events-auto flex flex-wrap items-center gap-2 px-3 py-2 shadow-2xl">
|
||||
<span className="px-1 text-sm tabular-nums text-slate-200">
|
||||
{ids.length} ausgewählt
|
||||
</span>
|
||||
|
||||
<span className="h-5 w-px bg-white/10" aria-hidden />
|
||||
|
||||
<button
|
||||
ref={statusRef}
|
||||
type="button"
|
||||
className="btn btn-ghost px-2.5 py-1.5 text-xs"
|
||||
onClick={() => setStatusOpen((value) => !value)}
|
||||
disabled={busy}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={statusOpen}
|
||||
>
|
||||
Status
|
||||
</button>
|
||||
<Popover
|
||||
open={statusOpen}
|
||||
anchorRef={statusRef}
|
||||
onClose={() => setStatusOpen(false)}
|
||||
align="start"
|
||||
>
|
||||
<div role="menu" className="min-w-[12rem] p-1">
|
||||
{STATUS_ORDER.map((status) => (
|
||||
<button
|
||||
key={status}
|
||||
type="button"
|
||||
role="menuitem"
|
||||
className="flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm text-slate-300 hover:bg-white/6"
|
||||
onClick={() => apply({ action: "status", status })}
|
||||
>
|
||||
<span
|
||||
className="h-2 w-2 rounded-full"
|
||||
style={{ backgroundColor: STATUS_META[status].color }}
|
||||
/>
|
||||
{STATUS_META[status].label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</Popover>
|
||||
|
||||
<button
|
||||
ref={tagsRef}
|
||||
type="button"
|
||||
className="btn btn-ghost px-2.5 py-1.5 text-xs"
|
||||
onClick={() => setTagsOpen((value) => !value)}
|
||||
disabled={busy}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={tagsOpen}
|
||||
>
|
||||
<Tag className="h-3.5 w-3.5" />
|
||||
Tags
|
||||
</button>
|
||||
<Popover open={tagsOpen} anchorRef={tagsRef} onClose={() => setTagsOpen(false)} align="start">
|
||||
<div className="w-64 space-y-2 p-3">
|
||||
<label className="field-label" htmlFor="bulk-tags">
|
||||
Tags (kommagetrennt)
|
||||
</label>
|
||||
<input
|
||||
id="bulk-tags"
|
||||
className="field"
|
||||
value={tagInput}
|
||||
onChange={(event) => setTagInput(event.target.value)}
|
||||
placeholder="experiment, archiv"
|
||||
autoFocus
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary flex-1 px-2 py-1.5 text-xs"
|
||||
disabled={busy || parseTags(tagInput).length === 0}
|
||||
onClick={() =>
|
||||
apply({ action: "tags", tags: parseTags(tagInput), tagMode: "add" })
|
||||
}
|
||||
>
|
||||
Hinzufügen
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost flex-1 px-2 py-1.5 text-xs"
|
||||
disabled={busy || parseTags(tagInput).length === 0}
|
||||
onClick={() =>
|
||||
apply({ action: "tags", tags: parseTags(tagInput), tagMode: "remove" })
|
||||
}
|
||||
>
|
||||
Entfernen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Popover>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost px-2.5 py-1.5 text-xs"
|
||||
onClick={() => apply({ action: "favorite", favorite: true })}
|
||||
disabled={busy}
|
||||
title="Als Favoriten markieren"
|
||||
>
|
||||
<Star className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost px-2.5 py-1.5 text-xs text-rose-200"
|
||||
onClick={remove}
|
||||
disabled={busy}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
Löschen
|
||||
</button>
|
||||
|
||||
{busy ? <Loader2 className="h-4 w-4 animate-spin text-slate-400" /> : null}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClear}
|
||||
className="rounded-lg p-1.5 text-slate-500 hover:text-white"
|
||||
aria-label="Auswahl aufheben"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
{error ? (
|
||||
<p className={cn("w-full px-1 text-xs text-rose-300")}>{error}</p>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import type { ProjectStatus } from "@prisma/client";
|
||||
import { BulkBar } from "@/components/BulkBar";
|
||||
import { ImportDialog } from "@/components/ImportDialog";
|
||||
import { KanbanBoard } from "@/components/KanbanBoard";
|
||||
import { ProjectCard } from "@/components/ProjectCard";
|
||||
@@ -54,6 +55,11 @@ function highlight(snippet: string): React.ReactNode[] {
|
||||
type SortKey = "updated" | "created" | "name" | "progress" | "priority";
|
||||
type ViewMode = "grid" | "grouped" | "kanban";
|
||||
|
||||
const VIEWS: ViewMode[] = ["grid", "grouped", "kanban"];
|
||||
|
||||
/** Wo Ansicht, Sortierung und Archivschalter im Browser liegen. */
|
||||
const ANSICHT_SCHLUESSEL = "nebula.board";
|
||||
|
||||
const SORT_LABEL: Record<SortKey, string> = {
|
||||
updated: "Zuletzt geaendert",
|
||||
created: "Neueste zuerst",
|
||||
@@ -74,11 +80,52 @@ export function ProjectBoard({
|
||||
const [sort, setSort] = useState<SortKey>("updated");
|
||||
const [view, setView] = useState<ViewMode>("grid");
|
||||
const [showArchived, setShowArchived] = useState(false);
|
||||
|
||||
/**
|
||||
* Ansicht und Sortierung ueberdauern das Neuladen.
|
||||
*
|
||||
* Wer sein Brett von Hand anordnet, will es beim naechsten Aufruf auch
|
||||
* sehen und nicht wieder das Raster. Bewusst erst nach dem ersten Rendern
|
||||
* gelesen: der Server kennt den gespeicherten Wert nicht, und ein
|
||||
* Unterschied zwischen beiden waere ein Hydrationsfehler.
|
||||
*
|
||||
* Der Suchbegriff bleibt aussen vor – eine Suche von gestern beim Oeffnen
|
||||
* wiederherzustellen waere eher verwirrend als hilfreich.
|
||||
*/
|
||||
useEffect(() => {
|
||||
try {
|
||||
const gespeichert = window.localStorage.getItem(ANSICHT_SCHLUESSEL);
|
||||
if (!gespeichert) return;
|
||||
const wert = JSON.parse(gespeichert) as Partial<{
|
||||
view: ViewMode;
|
||||
sort: SortKey;
|
||||
showArchived: boolean;
|
||||
}>;
|
||||
if (wert.view && VIEWS.includes(wert.view)) setView(wert.view);
|
||||
if (wert.sort && wert.sort in SORT_LABEL) setSort(wert.sort);
|
||||
if (typeof wert.showArchived === "boolean") setShowArchived(wert.showArchived);
|
||||
} catch {
|
||||
// Kaputter oder gesperrter Speicher: dann eben die Voreinstellung.
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
window.localStorage.setItem(
|
||||
ANSICHT_SCHLUESSEL,
|
||||
JSON.stringify({ view, sort, showArchived }),
|
||||
);
|
||||
} catch {
|
||||
// Im privaten Modus mancher Browser nicht beschreibbar – kein Grund,
|
||||
// die Seite scheitern zu lassen.
|
||||
}
|
||||
}, [view, sort, showArchived]);
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const [importOpen, setImportOpen] = useState(false);
|
||||
const [dataMenuOpen, setDataMenuOpen] = useState(false);
|
||||
const dataButtonRef = useRef<HTMLButtonElement>(null);
|
||||
const [noteHits, setNoteHits] = useState<NoteHit[]>([]);
|
||||
const [selection, setSelection] = useState<Set<string>>(new Set());
|
||||
|
||||
/**
|
||||
* Notizen liegen im Board nicht vor – sie mitzuladen wuerde die Seite
|
||||
@@ -174,6 +221,28 @@ export function ProjectBoard({
|
||||
})).filter((group) => group.items.length > 0);
|
||||
}, [visible]);
|
||||
|
||||
/**
|
||||
* Was der Filter ausblendet, bleibt nicht ausgewaehlt. Sonst traefe eine
|
||||
* Massenaenderung Projekte, die man gar nicht mehr vor Augen hat.
|
||||
*/
|
||||
useEffect(() => {
|
||||
setSelection((current) => {
|
||||
if (current.size === 0) return current;
|
||||
const sichtbar = new Set(visible.map((project) => project.id));
|
||||
const next = new Set([...current].filter((id) => sichtbar.has(id)));
|
||||
return next.size === current.size ? current : next;
|
||||
});
|
||||
}, [visible]);
|
||||
|
||||
function toggleSelect(id: string, selected: boolean) {
|
||||
setSelection((current) => {
|
||||
const next = new Set(current);
|
||||
if (selected) next.add(id);
|
||||
else next.delete(id);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
function toggleStatus(status: ProjectStatus) {
|
||||
setStatusFilter((current) =>
|
||||
current.includes(status)
|
||||
@@ -218,6 +287,14 @@ export function ProjectBoard({
|
||||
className="field w-auto min-w-[11rem]"
|
||||
value={sort}
|
||||
onChange={(event) => setSort(event.target.value as SortKey)}
|
||||
// Im Brett zaehlt die Anordnung von Hand. Die Sortierung hier
|
||||
// stehen zu lassen, ohne dass sie etwas bewirkt, waere irrefuehrend.
|
||||
disabled={view === "kanban"}
|
||||
title={
|
||||
view === "kanban"
|
||||
? "Im Brett bestimmt die Reihenfolge, in der du die Karten ablegst."
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{(Object.keys(SORT_LABEL) as SortKey[]).map((key) => (
|
||||
<option key={key} value={key}>
|
||||
@@ -388,11 +465,22 @@ export function ProjectBoard({
|
||||
{visible.length === 0 ? (
|
||||
<EmptyState hasFilters={hasFilters} onCreate={() => setDialogOpen(true)} />
|
||||
) : view === "kanban" ? (
|
||||
<KanbanBoard projects={visible} showArchived={showArchived} />
|
||||
<KanbanBoard
|
||||
projects={visible}
|
||||
showArchived={showArchived}
|
||||
selection={selection}
|
||||
onToggleSelect={toggleSelect}
|
||||
/>
|
||||
) : view === "grid" ? (
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{visible.map((project, index) => (
|
||||
<ProjectCard key={project.id} project={project} index={index} />
|
||||
<ProjectCard
|
||||
key={project.id}
|
||||
project={project}
|
||||
index={index}
|
||||
selected={selection.has(project.id)}
|
||||
onToggleSelect={toggleSelect}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
@@ -416,7 +504,13 @@ export function ProjectBoard({
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
{group.items.map((project, index) => (
|
||||
<ProjectCard key={project.id} project={project} index={index} />
|
||||
<ProjectCard
|
||||
key={project.id}
|
||||
project={project}
|
||||
index={index}
|
||||
selected={selection.has(project.id)}
|
||||
onToggleSelect={toggleSelect}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
@@ -425,6 +519,14 @@ export function ProjectBoard({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selection.size > 0 ? (
|
||||
<BulkBar
|
||||
ids={[...selection]}
|
||||
onDone={() => setSelection(new Set())}
|
||||
onClear={() => setSelection(new Set())}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<Popover
|
||||
anchorRef={dataButtonRef}
|
||||
open={dataMenuOpen}
|
||||
|
||||
@@ -29,7 +29,17 @@ const PROVIDER_LABEL: Record<string, string> = {
|
||||
* Karte im Board. Die gesamte Flaeche ist ein Link (per "stretched link"),
|
||||
* interaktive Elemente liegen darueber und bekommen pointer-events zurueck.
|
||||
*/
|
||||
export function ProjectCard({ project, index = 0 }: { project: ProjectListItem; index?: number }) {
|
||||
export function ProjectCard({
|
||||
project,
|
||||
index = 0,
|
||||
selected = false,
|
||||
onToggleSelect,
|
||||
}: {
|
||||
project: ProjectListItem;
|
||||
index?: number;
|
||||
selected?: boolean;
|
||||
onToggleSelect?: (id: string, selected: boolean) => void;
|
||||
}) {
|
||||
const accent = accentOf(project.accent);
|
||||
const priority = PRIORITY_META[project.priority] ?? PRIORITY_META[2];
|
||||
// Auf der Karte ist nur fuer eines Platz: das fuehrende. Wie viele es
|
||||
@@ -60,7 +70,10 @@ export function ProjectCard({ project, index = 0 }: { project: ProjectListItem;
|
||||
|
||||
return (
|
||||
<article
|
||||
className="glass card-glow fade-up group relative overflow-hidden p-5"
|
||||
className={cn(
|
||||
"glass card-glow fade-up group relative overflow-hidden p-5",
|
||||
selected && "ring-1 ring-violet-400/60",
|
||||
)}
|
||||
style={
|
||||
{
|
||||
"--accent-from": accent.from,
|
||||
@@ -81,6 +94,21 @@ export function ProjectCard({ project, index = 0 }: { project: ProjectListItem;
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
{/* Gedaempft, aber immer da. Nur beim Ueberfahren einzublenden
|
||||
waere auf einem Touchgeraet gar nicht erreichbar – und wer
|
||||
es nie sieht, weiss nicht, dass es die Auswahl gibt. */}
|
||||
{onToggleSelect ? (
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected}
|
||||
onChange={(event) => onToggleSelect(project.id, event.target.checked)}
|
||||
aria-label={`${project.name} auswaehlen`}
|
||||
className={cn(
|
||||
"pointer-events-auto h-3.5 w-3.5 shrink-0 accent-violet-500 transition-opacity",
|
||||
!selected && "opacity-35 group-hover:opacity-100 focus-visible:opacity-100",
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
<h3 className="truncate text-base font-semibold text-white transition-colors group-hover:text-violet-200">
|
||||
{project.name}
|
||||
</h3>
|
||||
|
||||
Reference in New Issue
Block a user