The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { CollapsibleSectionHeader } from "../ui/collapsible-section-header"; |
| 2 | import { useSortable } from "@dnd-kit/sortable"; |
| 3 | import { CSS } from "@dnd-kit/utilities"; |
| 4 | import { type ReactNode, useLayoutEffect } from "react"; |
| 5 | import { cn } from "~/lib/utils"; |
| 6 | import { |
| 7 | animateSidebarLayoutChanges, |
| 8 | sidebarMarkerId, |
| 9 | type SidebarListMarker, |
| 10 | } from "../Sidebar.logic"; |
| 11 | import { SIDEBAR_SORTABLE_DRAG_DISABLED } from "./SidebarThreadRow"; |
| 12 | |
| 13 | function SortableSidebarMarker(props: { |
| 14 | marker: SidebarListMarker; |
| 15 | className?: string; |
| 16 | children?: ReactNode; |
| 17 | revealOverflow?: boolean; |
| 18 | "data-testid"?: string; |
| 19 | }) { |
| 20 | const { node, setNodeRef, transform, transition } = useSortable({ |
| 21 | id: sidebarMarkerId(props.marker), |
| 22 | disabled: SIDEBAR_SORTABLE_DRAG_DISABLED, |
| 23 | animateLayoutChanges: animateSidebarLayoutChanges, |
| 24 | }); |
| 25 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- keeps the projected drop box inside the scroll viewport as drag transforms move it |
| 26 | useLayoutEffect(() => { |
| 27 | if (props.revealOverflow && transform?.y !== undefined) { |
| 28 | node.current?.firstElementChild?.scrollIntoView({ block: "nearest", inline: "nearest" }); |
| 29 | } |
| 30 | }, [node, props.revealOverflow, transform?.y]); |
| 31 | return ( |
| 32 | <li |
| 33 | ref={setNodeRef} |
| 34 | data-thread-selection-safe |
| 35 | data-testid={props["data-testid"]} |
| 36 | className={cn("list-none", props.className)} |
| 37 | style={{ |
| 38 | transform: CSS.Translate.toString(transform), |
| 39 | transition: props.marker.endsWith("-placeholder") ? "none" : transition, |
| 40 | visibility: transform?.scaleY === 0 ? "hidden" : undefined, |
| 41 | }} |
| 42 | > |
| 43 | {props.children} |
| 44 | </li> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | export function SidebarSectionPlaceholder(props: { |
| 49 | marker: "active-placeholder" | "settled-placeholder"; |
| 50 | label: string; |
| 51 | showHint: boolean; |
| 52 | isDropTarget: boolean; |
| 53 | }) { |
| 54 | return ( |
| 55 | <SortableSidebarMarker |
| 56 | marker={props.marker} |
| 57 | data-testid={`sidebar-${props.marker}`} |
| 58 | className="relative mx-0.5 -mb-px h-0" |
| 59 | // Revealing on every drag scrolls the list out from under the pointer. |
| 60 | revealOverflow={ |
| 61 | props.marker === "settled-placeholder" && props.showHint && props.isDropTarget |
| 62 | } |
| 63 | > |
| 64 | {props.showHint ? ( |
| 65 | <div |
| 66 | className={cn( |
| 67 | "absolute inset-x-0 top-0 flex h-9 items-center justify-center rounded-md border border-dashed border-sidebar-foreground/25 text-xs text-sidebar-foreground/80", |
| 68 | props.isDropTarget && "border-primary/40 bg-primary/5 text-primary", |
| 69 | )} |
| 70 | > |
| 71 | {props.label} |
| 72 | </div> |
| 73 | ) : null} |
| 74 | </SortableSidebarMarker> |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | export function SidebarDragBoundary(props: { |
| 79 | marker: "pinned-header" | "pinned-divider"; |
| 80 | label: string; |
| 81 | visible: boolean; |
| 82 | isDropTarget: boolean; |
| 83 | }) { |
| 84 | return ( |
| 85 | <SortableSidebarMarker |
| 86 | marker={props.marker} |
| 87 | data-testid={`sidebar-${props.marker}`} |
| 88 | className="pointer-events-none relative mx-0.5 -mb-px h-0" |
| 89 | > |
| 90 | {props.visible ? ( |
| 91 | <div className="sidebar-drag-boundary-label absolute inset-x-2 top-1 flex h-4 items-center gap-2"> |
| 92 | <span |
| 93 | className={cn( |
| 94 | "shrink-0 text-xs font-medium", |
| 95 | props.isDropTarget ? "text-primary" : "text-sidebar-foreground/80", |
| 96 | )} |
| 97 | > |
| 98 | {props.label} |
| 99 | </span> |
| 100 | <span |
| 101 | aria-hidden |
| 102 | className={cn( |
| 103 | "h-px flex-1", |
| 104 | props.isDropTarget ? "bg-primary/50" : "bg-sidebar-foreground/25", |
| 105 | )} |
| 106 | /> |
| 107 | </div> |
| 108 | ) : null} |
| 109 | </SortableSidebarMarker> |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | export function SidebarSectionHeader(props: { |
| 114 | marker: "working-header" | "snoozed-header" | "settled-header"; |
| 115 | label: string; |
| 116 | /** A muted trailing count. */ |
| 117 | count: number; |
| 118 | className?: string; |
| 119 | dragging?: boolean; |
| 120 | isDropTarget?: boolean; |
| 121 | toggle: { expanded: boolean; onToggle: () => void }; |
| 122 | }) { |
| 123 | const shelf = |
| 124 | props.marker === "working-header" |
| 125 | ? "working" |
| 126 | : props.marker === "snoozed-header" |
| 127 | ? "snoozed" |
| 128 | : "settled"; |
| 129 | return ( |
| 130 | <SortableSidebarMarker |
| 131 | marker={props.marker} |
| 132 | data-testid={`sidebar-${props.marker}`} |
| 133 | className={cn("relative mx-0.5 h-8", props.className)} |
| 134 | > |
| 135 | <CollapsibleSectionHeader |
| 136 | data-sidebar-row={`shelf:${shelf}`} |
| 137 | onClick={props.toggle.onToggle} |
| 138 | expanded={props.toggle.expanded} |
| 139 | tone={props.isDropTarget ? "accent" : props.dragging ? "emphasized" : "muted"} |
| 140 | data-testid={`sidebar-${shelf}-shelf-toggle`} |
| 141 | accessory={<span className="font-normal tabular-nums">{props.count}</span>} |
| 142 | > |
| 143 | {props.label} |
| 144 | </CollapsibleSectionHeader> |
| 145 | </SortableSidebarMarker> |
| 146 | ); |
| 147 | } |