You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

page.tsx 917B

12345678910111213141516171819202122232425262728293031
  1. import { useSelector } from 'state'
  2. import Shape from './shape'
  3. import HoveredShape from './hovered-shape'
  4. import usePageShapes from 'hooks/usePageShapes'
  5. /*
  6. On each state change, compare node ids of all shapes
  7. on the current page. Kind of expensive but only happens
  8. here; and still cheaper than any other pattern I've found.
  9. */
  10. export default function Page(): JSX.Element {
  11. const isSelecting = useSelector((s) => s.isIn('selecting'))
  12. const visiblePageShapeIds = usePageShapes()
  13. const hoveredShapeId = useSelector((s) => {
  14. return visiblePageShapeIds.find((id) => id === s.data.hoveredId)
  15. })
  16. return (
  17. <g pointerEvents={isSelecting ? 'all' : 'none'}>
  18. {isSelecting && hoveredShapeId && (
  19. <HoveredShape key={hoveredShapeId} id={hoveredShapeId} />
  20. )}
  21. {visiblePageShapeIds.map((id) => (
  22. <Shape key={id} id={id} isSelecting={isSelecting} />
  23. ))}
  24. </g>
  25. )
  26. }