Skip to content

Commit 366294c

Browse files
chore: more cleanup
1 parent 1265766 commit 366294c

20 files changed

Lines changed: 47 additions & 220 deletions

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"[dockerfile]": {
88
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
99
},
10-
"editor.tabCompletion": "on"
10+
"editor.tabCompletion": "on",
11+
"github.copilot.nextEditSuggestions.enabled": true
1112
}

src/components/Analysis/AnalysisGameList.tsx

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { Tournament } from 'src/components'
1212
import { FavoriteModal } from 'src/components/Common/FavoriteModal'
1313
import { AnalysisListContext } from 'src/contexts'
1414
import { fetchMaiaGameList } from 'src/api'
15-
import { ensureMigration } from 'src/lib/customAnalysis'
1615
import {
1716
getFavoritesAsWebGames,
1817
addFavoriteGame,
@@ -60,21 +59,13 @@ interface AnalysisGameListProps {
6059
export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
6160
currentId,
6261
loadNewTournamentGame,
63-
loadNewLichessGames,
64-
loadNewUserGames,
65-
loadNewCustomGame,
6662
onCustomAnalysis,
6763
onGameSelected,
6864
refreshTrigger,
6965
}) => {
7066
const router = useRouter()
71-
const {
72-
analysisPlayList,
73-
analysisHandList,
74-
analysisBrainList,
75-
analysisLichessList,
76-
analysisTournamentList,
77-
} = useContext(AnalysisListContext)
67+
const { analysisLichessList, analysisTournamentList } =
68+
useContext(AnalysisListContext)
7869

7970
const [currentPage, setCurrentPage] = useState(1)
8071
const [totalPages, setTotalPages] = useState(1)
@@ -96,14 +87,12 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
9687
)
9788
const [hbSubsection, setHbSubsection] = useState<'hand' | 'brain'>('hand')
9889

99-
// Modal state for favoriting
10090
const [favoriteModal, setFavoriteModal] = useState<{
10191
isOpen: boolean
10292
game: MaiaGameListEntry | null
10393
}>({ isOpen: false, game: null })
10494

10595
useEffect(() => {
106-
// Load favorites asynchronously
10796
getFavoritesAsWebGames()
10897
.then((favorites) => {
10998
setFavoriteGames(favorites)
@@ -115,12 +104,6 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
115104
})
116105
}, [refreshTrigger])
117106

118-
useEffect(() => {
119-
ensureMigration().catch((error) => {
120-
console.warn('Failed to migrate custom analyses:', error)
121-
})
122-
}, [])
123-
124107
useEffect(() => {
125108
if (currentId?.[1] === 'custom') {
126109
setSelected('custom')
@@ -752,10 +735,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
752735
setLoadingIndex(index)
753736
if (game.type === 'pgn') {
754737
router.push(`/analysis/${game.id}/pgn`)
755-
} else if (
756-
game.type === 'custom-pgn' ||
757-
game.type === 'custom-fen'
758-
) {
738+
} else if (game.type === 'custom') {
759739
router.push(`/analysis/${game.id}/custom`)
760740
} else {
761741
router.push(`/analysis/${game.id}/${game.type}`)

src/components/Analysis/Highlight.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cpToWinrate } from 'src/lib'
12
import { MoveTooltip } from './MoveTooltip'
23
import { InteractiveDescription } from './InteractiveDescription'
34
import { useState, useEffect, useRef, useContext } from 'react'
@@ -8,7 +9,6 @@ import {
89
ColorSanMapping,
910
GameNode,
1011
} from 'src/types'
11-
import { cpToWinrate } from 'src/lib/engine'
1212
import { MAIA_MODELS } from 'src/constants/common'
1313
import { WindowSizeContext } from 'src/contexts'
1414

src/components/Board/MovesContainer.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* eslint-disable jsx-a11y/no-static-element-interactions */
22
/* eslint-disable jsx-a11y/click-events-have-key-events */
3+
import { TuringGame } from 'src/types/turing'
34
import React, { useContext, useMemo, Fragment, useEffect, useRef } from 'react'
4-
import { WindowSizeContext } from 'src/contexts'
5+
import { TreeControllerContext, WindowSizeContext } from 'src/contexts'
56
import { GameNode, AnalyzedGame, Termination, BaseGame } from 'src/types'
6-
import { TuringGame } from 'src/types/turing'
7-
import { useBaseTreeController } from 'src/hooks/useBaseTreeController'
87
import { MoveClassificationIcon } from 'src/components/Common/MoveIcons'
98

109
interface AnalysisProps {
@@ -92,7 +91,7 @@ export const MovesContainer: React.FC<Props> = (props) => {
9291
return plyFromStart >= 6
9392
}
9493

95-
const baseController = useBaseTreeController(type)
94+
const baseController = useContext(TreeControllerContext)
9695

9796
const mainLineNodes = useMemo(() => {
9897
return baseController.gameTree.getMainLine() ?? game.tree.getMainLine()

src/components/Common/ExportGame.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import toast from 'react-hot-toast'
44
import { useContext, useEffect, useState } from 'react'
55

66
import { PlayedGame, AnalyzedGame, GameTree, GameNode } from 'src/types'
7-
import { useBaseTreeController } from 'src/hooks/useBaseTreeController'
7+
import { TreeControllerContext } from 'src/contexts'
88

99
interface AnalysisProps {
1010
game: AnalyzedGame
@@ -41,7 +41,7 @@ export const ExportGame: React.FC<Props> = (props) => {
4141
const [fen, setFen] = useState('')
4242
const [pgn, setPgn] = useState('')
4343

44-
const controller = useBaseTreeController(type)
44+
const controller = useContext(TreeControllerContext)
4545

4646
const { currentNode, gameTree } =
4747
type === 'analysis'
@@ -81,7 +81,6 @@ export const ExportGame: React.FC<Props> = (props) => {
8181
setFen(currentNode.fen)
8282
}, [
8383
currentNode,
84-
game.moves,
8584
game.id,
8685
game.termination,
8786
whitePlayer,

src/components/Profile/GameList.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import React, { useState, useEffect, useContext } from 'react'
44
import { AuthContext } from 'src/contexts'
55
import { MaiaGameListEntry } from 'src/types'
66
import { streamLichessGames, fetchMaiaGameList } from 'src/api'
7-
import { getCustomAnalysesAsWebGames } from 'src/lib/customAnalysis'
87
import { FavoriteModal } from 'src/components/Common/FavoriteModal'
98
import {
10-
getFavoritesAsWebGames,
119
addFavoriteGame,
1210
removeFavoriteGame,
13-
isFavoriteGame,
11+
getFavoritesAsWebGames,
1412
} from 'src/lib/favorites'
1513

1614
interface GameData {
@@ -55,12 +53,6 @@ export const GameList = ({
5553
favorites: {},
5654
})
5755

58-
const [customAnalyses, setCustomAnalyses] = useState(() => {
59-
if (typeof window !== 'undefined') {
60-
return getCustomAnalysesAsWebGames()
61-
}
62-
return []
63-
})
6456
const [favoriteGames, setFavoriteGames] = useState<MaiaGameListEntry[]>([])
6557
const [favoritedGameIds, setFavoritedGameIds] = useState<Set<string>>(
6658
new Set(),
@@ -101,9 +93,6 @@ export const GameList = ({
10193

10294
// Update custom analyses and favorites when component mounts
10395
useEffect(() => {
104-
if (showCustom) {
105-
setCustomAnalyses(getCustomAnalysesAsWebGames())
106-
}
10796
// Load favorites (supports both sync and async implementations)
10897
Promise.resolve(getFavoritesAsWebGames())
10998
.then((favorites) => {
@@ -413,8 +402,6 @@ export const GameList = ({
413402
} else if (selected === 'hb') {
414403
const gameType = hbSubsection
415404
return gamesByPage[gameType]?.[currentPage] || []
416-
} else if (selected === 'custom' && showCustom) {
417-
return customAnalyses
418405
} else if (selected === 'lichess' && showLichess) {
419406
return games
420407
} else if (selected === 'favorites') {

src/contexts/PlayControllerContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const defaultGameTree = new GameTree(new Chess().fen())
3636

3737
export const PlayControllerContext =
3838
React.createContext<IPlayControllerContext>({
39-
game: { id: '', moves: [], turn: 'black', tree: defaultGameTree },
39+
game: { id: '', turn: 'black', tree: defaultGameTree },
4040
playType: 'againstMaia',
4141
timeControl: 'unlimited',
4242
player: 'white',

src/contexts/TrainingControllerContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export interface ITrainingControllerContext extends BaseTreeControllerContext {
1010
const defaultContext: ITrainingControllerContext = {
1111
gameTree: new GameTree(new Chess().fen()),
1212
currentNode: new GameTree(new Chess().fen()).getRoot(),
13+
setCurrentNode: () => {
14+
/* no-op */
15+
},
1316
goToNode: () => {
1417
/* no-op */
1518
},

src/contexts/TreeControllerContext.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import React from 'react'
22
import { Chess } from 'chess.ts'
3-
import { useTreeController } from 'src/hooks/useTreeController'
43
import { GameTree, BaseTreeControllerContext } from 'src/types'
54

6-
export interface ITreeControllerContext extends BaseTreeControllerContext {
7-
currentNode: ReturnType<typeof useTreeController>['currentNode']
8-
setCurrentNode: ReturnType<typeof useTreeController>['setCurrentNode']
9-
}
10-
115
const defaultGameTree = new GameTree(new Chess().fen())
126

137
export const TreeControllerContext =
14-
React.createContext<ITreeControllerContext>({
8+
React.createContext<BaseTreeControllerContext>({
159
gameTree: defaultGameTree,
1610
currentNode: defaultGameTree.getRoot(),
1711
setCurrentNode: () => {

src/contexts/TuringTreeControllerContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export interface ITuringControllerContext extends BaseTreeControllerContext {
2525
const defaultContext: ITuringControllerContext = {
2626
gameTree: new GameTree(new Chess().fen()),
2727
currentNode: new GameTree(new Chess().fen()).getRoot(),
28+
setCurrentNode: () => {
29+
/* no-op */
30+
},
2831
goToNode: () => {
2932
/* no-op */
3033
},

0 commit comments

Comments
 (0)