"use client"; import { useState } from "react"; import { DndContext, DragOverlay, PointerSensor, TouchSensor, useSensor, useSensors, useDraggable, useDroppable, type DragEndEvent } from "@dnd-kit/core"; import { Plus } from "lucide-react"; import { Empty } from "@/components/ui/primitives"; import { cn } from "@/lib/utils"; import type { RowOut } from "@/lib/databases/types"; import { isEmpty } from "@/lib/databases/values"; import { useDb } from "../hooks"; import { CellDisplay } from "../cells/Cell"; import { groupRows, type Group } from "../group"; import { OPTION_CLASS } from "../colors"; export function BoardView() { const ctx = useDb(); const gb = ctx.props.find((p) => p.id === ctx.view.config.groupBy); const [active, setActive] = useState(null); const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } }), useSensor(TouchSensor, { activationConstraint: { delay: 150, tolerance: 6 } })); if (!gb) return ; const groups = groupRows(ctx.rows, gb); const onDragEnd = (e: DragEndEvent) => { setActive(null); const { active, over } = e; if (!over) return; const g = groups.find((x) => x.key === over.id); const row = ctx.rows.find((r) => r.id === active.id); if (!g || !row) return; if ((row.values[gb.id] ?? null) !== (g.value ?? null)) ctx.setCell(row.id, { [gb.id]: g.value ?? null }); }; return ( setActive(ctx.rows.find((r) => r.id === e.active.id) ?? null)} onDragEnd={onDragEnd} onDragCancel={() => setActive(null)}>
{groups.map((g) => ctx.addRow(g.value === undefined ? {} : { [gb.id]: g.value })} />)}
{active ? : null}
); } function Column({ g, onAdd }: { g: Group; onAdd: () => void }) { const { setNodeRef, isOver } = useDroppable({ id: g.key }); return (
{g.label}{g.rows.length}
{g.rows.map((r) => )}
); } function Draggable({ row }: { row: RowOut }) { const { attributes, listeners, setNodeRef, isDragging } = useDraggable({ id: row.id }); return
; } export function Card({ row, overlay }: { row: RowOut; overlay?: boolean }) { const ctx = useDb(); const gb = ctx.view.config.groupBy; const props = ctx.visibleProps.filter((p) => p.type !== "title" && p.id !== gb && !isEmpty(row.values[p.id])).slice(0, 4); return (
!overlay && ctx.open(row.id)} className={cn("cursor-pointer rounded-md border border-line bg-bg-elev p-2.5 shadow-card transition-shadow hover:shadow-pop", overlay && "rotate-1 shadow-pop")}>
{row.icon ? `${row.icon} ` : ""}{row.title || Untitled}
{props.length > 0 &&
{props.map((p) =>
)}
}
); }