Fix grid not showing in editor, and width resize
This commit is contained in:
parent
d0377596d2
commit
f1dce05830
@ -19,13 +19,13 @@ function Grid({ strokeWidth, stroke }) {
|
||||
} = useGrid();
|
||||
|
||||
const gridGroupRef = useRef();
|
||||
const { stageScale } = useMapInteraction();
|
||||
const { stageScale, mapWidth } = useMapInteraction();
|
||||
const debouncedStageScale = useDebounce(stageScale, 50);
|
||||
|
||||
useEffect(() => {
|
||||
const gridGroup = gridGroupRef.current;
|
||||
if (gridGroup && grid?.size.x && grid?.size.y) {
|
||||
if (gridGroup && grid?.size.x && grid?.size.y && debouncedStageScale) {
|
||||
const gridRect = gridGroup.getClientRect();
|
||||
if (gridRect.width > 0 && gridRect.height > 0) {
|
||||
// 150 pixels per grid cell
|
||||
const maxMapSize = Math.max(grid.size.x, grid.size.y) * 150;
|
||||
const maxGridSize =
|
||||
@ -38,7 +38,8 @@ function Grid({ strokeWidth, stroke }) {
|
||||
),
|
||||
});
|
||||
}
|
||||
}, [grid, debouncedStageScale]);
|
||||
}
|
||||
}, [grid, debouncedStageScale, mapWidth]);
|
||||
|
||||
if (!grid?.size.x || !grid?.size.y) {
|
||||
return null;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
function useDebounce(value, delay) {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
const [debouncedValue, setDebouncedValue] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
const timeout = setTimeout(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user