Skip to content

Commit 0e8aaa3

Browse files
committed
no resize
1 parent 76c42f3 commit 0e8aaa3

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

src/app/PuzzleClient.tsx

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,26 @@ import clsx from 'clsx';
1010
import Image from 'next/image';
1111
import Confetti from 'react-confetti';
1212

13-
function useGridSize() {
14-
const [gridSize, setGridSize] = useState(3);
15-
16-
useEffect(() => {
17-
function handleResize() {
18-
const width = window.innerWidth;
19-
const height = window.innerHeight;
20-
if (width < 640 || height < 640) {
21-
setGridSize(3);
22-
} else if (width < 1024 || height < 1024) {
23-
setGridSize(4);
24-
} else {
25-
setGridSize(5);
26-
}
27-
}
28-
handleResize();
29-
window.addEventListener("resize", handleResize);
30-
return () => window.removeEventListener("resize", handleResize);
31-
}, []);
32-
33-
return gridSize;
34-
}
35-
3613
function useContainerSize() {
37-
const [containerSize, setContainerSize] = useState(0);
14+
const [containerSize, setContainerSize] = useState(() => {
15+
const maxWidth = window.innerWidth - 32;
16+
const maxHeight = window.innerHeight - 64;
17+
return Math.min(maxWidth, maxHeight);
18+
});
19+
return containerSize;
20+
}
3821

39-
useEffect(() => {
40-
function updateSize() {
41-
const maxWidth = window.innerWidth - 32;
42-
const maxHeight = window.innerHeight - 64;
43-
setContainerSize(Math.min(maxWidth, maxHeight));
22+
function useGridSize() {
23+
const containerSize = useContainerSize();
24+
const [gridSize, setGridSize] = useState(() => {
25+
if (containerSize < 640) {
26+
return 3;
27+
} else if (containerSize < 900) {
28+
return 4;
4429
}
45-
updateSize();
46-
window.addEventListener("resize", updateSize);
47-
return () => window.removeEventListener("resize", updateSize);
48-
}, []);
49-
50-
return containerSize;
30+
return 5;
31+
});
32+
return gridSize;
5133
}
5234

5335
// --------------------------------------------------------------------------
@@ -204,7 +186,7 @@ export default function PuzzleClient() {
204186
const [showEasyModePrompt, setShowEasyModePrompt] = useState(false);
205187

206188
useEffect(() => {
207-
const arr = randomLegalScramble(gridSize);
189+
const arr = randomLegalScramble(gridSize, 200);
208190
setTiles(arr);
209191
setTileOffsets(arr.map(() => ({ x: 0, y: 0 })));
210192
setIsDraggingTile(arr.map(() => false));
@@ -469,7 +451,7 @@ export default function PuzzleClient() {
469451
// Render puzzle
470452
// ------------------------------------------------------
471453
return (
472-
<div className="w-screen min-h-[100dvh] flex items-center justify-center relative p-4 md:p-8">
454+
<div className="flex items-center justify-center relative p-4 md:p-8">
473455
{isWon && (
474456
<>
475457
<Confetti

0 commit comments

Comments
 (0)