import { DndContext, closestCenter, MouseSensor, TouchSensor, useSensor, useSensors, DragEndEvent } from "@dnd-kit/core"; import { arrayMove, SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { XIcon } from "lucide-react"; import { Attachment } from "@/types/proto/api/v1/attachment_service"; import AttachmentIcon from "../AttachmentIcon"; import SortableItem from "./SortableItem"; interface Props { attachmentList: Attachment[]; setAttachmentList: (attachmentList: Attachment[]) => void; } const AttachmentListView = (props: Props) => { const { attachmentList, setAttachmentList } = props; const sensors = useSensors(useSensor(MouseSensor), useSensor(TouchSensor)); const handleDeleteAttachment = async (name: string) => { setAttachmentList(attachmentList.filter((attachment) => attachment.name !== name)); }; const handleDragEnd = (event: DragEndEvent) => { const { active, over } = event; if (over && active.id !== over.id) { const oldIndex = attachmentList.findIndex((attachment) => attachment.name === active.id); const newIndex = attachmentList.findIndex((attachment) => attachment.name === over.id); setAttachmentList(arrayMove(attachmentList, oldIndex, newIndex)); } }; return ( attachment.name)} strategy={verticalListSortingStrategy}> {attachmentList.length > 0 && (
{attachmentList.map((attachment) => { return (
{attachment.filename}
); })}
)}
); }; export default AttachmentListView;