import type { ComponentPropsWithoutRef, ReactNode } from "react"; import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core"; import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { GripVertical, PinOff } from "lucide-react"; import { RecentTaskNavItem } from "./RecentTaskNavItem"; import { SidebarNavItem } from "./SidebarNavItem"; import { cn } from "@/lib/utils"; import type { Project } from "@paperclipai/shared"; import { SidebarProjectTasks } from "./SidebarProjectTasks"; export interface PinnedNavigationItem { key: string; to: string; label: string; icon: ReactNode; task?: { id: string; identifier: string | null; isUnreadForMe?: boolean }; project?: Pick; } /** Keep this row mounted when a pin is toggled so its controls retain focus. */ export function SortablePinnedRow({ id, label, disabled = false, className, handleClassName, handleIconClassName, children, ...props }: Omit, "id" | "children"> & { id: string; label: string; disabled?: boolean; handleClassName: string; handleIconClassName: string; children: ReactNode | ((handle: ReactNode) => ReactNode); }) { const sortable = useSortable({ id, disabled, transition: null }); const handle = !disabled && ; return
event.preventDefault()}> {typeof children === "function" ? children(handle) : <>{children}{handle}}
; } function PinnedItem({ item, userId, onUnpin }: { item: PinnedNavigationItem; userId?: string | null; onUnpin: (key: string) => void }) { const link = { to: item.to, label: item.label, iconNode: item.icon, className: "design-sidebar-item design-sidebar-pinned-item group-hover/coordinator-pin:bg-sidebar-accent" }; const row = (handle: ReactNode) => <> {item.task ? : } {handle} ; return {handle => item.project ? {row(handle)} : row(handle)} ; } export function SortablePinnedList({ keys, onReorder, children }: { keys: string[]; onReorder?: (keys: string[]) => void; children: ReactNode; }) { const sensors = useSensors( useSensor(PointerSensor, { activationConstraint: { distance: 8 } }), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), ); function move({ active, over }: DragEndEvent) { if (!over || active.id === over.id) return; const from = keys.indexOf(String(active.id)), to = keys.indexOf(String(over.id)); if (from >= 0 && to >= 0) onReorder?.(arrayMove(keys, from, to)); } return {children} ; } export function PinnedNavigationList({ items, userId, onReorder, onUnpin }: { items: PinnedNavigationItem[]; userId?: string | null; onReorder: (keys: string[]) => void; onUnpin: (key: string) => void; }) { return item.key)} onReorder={onReorder}> {items.map(item => )} ; }