import React, { useRef, useEffect } from 'react'; import { DotCircle } from 'shared/icons'; import { EntryChildren, EntryWrapper, EntryContent, EntryInnerContent, EntryHandle } from './Styles'; import { useDrag } from './useDrag'; type EntryProps = { id: string; parentID: string; onStartDrag: (e: { id: string; clientX: number; clientY: number }) => void; isRoot?: boolean; draggingID: null | string; entries: Array; position: number; chain?: Array; depth?: number; }; const Entry: React.FC = ({ id, parentID, isRoot = false, position, onStartDrag, draggingID, entries, chain = [], depth = 0, }) => { const $entry = useRef(null); const $children = useRef(null); const { setNodeDimensions } = useDrag(); useEffect(() => { if (isRoot) return; if ($entry && $entry.current) { setNodeDimensions(id, { entry: $entry, children: entries.length !== 0 ? $children : null, }); } }, [position, depth, entries]); let showHandle = true; if (draggingID && draggingID === id) { showHandle = false; } return ( {!isRoot && ( {showHandle && ( onStartDrag({ id, clientX: e.clientX, clientY: e.clientY })}> )} {id.toString()} )} {entries.length !== 0 && ( {entries .sort((a, b) => a.position - b.position) .map(entry => ( ))} )} ); }; export default Entry;