import { DndContext, closestCenter, MouseSensor, TouchSensor, useSensor, useSensors, DragEndEvent } from "@dnd-kit/core"; import { arrayMove, SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { Resource } from "@/types/proto/api/v1/resource_service"; import Icon from "../Icon"; import ResourceIcon from "../ResourceIcon"; import SortableItem from "./SortableItem"; interface Props { resourceList: Resource[]; setResourceList: (resourceList: Resource[]) => void; } const ResourceListView = (props: Props) => { const { resourceList, setResourceList } = props; const sensors = useSensors(useSensor(MouseSensor), useSensor(TouchSensor)); const handleDeleteResource = async (name: string) => { setResourceList(resourceList.filter((resource) => resource.name !== name)); }; const handleDragEnd = (event: DragEndEvent) => { const { active, over } = event; if (over && active.id !== over.id) { const oldIndex = resourceList.findIndex((resource) => resource.name === active.id); const newIndex = resourceList.findIndex((resource) => resource.name === over.id); setResourceList(arrayMove(resourceList, oldIndex, newIndex)); } }; return ( resource.name)} strategy={verticalListSortingStrategy}> {resourceList.length > 0 && (
{resourceList.map((resource) => { return (
{resource.filename}
); })}
)}
); }; export default ResourceListView;