Skip to content

Commit 632041a

Browse files
fix: opening page re-renders + close modal button
1 parent 249c778 commit 632041a

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

src/components/Openings/OpeningDrillAnalysis.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const OpeningDrillAnalysis: React.FC<Props> = ({
109109
<span className="material-symbols-outlined !text-sm">
110110
{analysisEnabled ? 'visibility' : 'visibility_off'}
111111
</span>
112-
{analysisEnabled ? 'Visible' : 'Hidden'}
112+
{analysisEnabled ? 'Hide' : 'Show'}
113113
</button>
114114
</div>
115115

src/components/Openings/OpeningSelectionModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,6 @@ export const OpeningSelectionModal: React.FC<Props> = ({
15891589
'radial-gradient(ellipse 180% 160% at 0% 100%, rgba(239, 68, 68, 0.10) 0%, transparent 72%)',
15901590
}}
15911591
/>
1592-
{/* Close Button - Top Right of Modal */}
15931592
<button
15941593
onClick={onClose}
15951594
className="absolute right-4 top-4 z-10 text-secondary transition-colors hover:text-primary"

src/hooks/useOpeningDrillController/useOpeningDrillController.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ export const useOpeningDrillController = (
249249
setContinueAnalyzingMode(false)
250250
}, [currentDrill])
251251

252-
const gameTree = currentDrillGame?.tree || new GameTree(new Chess().fen())
252+
const fallbackGameTree = useMemo(
253+
() => new GameTree(new Chess().fen()),
254+
[],
255+
)
256+
257+
const gameTree = currentDrillGame?.tree || fallbackGameTree
253258

254259
// Delegate navigation/orientation to the shared tree controller
255260
const treeController = useTreeController(

src/pages/openings/index.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Head from 'next/head'
22
import { NextPage } from 'next'
3-
import { useRouter } from 'next/router'
43
import { useState, useEffect, useContext, useCallback, useMemo } from 'react'
4+
import { useRouter } from 'next/router'
55
import { Chess, PieceSymbol } from 'chess.ts'
66
import { AnimatePresence } from 'framer-motion'
77
import type { Key } from 'chessground/types'
@@ -44,6 +44,7 @@ const OpeningsPage: NextPage = () => {
4444
const handleCloseModal = () => {
4545
router.push('/')
4646
}
47+
4748
const [drillConfiguration, setDrillConfiguration] =
4849
useState<DrillConfiguration | null>(null)
4950
const [promotionFromTo, setPromotionFromTo] = useState<
@@ -58,13 +59,12 @@ const OpeningsPage: NextPage = () => {
5859
}
5960
}, [])
6061

61-
const emptyConfiguration: DrillConfiguration = {
62-
selections: [],
63-
}
64-
65-
const controller = useOpeningDrillController(
66-
drillConfiguration || emptyConfiguration,
62+
const safeConfiguration = useMemo<DrillConfiguration>(
63+
() => drillConfiguration ?? { selections: [] },
64+
[drillConfiguration],
6765
)
66+
67+
const controller = useOpeningDrillController(safeConfiguration)
6868
const { isMobile } = useContext(WindowSizeContext)
6969

7070
const playerNames = useMemo(() => {
@@ -192,12 +192,7 @@ const OpeningsPage: NextPage = () => {
192192
}
193193
}, [controller.gameTree, controller.currentDrill?.id])
194194

195-
// Show selection modal when no drill configuration exists
196-
useEffect(() => {
197-
if (!drillConfiguration || drillConfiguration.selections.length === 0) {
198-
setShowSelectionModal(true)
199-
}
200-
}, [drillConfiguration])
195+
// Removed auto-reopen behavior so the modal can be dismissed even without configuration
201196

202197
const handleCompleteSelection = useCallback(
203198
(configuration: DrillConfiguration) => {
@@ -444,11 +439,7 @@ const OpeningsPage: NextPage = () => {
444439
}
445440

446441
// Show selection modal when no drill configuration exists (after model is ready)
447-
if (
448-
!drillConfiguration ||
449-
drillConfiguration.selections.length === 0 ||
450-
showSelectionModal
451-
) {
442+
if (showSelectionModal) {
452443
return (
453444
<>
454445
<Head>

0 commit comments

Comments
 (0)