feat(node list): make nodes dragable

This commit is contained in:
Hristo Nedelkov 2024-03-07 13:03:38 +02:00 committed by Emil Ivanichkov
parent 7e9b5b161c
commit 6d73b1aed8
1 changed files with 42 additions and 64 deletions

View File

@ -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 { Text } from '@status-im/components'
import { DragIcon, StatusIcon, ChevronRightIcon } from '@status-im/icons' import DraggableNode from './DragableNode'
import { Stack, Tooltip, XStack, YStack } from 'tamagui' interface NodeItem {
import Icon from '../Icon' 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 = () => { const NodesList = () => {
const [nodes, setNodes] = useState<NodeItem[]>(initialNodes)
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 ( return (
<YStack backgroundColor={'#fff'} padding="18px" borderRadius={25}> <DndProvider backend={HTML5Backend}>
<YStack backgroundColor="#fff" padding="18px" borderRadius={25}>
<Text size={15} color="#647084" weight="semibold"> <Text size={15} color="#647084" weight="semibold">
Nodes Nodes
</Text> </Text>
<YStack padding="$2" space="$3"> {nodes.map((node, index) => (
{Array.from(Array(3).keys()).map(e => { <DraggableNode
return ( key={node.id}
<XStack id={node.id}
alignContent="center" content={node.content}
alignItems="center" index={index}
justifyContent="space-between" moveNode={moveNode}
width={'250px'} />
backgroundColor={'#FAFBFC'} ))}
borderRadius={15}
>
<XStack
space="$3"
alignContent="center"
alignItems="center"
padding="8px"
>
<DragIcon size={20} color="#09101C"></DragIcon>
<StatusIcon size={20}></StatusIcon>
<YStack>
<Text size={15} weight="semibold">
Nickname {e}
</Text>
<Text size={13} color="#647084">
Validators
</Text>
</YStack>
</XStack>
<Tooltip>
<Tooltip.Trigger>
<Stack padding="3px">
<ChevronRightIcon size={20}></ChevronRightIcon>
</Stack>
</Tooltip.Trigger>
<Tooltip.Content>
<XStack alignContent="center" alignItems="center" space="$1">
<Icon
src="icons/tooltipIcon.png"
width={22}
height={22}
></Icon>
<YStack space="$2">
<Text size={15} weight="semibold">
Client Name
</Text>
<Text size={15} weight="semibold">
Host Name
</Text>
</YStack>
</XStack>
</Tooltip.Content>
</Tooltip>
</XStack>
)
})}
</YStack>
</YStack> </YStack>
</DndProvider>
) )
} }
export default NodesList export default NodesList