Add drag-and-drop project reordering to the sidebar #185
Mergedjuliusmarmingemerged 7 commits into
main fromrefs/pull/185/headmerged by juliusmarminge View on GitHub- apps/web/src/components/Sidebar.tsx line 251Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -259,0 +276,21 @@276+ children,277+}: {278+ projectId: ProjectId;279+ children: (handleProps: SortableProjectHandleProps) => React.ReactNode;280+}) {281+ const { attributes, listeners, setNodeRef, transform, transition, isDragging, isOver } =282+ useSortable({ id: projectId });283+ return (284+ <div285+ ref={setNodeRef}286+ style={{287+ transform: CSS.Translate.toString(transform),288+ transition,289+ }}290+ className={`rounded-md ${291+ isDragging ? "z-20 opacity-80" : ""292+ } ${isOver && !isDragging ? "ring-1 ring-primary/40" : ""}`}293+ >294+ {children({ attributes, listeners })}295+ </div>296+ );
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
@@ -127,5 +145,14 @@127145 ? persistedExpandedProjectCwds.has(project.workspaceRoot)128146 : true),129147 scripts: project.scripts.map((script) => ({ ...script })),130- };148+ } satisfies Project;131149 });150+151+ return mappedProjects152+ .map((project, incomingIndex) => {153+ const previousIndex = previousOrderById.get(project.id) ?? previousOrderByCwd.get(project.cwd);154+ const persistedIndex = usePersistedOrder ? persistedOrderByCwd.get(project.cwd) : undefined;155+ const orderIndex =156+ previousIndex ??157+ persistedIndex ??158+ (usePersistedOrder ? persistedProjectOrderCwds.length : previous.length) + incomingIndex;apps/web/src/components/Sidebar.tsx line 875Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -793,0 +856,21 @@856+ (event: DragEndEvent) => {857+ dragInProgressRef.current = false;858+ const { active, over } = event;859+ if (!over || active.id === over.id) return;860+ const activeProject = projects.find((project) => project.id === active.id);861+ const overProject = projects.find((project) => project.id === over.id);862+ if (!activeProject || !overProject) return;863+ reorderProjects(activeProject.id, overProject.id);864+ },865+ [projects, reorderProjects],866+ );867+868+ const handleProjectDragStart = useCallback((_event: DragStartEvent) => {869+ dragInProgressRef.current = true;870+ suppressProjectClickAfterDragRef.current = true;871+ }, []);872+873+ const handleProjectDragCancel = useCallback((_event: DragCancelEvent) => {874+ dragInProgressRef.current = false;875+ suppressProjectClickAfterDragRef.current = false;876+ }, []);juliusmarminge merged this9fb9467
juliusmarminge closed this
@@ -127,5 +145,14 @@127145 ? persistedExpandedProjectCwds.has(project.workspaceRoot)128146 : true),129147 scripts: project.scripts.map((script) => ({ ...script })),130- };148+ } satisfies Project;131149 });150+151+ return mappedProjects152+ .map((project, incomingIndex) => {153+ const previousIndex = previousOrderById.get(project.id) ?? previousOrderByCwd.get(project.cwd);154+ const persistedIndex = usePersistedOrder ? persistedOrderByCwd.get(project.cwd) : undefined;155+ const orderIndex =156+ previousIndex ??157+ persistedIndex ??158+ (usePersistedOrder ? persistedProjectOrderCwds.length : previous.length) + incomingIndex;
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
82de4b9a-1b6e-4109-9149-c152af40ab9fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.