2021-06-21 21:35:28 +00:00
|
|
|
import { useSelector } from 'state'
|
2021-07-11 07:03:20 +00:00
|
|
|
import { ShapeTreeNode } from 'types'
|
2021-07-09 20:04:41 +00:00
|
|
|
import ShapeComponent from './shape'
|
2021-05-09 21:22:25 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export default function Page(): JSX.Element {
|
2021-07-11 07:03:20 +00:00
|
|
|
const shapesToRender = useSelector((s) => s.values.shapesToRender)
|
2021-07-11 12:51:01 +00:00
|
|
|
|
2021-07-11 07:03:20 +00:00
|
|
|
const allowHovers = useSelector((s) =>
|
|
|
|
s.isInAny('selecting', 'text', 'editingShape')
|
|
|
|
)
|
2021-06-28 12:13:34 +00:00
|
|
|
|
2021-05-09 21:22:25 +00:00
|
|
|
return (
|
2021-07-09 16:15:27 +00:00
|
|
|
<>
|
2021-07-11 07:03:20 +00:00
|
|
|
{shapesToRender.map((node) => (
|
|
|
|
<ShapeNode key={node.shape.id} node={node} allowHovers={allowHovers} />
|
2021-07-09 16:15:27 +00:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-09 20:04:41 +00:00
|
|
|
interface ShapeNodeProps {
|
2021-07-11 07:03:20 +00:00
|
|
|
node: ShapeTreeNode
|
|
|
|
allowHovers: boolean
|
2021-07-09 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 20:04:41 +00:00
|
|
|
const ShapeNode = ({
|
2021-07-10 20:39:29 +00:00
|
|
|
node: {
|
|
|
|
shape,
|
|
|
|
children,
|
|
|
|
isEditing,
|
|
|
|
isHovered,
|
|
|
|
isDarkMode,
|
|
|
|
isSelected,
|
|
|
|
isCurrentParent,
|
|
|
|
},
|
2021-07-11 07:03:20 +00:00
|
|
|
allowHovers,
|
2021-07-09 20:04:41 +00:00
|
|
|
}: ShapeNodeProps) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ShapeComponent
|
|
|
|
shape={shape}
|
|
|
|
isEditing={isEditing}
|
2021-07-11 07:03:20 +00:00
|
|
|
isHovered={allowHovers && isHovered}
|
2021-07-09 20:04:41 +00:00
|
|
|
isSelected={isSelected}
|
2021-07-10 20:39:29 +00:00
|
|
|
isDarkMode={isDarkMode}
|
2021-07-09 20:04:41 +00:00
|
|
|
isCurrentParent={isCurrentParent}
|
|
|
|
/>
|
|
|
|
{children.map((childNode) => (
|
2021-07-11 07:03:20 +00:00
|
|
|
<ShapeNode
|
|
|
|
key={childNode.shape.id}
|
|
|
|
node={childNode}
|
|
|
|
allowHovers={allowHovers}
|
|
|
|
/>
|
2021-07-09 20:04:41 +00:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|