import React, { useState } from 'react'; import { Grid } from '@mantine/core'; import { closestCenter, DndContext, DragOverlay, MouseSensor, useSensor, useSensors, } from '@dnd-kit/core'; import { arrayMove, SortableContext } from '@dnd-kit/sortable'; import { useConfig } from '../../tools/state'; import { SortableAppShelfItem, AppShelfItem } from './AppShelfItem'; const AppShelf = (props: any) => { const [activeId, setActiveId] = useState(null); const { config, setConfig } = useConfig(); const sensors = useSensors( useSensor(MouseSensor, { // Require the mouse to move by 10 pixels before activating activationConstraint: { delay: 250, tolerance: 5, }, }) ); function handleDragStart(event: any) { const { active } = event; setActiveId(active.id); } function handleDragEnd(event: any) { const { active, over } = event; if (active.id !== over.id) { const newConfig = { ...config }; const activeIndex = newConfig.services.findIndex((e) => e.id === active.id); const overIndex = newConfig.services.findIndex((e) => e.id === over.id); newConfig.services = arrayMove(newConfig.services, activeIndex, overIndex); setConfig(newConfig); } setActiveId(null); } return ( {config.services.map((service) => ( ))} {activeId ? ( e.id === activeId)} id={activeId} /> ) : null} ); }; export default AppShelf;