mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
Extract 3 simple hooks with no UI dependencies: - use-theme-preview.ts: Debounced theme preview on hover - use-sidebar-auto-collapse.ts: Auto-collapse on small screens - use-drag-and-drop.ts: Project reordering drag-and-drop Benefits: - Reduced sidebar.tsx by 88 lines (-4%) - Improved testability (hooks can be tested in isolation) - Removed unused imports (DragEndEvent, PointerSensor, useSensor, useSensors) - Created hooks/ barrel export pattern Next steps: Extract 10+ remaining hooks and 10+ UI sections to reach target of 200-300 lines (current: 2099 lines, need to reduce ~1800 more) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { useSensors, useSensor, PointerSensor, type DragEndEvent } from '@dnd-kit/core';
|
|
import type { Project } from '@/lib/electron';
|
|
|
|
interface UseDragAndDropProps {
|
|
projects: Project[];
|
|
reorderProjects: (oldIndex: number, newIndex: number) => void;
|
|
}
|
|
|
|
export function useDragAndDrop({ projects, reorderProjects }: UseDragAndDropProps) {
|
|
// Sensors for drag-and-drop
|
|
const sensors = useSensors(
|
|
useSensor(PointerSensor, {
|
|
activationConstraint: {
|
|
distance: 5, // Small distance to start drag
|
|
},
|
|
})
|
|
);
|
|
|
|
// Handle drag end for reordering projects
|
|
const handleDragEnd = useCallback(
|
|
(event: DragEndEvent) => {
|
|
const { active, over } = event;
|
|
|
|
if (over && active.id !== over.id) {
|
|
const oldIndex = projects.findIndex((p) => p.id === active.id);
|
|
const newIndex = projects.findIndex((p) => p.id === over.id);
|
|
|
|
if (oldIndex !== -1 && newIndex !== -1) {
|
|
reorderProjects(oldIndex, newIndex);
|
|
}
|
|
}
|
|
},
|
|
[projects, reorderProjects]
|
|
);
|
|
|
|
return {
|
|
sensors,
|
|
handleDragEnd,
|
|
};
|
|
}
|