import { FC } from 'react'; import { useDrop, XYCoord } from 'react-dnd'; import { connect } from 'react-redux'; import { MappingContainer } from '../styles/Mapping'; import { Circle } from './Circle'; import { Image } from './Image'; import { Line } from './Line'; import { Square } from './Square'; export interface ContainerProps { dispatch: any; items: Array; } export const ContainerComponent: FC = ({ dispatch, items }) => { const [, drop] = useDrop({ accept: ['SQUARE', 'CIRCLE', 'LINE', 'IMAGE'], drop(item: any, monitor) { const delta = monitor.getDifferenceFromInitialOffset() as XYCoord; const left = Math.round(item.left + delta.x); const top = Math.round(item.top + delta.y); dispatch({ type: 'UPDATE_POSITION', object: item.type, index: item.id, left, top }) } }); return( { items.map((item, id) => { switch (item.type) { case 'SQUARE': return( ) case 'CIRCLE': return( ) case 'LINE': return( ) case 'IMAGE': return( ) default: return(
) } }) } ) } export const Container = connect( (state: any) => ({ items: state.items, }) )(ContainerComponent);