2021-05-09 21:22:25 +00:00
|
|
|
import { useSelector } from "state"
|
2021-05-22 15:45:24 +00:00
|
|
|
import { deepCompareArrays, getPage } from "utils/utils"
|
2021-05-09 21:22:25 +00:00
|
|
|
import Shape from "./shape"
|
|
|
|
|
|
|
|
/*
|
|
|
|
On each state change, compare node ids of all shapes
|
|
|
|
on the current page. Kind of expensive but only happens
|
|
|
|
here; and still cheaper than any other pattern I've found.
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default function Page() {
|
2021-05-23 13:46:04 +00:00
|
|
|
const currentPageShapeIds = useSelector(({ data }) => {
|
|
|
|
return Object.values(getPage(data).shapes)
|
|
|
|
.sort((a, b) => a.childIndex - b.childIndex)
|
|
|
|
.map((shape) => shape.id)
|
|
|
|
}, deepCompareArrays)
|
2021-05-09 21:22:25 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{currentPageShapeIds.map((shapeId) => (
|
|
|
|
<Shape key={shapeId} id={shapeId} />
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|