import { DragDropContext, Draggable, Droppable } from '@hello-pangea/dnd'; import { List } from '@/components/list'; import useAdmin from '@/hook/useAdmin'; function reorder(list, startIndex, endIndex) { const result = Array.from(list); const [removed] = result.splice(startIndex, 1); result.splice(endIndex, 0, removed); return result; }; function TeamManagerItem({ team, index }) { const { updateTeam, removeTeam } = useAdmin(); function handleRemove() { removeTeam(team.id); } return ( {provided => ( {team.name} {String(team.id).padStart(6, '0').replace(/(\d{3})(\d{3})/, "$1 $2")} updateTeam(team.id, { captured: !team.captured })} /> )} ); } export default function TeamManager() { const { teams, reorderTeams } = useAdmin(); function onDragEnd(result) { if (!result.destination) return; if (result.destination.index === result.source.index) return; const newTeams = reorder(teams, result.source.index, result.destination.index); reorderTeams(newTeams); } return ( {provided => ( {(team, i) => ( )} {provided.placeholder} )} ); }
{team.name}
{String(team.id).padStart(6, '0').replace(/(\d{3})(\d{3})/, "$1 $2")}