From 6d73b1aed898565f4799b6866bc313911968f4b2 Mon Sep 17 00:00:00 2001 From: Hristo Nedelkov Date: Thu, 7 Mar 2024 13:03:38 +0200 Subject: [PATCH] feat(node list): make nodes dragable --- .../General/RightSideBar/NodesList.tsx | 106 +++++++----------- 1 file changed, 42 insertions(+), 64 deletions(-) diff --git a/src/components/General/RightSideBar/NodesList.tsx b/src/components/General/RightSideBar/NodesList.tsx index 46b6dd1c..677d1163 100644 --- a/src/components/General/RightSideBar/NodesList.tsx +++ b/src/components/General/RightSideBar/NodesList.tsx @@ -1,72 +1,50 @@ +import { useState } from 'react' +import { DndProvider } from 'react-dnd' +import { HTML5Backend } from 'react-dnd-html5-backend' +import { YStack } from 'tamagui' + import { Text } from '@status-im/components' -import { DragIcon, StatusIcon, ChevronRightIcon } from '@status-im/icons' -import { Stack, Tooltip, XStack, YStack } from 'tamagui' -import Icon from '../Icon' +import DraggableNode from './DragableNode' +interface NodeItem { + id: string + content: string +} + +const initialNodes: NodeItem[] = [ + { id: 'item-0', content: 'Nickname 0' }, + { id: 'item-1', content: 'Nickname 1' }, + { id: 'item-2', content: 'Nickname 2' }, +] const NodesList = () => { - return ( - - - Nodes - - - {Array.from(Array(3).keys()).map(e => { - return ( - - - - - - - Nickname {e} - - - Validators - - - + const [nodes, setNodes] = useState(initialNodes) - - - - - - - - - - - - Client Name - - - Host Name - - - - - - - ) - })} + const moveNode = (dragIndex: number, hoverIndex: number) => { + const dragNode = nodes[dragIndex] + const newNodes = [...nodes] + newNodes.splice(dragIndex, 1) + newNodes.splice(hoverIndex, 0, dragNode) + setNodes(newNodes) + } + + return ( + + + + Nodes + + {nodes.map((node, index) => ( + + ))} - + ) } + export default NodesList