import React, { useState, useEffect, useRef } from 'react'; import type { GeIdItem } from './QueueStatus'; import DragHandleIcon from './DragHandleIcon'; interface QueueManagementModalProps { isOpen: boolean; onClose: () => void; queueItems: GeIdItem[]; onReorder: (reorderedItems: GeIdItem[]) => void; onDelete: (key: string) => void; } const QueueManagementModal: React.FC = ({ isOpen, onClose, queueItems, onReorder, onDelete, }) => { const [localItems, setLocalItems] = useState([]); const dragItem = useRef(null); const dragOverItem = useRef(null); useEffect(() => { if (isOpen) { document.body.style.overflow = 'hidden'; setLocalItems(queueItems.filter(item => item.status === 'waiting')); } else { document.body.style.overflow = 'auto'; } return () => { document.body.style.overflow = 'auto'; }; }, [isOpen, queueItems]); if (!isOpen) { return null; } const handleDragStart = (e: React.DragEvent, position: number) => { dragItem.current = position; e.dataTransfer.effectAllowed = 'move'; // Add a delay to allow the ghost image to be created before styling setTimeout(() => { e.currentTarget.classList.add('dragging'); }, 0) }; const handleDragEnter = (e: React.DragEvent, position: number) => { dragOverItem.current = position; }; const handleDrop = (e: React.DragEvent) => { if (dragItem.current === null || dragOverItem.current === null) return; const newItems = [...localItems]; const dragItemContent = newItems[dragItem.current]; newItems.splice(dragItem.current, 1); newItems.splice(dragOverItem.current, 0, dragItemContent); dragItem.current = null; dragOverItem.current = null; setLocalItems(newItems); onReorder(newItems); // Update parent state }; const handleDragEnd = (e: React.DragEvent) => { e.currentTarget.classList.remove('dragging'); } return (
e.stopPropagation()} >

Quản lý Hàng đợi

{localItems.length > 0 ? (
{localItems.map((item, index) => (
handleDragStart(e, index)} onDragEnter={(e) => handleDragEnter(e, index)} onDragEnd={handleDragEnd} onDragOver={(e) => e.preventDefault()} onDrop={handleDrop} >
{item.id} ({item.lang})
{item.usernames}
))}
) : (

Không có submit nào đang chờ.

)}
); }; export default QueueManagementModal;