Skip to content

Commit 9dce69f

Browse files
Merge pull request #99 from CSSLab/dev
Minor bug fixes + optimization
2 parents 38c6685 + a1ba385 commit 9dce69f

9 files changed

Lines changed: 110 additions & 122 deletions

File tree

src/components/Common/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export const Header: React.FC = () => {
226226
<span className="material-symbols-outlined text-3xl">menu</span>
227227
</button>
228228
{showMenu && (
229-
<div className="fixed left-0 top-0 z-[10101] flex h-screen w-screen flex-col items-start justify-between bg-backdrop py-4">
229+
<div className="fixed left-0 top-0 z-40 flex h-screen w-screen flex-col items-start justify-between bg-backdrop py-4">
230230
<div className="flex w-full flex-row justify-between px-4">
231231
<Link href="/" passHref>
232232
<div className="flex flex-row items-center gap-2">

src/components/Common/ModalContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ModalContainer: React.FC<Props> = ({
2929
exit={{ opacity: 0 }}
3030
transition={{ duration: 0.1 }}
3131
onClick={dismiss}
32-
className={`fixed bottom-0 top-0 z-[10102] flex w-screen items-center justify-center bg-backdrop/90 text-primary ${className}`}
32+
className={`fixed bottom-0 top-0 z-50 flex w-screen items-center justify-center bg-backdrop/90 text-primary ${className}`}
3333
>
3434
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
3535
<motion.div

src/components/Common/MoveIcons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const ExcellentIcon: React.FC<IconProps> = ({
8888
className={`ml-1 flex select-none items-center justify-center rounded-full bg-green-500 font-bold text-white ${sizeClasses} ${className}`}
8989
data-tooltip-id={id}
9090
>
91-
!!
91+
!
9292
</div>
9393
<Tooltip
9494
id={id}

src/components/Openings/OpeningSelectionModal.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ const PreviewPanel: React.FC<{
478478
<p className="text-xs text-secondary">Configure your drill settings</p>
479479
</div>
480480

481-
<div className="flex flex-1 flex-col gap-4 overflow-hidden p-2 md:p-3">
481+
<div className="flex flex-1 flex-col gap-4 overflow-hidden p-3 md:p-4">
482482
<div className="flex flex-col gap-1">
483483
<p className="text-sm font-medium md:text-base">
484484
{previewOpening.name}
@@ -629,10 +629,10 @@ const SelectedPanel: React.FC<{
629629
}
630630
}}
631631
onClick={() => removeSelection(selection.id)}
632-
className="group flex cursor-pointer items-center justify-between border-b border-white/5 p-3 transition-colors hover:bg-human-2/10 md:p-4"
632+
className="group flex cursor-pointer items-center justify-between border-b border-white/5 p-3 transition-colors hover:bg-human-2/10 md:px-4"
633633
>
634634
<div className="min-w-0 flex-1">
635-
<div className="flex items-center gap-3">
635+
<div className="flex items-center gap-2">
636636
<div className="relative h-4 w-4 flex-shrink-0 md:h-5 md:w-5">
637637
<Image
638638
src={
@@ -644,22 +644,15 @@ const SelectedPanel: React.FC<{
644644
alt={`${selection.playerColor} king`}
645645
/>
646646
</div>
647-
<div className="flex min-w-0 flex-1 flex-col">
647+
<div className="flex min-w-0 flex-1 flex-row items-center gap-2">
648648
<span className="truncate text-xs font-medium text-primary md:text-sm">
649649
{selection.opening.name}
650650
</span>
651-
<div className="flex items-center gap-1 text-xs text-secondary">
652-
{selection.variation && (
653-
<span className="truncate">
654-
{selection.variation.name}
655-
</span>
656-
)}
657-
<span>
658-
v. Maia{' '}
659-
{selection.maiaVersion.replace('maia_kdd_', '')}
651+
{selection.variation && (
652+
<span className="mt-1 truncate text-xxs text-secondary">
653+
{selection.variation.name}
660654
</span>
661-
<span>{selection.targetMoveNumber} moves</span>
662-
</div>
655+
)}
663656
</div>
664657
</div>
665658
</div>
@@ -708,14 +701,14 @@ const SelectedPanel: React.FC<{
708701
<input
709702
type="range"
710703
min="5"
711-
max="30"
704+
max="20"
712705
value={targetMoveNumber}
713706
onChange={(e) => setTargetMoveNumber(parseInt(e.target.value) || 10)}
714707
className="w-full accent-human-4"
715708
/>
716709
<div className="mt-1 flex justify-between text-xs text-secondary">
717710
<span>5</span>
718-
<span>30</span>
711+
<span>20</span>
719712
</div>
720713
</div>
721714

@@ -727,14 +720,14 @@ const SelectedPanel: React.FC<{
727720
<input
728721
type="range"
729722
min="1"
730-
max="50"
723+
max="20"
731724
value={drillCount}
732725
onChange={(e) => setDrillCount(parseInt(e.target.value) || 5)}
733726
className="w-full accent-human-4"
734727
/>
735728
<div className="mt-1 flex justify-between text-xs text-secondary">
736729
<span>1</span>
737-
<span>50</span>
730+
<span>20</span>
738731
</div>
739732
<p className="mt-1 text-xs text-secondary">
740733
{drillCount <= selections.length
@@ -814,6 +807,17 @@ export const OpeningSelectionModal: React.FC<Props> = ({
814807
}
815808
}, [hasTrackedModalOpen, initialSelections.length])
816809

810+
// Update the ID to reflect the new settings
811+
useEffect(() => {
812+
setSelections((prevSelections) =>
813+
prevSelections.map((selection) => ({
814+
...selection,
815+
maiaVersion: selectedMaiaVersion.id,
816+
targetMoveNumber,
817+
})),
818+
)
819+
}, [selectedMaiaVersion.id, targetMoveNumber])
820+
817821
const handleStartTour = () => {
818822
startTour(tourConfigs.openingDrill.id, tourConfigs.openingDrill.steps, true)
819823
}

src/contexts/TourContext/TourContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ export const TourProvider: React.FC<TourProviderProps> = ({ children }) => {
631631
backgroundColor: 'rgb(38, 36, 45)', // background-1 to match tooltip
632632
overlayColor: 'rgba(0, 0, 0, 0.5)',
633633
spotlightShadow: '0 0 15px rgba(159, 79, 68, 0.3)',
634-
zIndex: 10000,
634+
zIndex: 30,
635635
},
636636
spotlight: {
637637
borderRadius: '4px',

src/hooks/useAnalysisController/useAnalysisController.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Chess } from 'chess.ts'
2-
import { useContext, useEffect, useMemo, useState } from 'react'
2+
import { Key, useContext, useEffect, useMemo, useState } from 'react'
33

4-
import { useTreeController, useLocalStorage } from '..'
54
import { AnalyzedGame } from 'src/types'
5+
import type { DrawShape } from 'chessground/draw'
66
import { MAIA_MODELS } from 'src/constants/common'
7-
import { generateColorSanMapping, calculateBlunderMeter } from './utils'
7+
import { useTreeController, useLocalStorage } from '..'
88
import { useEngineAnalysis } from './useEngineAnalysis'
9-
import { useMoveRecommendations } from './useMoveRecommendations'
109
import { useBoardDescription } from './useBoardDescription'
10+
import { useMoveRecommendations } from './useMoveRecommendations'
1111
import { MaiaEngineContext } from 'src/contexts/MaiaEngineContext'
12+
import { generateColorSanMapping, calculateBlunderMeter } from './utils'
1213
import { StockfishEngineContext } from 'src/contexts/StockfishEngineContext'
1314

1415
export const useAnalysisController = (
@@ -119,6 +120,37 @@ export const useAnalysisController = (
119120
return undefined
120121
}, [currentMove, controller.currentNode])
121122

123+
const arrows = useMemo(() => {
124+
if (!controller.currentNode) return []
125+
126+
const arrows: DrawShape[] = []
127+
128+
if (moveEvaluation?.maia) {
129+
const bestMove = Object.entries(moveEvaluation.maia.policy)[0]
130+
if (bestMove) {
131+
arrows.push({
132+
brush: 'red',
133+
orig: bestMove[0].slice(0, 2) as Key,
134+
dest: bestMove[0].slice(2, 4) as Key,
135+
} as DrawShape)
136+
}
137+
}
138+
139+
if (moveEvaluation?.stockfish) {
140+
const bestMove = Object.entries(moveEvaluation.stockfish.cp_vec)[0]
141+
if (bestMove) {
142+
arrows.push({
143+
brush: 'blue',
144+
orig: bestMove[0].slice(0, 2) as Key,
145+
dest: bestMove[0].slice(2, 4) as Key,
146+
modifiers: { lineWidth: 8 },
147+
} as DrawShape)
148+
}
149+
}
150+
151+
return arrows
152+
}, [controller.currentNode, moveEvaluation])
153+
122154
return {
123155
gameTree: controller.gameTree,
124156
currentNode: controller.currentNode,
@@ -144,6 +176,7 @@ export const useAnalysisController = (
144176
moveMap,
145177
blunderMeter,
146178
boardDescription,
179+
arrows,
147180
stockfish: stockfish,
148181
maia: maia,
149182
}

src/pages/analysis/[...id].tsx

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ const Analysis: React.FC<Props> = ({
308308
const { width } = useContext(WindowSizeContext)
309309
const isMobile = useMemo(() => width > 0 && width <= 670, [width])
310310
const [hoverArrow, setHoverArrow] = useState<DrawShape | null>(null)
311-
const [arrows, setArrows] = useState<DrawShape[]>([])
312311
const [currentSquare, setCurrentSquare] = useState<Key | null>(null)
313312
const [promotionFromTo, setPromotionFromTo] = useState<
314313
[string, string] | null
@@ -356,41 +355,6 @@ const Analysis: React.FC<Props> = ({
356355
}
357356
}, [analyzedGame, router])
358357

359-
useEffect(() => {
360-
const arr = []
361-
362-
if (controller.moveEvaluation?.maia) {
363-
const maia = Object.entries(controller.moveEvaluation?.maia?.policy)[0]
364-
if (maia) {
365-
arr.push({
366-
brush: 'red',
367-
orig: maia[0].slice(0, 2) as Key,
368-
dest: maia[0].slice(2, 4) as Key,
369-
} as DrawShape)
370-
}
371-
}
372-
373-
if (controller.moveEvaluation?.stockfish) {
374-
const stockfish = Object.entries(
375-
controller.moveEvaluation?.stockfish.cp_vec,
376-
)[0]
377-
if (stockfish) {
378-
arr.push({
379-
brush: 'blue',
380-
orig: stockfish[0].slice(0, 2) as Key,
381-
dest: stockfish[0].slice(2, 4) as Key,
382-
modifiers: { lineWidth: 8 },
383-
})
384-
}
385-
}
386-
387-
setArrows(arr)
388-
}, [
389-
controller.moveEvaluation,
390-
controller.currentNode,
391-
controller.orientation,
392-
])
393-
394358
const hover = (move?: string) => {
395359
if (move) {
396360
setHoverArrow({
@@ -672,7 +636,11 @@ const Analysis: React.FC<Props> = ({
672636
game={analyzedGame}
673637
availableMoves={controller.availableMoves}
674638
setCurrentSquare={setCurrentSquare}
675-
shapes={hoverArrow ? [...arrows, hoverArrow] : [...arrows]}
639+
shapes={
640+
hoverArrow
641+
? [...controller.arrows, hoverArrow]
642+
: [...controller.arrows]
643+
}
676644
currentNode={controller.currentNode as GameNode}
677645
orientation={controller.orientation}
678646
onPlayerMakeMove={onPlayerMakeMove}
@@ -919,7 +887,11 @@ const Analysis: React.FC<Props> = ({
919887
game={analyzedGame}
920888
availableMoves={controller.availableMoves}
921889
setCurrentSquare={setCurrentSquare}
922-
shapes={hoverArrow ? [...arrows, hoverArrow] : [...arrows]}
890+
shapes={
891+
hoverArrow
892+
? [...controller.arrows, hoverArrow]
893+
: [...controller.arrows]
894+
}
923895
currentNode={controller.currentNode as GameNode}
924896
orientation={controller.orientation}
925897
onPlayerMakeMove={onPlayerMakeMove}

src/pages/openings/index.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const OpeningsPage: NextPage = () => {
7474
const [promotionFromTo, setPromotionFromTo] = useState<
7575
[string, string] | null
7676
>(null)
77-
const [arrows, setArrows] = useState<DrawShape[]>([])
7877
const [hoverArrow, setHoverArrow] = useState<DrawShape | null>(null)
7978

8079
useEffect(() => {
@@ -85,7 +84,6 @@ const OpeningsPage: NextPage = () => {
8584

8685
useEffect(() => {
8786
return () => {
88-
setArrows([])
8987
setHoverArrow(null)
9088
setPromotionFromTo(null)
9189
}
@@ -207,13 +205,6 @@ const OpeningsPage: NextPage = () => {
207205
treeController.currentNode?.analysis?.stockfish,
208206
])
209207

210-
// Set arrows with deferred updates to prevent blocking UI
211-
useEffect(() => {
212-
deferHeavyOperation(() => {
213-
setArrows(calculatedArrows)
214-
})
215-
}, [calculatedArrows, deferHeavyOperation])
216-
217208
// Clear hover arrow when node changes
218209
useEffect(() => {
219210
setHoverArrow(null)
@@ -762,7 +753,15 @@ const OpeningsPage: NextPage = () => {
762753
availableMoves={availableMoves}
763754
onPlayerMakeMove={onPlayerMakeMove}
764755
onSelectSquare={onSelectSquare}
765-
shapes={hoverArrow ? [...arrows, hoverArrow] : [...arrows]}
756+
shapes={
757+
controller.analysisEnabled
758+
? hoverArrow
759+
? [...analysisController.arrows, hoverArrow]
760+
: [...analysisController.arrows]
761+
: hoverArrow
762+
? [hoverArrow]
763+
: []
764+
}
766765
/>
767766
{promotionFromTo && (
768767
<PromotionOverlay
@@ -919,7 +918,15 @@ const OpeningsPage: NextPage = () => {
919918
availableMoves={availableMoves}
920919
onPlayerMakeMove={onPlayerMakeMove}
921920
onSelectSquare={onSelectSquare}
922-
shapes={hoverArrow ? [...arrows, hoverArrow] : [...arrows]}
921+
shapes={
922+
controller.analysisEnabled
923+
? hoverArrow
924+
? [...analysisController.arrows, hoverArrow]
925+
: [...analysisController.arrows]
926+
: hoverArrow
927+
? [hoverArrow]
928+
: []
929+
}
923930
/>
924931
{promotionFromTo && (
925932
<PromotionOverlay

0 commit comments

Comments
 (0)