Skip to content

Commit 21bcb58

Browse files
chore: clean up types
1 parent 646ca91 commit 21bcb58

20 files changed

Lines changed: 120 additions & 131 deletions

File tree

__tests__/lib/favorites.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getFavoriteGame,
88
getFavoritesAsWebGames,
99
} from 'src/lib/favorites'
10-
import { AnalysisWebGame } from 'src/types'
10+
import { MaiaGameEntry } from 'src/types'
1111

1212
// Mock localStorage
1313
const localStorageMock = (() => {
@@ -46,7 +46,7 @@ describe('favorites', () => {
4646
localStorageMock.clear()
4747
})
4848

49-
const mockGame: AnalysisWebGame = {
49+
const mockGame: MaiaGameEntry = {
5050
id: 'test-game-1',
5151
type: 'play',
5252
label: 'You vs. Maia 1600',
@@ -124,7 +124,7 @@ describe('favorites', () => {
124124
it('should limit favorites to 100 entries', async () => {
125125
// Add 101 favorites
126126
for (let i = 0; i < 101; i++) {
127-
const game: AnalysisWebGame = {
127+
const game: MaiaGameEntry = {
128128
id: `game-${i}`,
129129
type: 'play',
130130
label: `Game ${i}`,

src/api/analysis.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
MaiaEvaluation,
99
PositionEvaluation,
1010
StockfishEvaluation,
11-
AnalysisTournamentGame,
11+
WorldChampionshipGameEntry,
1212
} from 'src/types'
1313
import {
1414
readLichessStream,
@@ -17,15 +17,15 @@ import {
1717
} from 'src/lib'
1818
import { buildUrl } from './utils'
1919
import { Chess } from 'chess.ts'
20-
import { AvailableMoves } from 'src/types/training'
20+
import { AvailableMoves } from 'src/types/puzzle'
2121

2222
import {
2323
saveCustomAnalysis,
2424
getCustomAnalysisById,
2525
} from 'src/lib/customAnalysis'
2626

2727
export const fetchWorldChampionshipGameList = async (): Promise<
28-
Map<string, AnalysisTournamentGame[]>
28+
Map<string, WorldChampionshipGameEntry[]>
2929
> => {
3030
const res = await fetch(buildUrl('analysis/list'))
3131

src/api/train.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { buildUrl } from './utils'
33
import { MoveMap, GameTree } from 'src/types'
4-
import { AvailableMoves, TrainingGame } from 'src/types/training'
4+
import { AvailableMoves, PuzzleGame } from 'src/types/puzzle'
55

66
export const fetchPuzzle = async () => {
77
const res = await fetch(buildUrl('puzzle/new_puzzle'))
@@ -111,7 +111,7 @@ export const fetchPuzzle = async () => {
111111
termination,
112112
availableMoves,
113113
targetIndex: data['target_move_index'],
114-
} as any as TrainingGame
114+
} as any as PuzzleGame
115115
}
116116

117117
export const logPuzzleGuesses = async (

src/components/Analysis/AnalysisGameList.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
updateFavoriteName,
2121
isFavoriteGame,
2222
} from 'src/lib/favorites'
23-
import { AnalysisWebGame } from 'src/types'
23+
import { MaiaGameEntry } from 'src/types'
2424
import { useRouter } from 'next/router'
2525

2626
interface GameData {
@@ -81,7 +81,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
8181
const [loading, setLoading] = useState(false)
8282

8383
const [gamesByPage, setGamesByPage] = useState<{
84-
[gameType: string]: { [page: number]: AnalysisWebGame[] }
84+
[gameType: string]: { [page: number]: MaiaGameEntry[] }
8585
}>({
8686
play: {},
8787
hand: {},
@@ -90,7 +90,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
9090
custom: {},
9191
})
9292

93-
const [favoriteGames, setFavoriteGames] = useState<AnalysisWebGame[]>([])
93+
const [favoriteGames, setFavoriteGames] = useState<MaiaGameEntry[]>([])
9494
const [favoritedGameIds, setFavoritedGameIds] = useState<Set<string>>(
9595
new Set(),
9696
)
@@ -99,7 +99,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
9999
// Modal state for favoriting
100100
const [favoriteModal, setFavoriteModal] = useState<{
101101
isOpen: boolean
102-
game: AnalysisWebGame | null
102+
game: MaiaGameEntry | null
103103
}>({ isOpen: false, game: null })
104104

105105
useEffect(() => {
@@ -226,7 +226,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
226226

227227
fetchMaiaGameList(selected, currentPage)
228228
.then((data) => {
229-
let parsedGames: AnalysisWebGame[] = []
229+
let parsedGames: MaiaGameEntry[] = []
230230

231231
if (selected === 'favorites') {
232232
// Handle favorites response format
@@ -463,7 +463,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
463463
setSelected(newTab)
464464
}
465465

466-
const handleFavoriteGame = (game: AnalysisWebGame) => {
466+
const handleFavoriteGame = (game: MaiaGameEntry) => {
467467
setFavoriteModal({ isOpen: true, game })
468468
}
469469

@@ -541,7 +541,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
541541
}
542542
}
543543

544-
const handleDirectUnfavorite = async (game: AnalysisWebGame) => {
544+
const handleDirectUnfavorite = async (game: MaiaGameEntry) => {
545545
await removeFavoriteGame(game.id, game.type)
546546
const updatedFavorites = await getFavoritesAsWebGames()
547547
setFavoriteGames(updatedFavorites)

src/components/Analysis/Tournament.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Dispatch, SetStateAction } from 'react'
2-
import { AnalysisTournamentGame } from 'src/types'
2+
import { WorldChampionshipGameEntry } from 'src/types'
33
import { useRouter } from 'next/router'
44
type Props = {
55
id: string
@@ -11,7 +11,7 @@ type Props = {
1111
setLoadingIndex: (index: number | null) => void
1212
openElement: React.RefObject<HTMLDivElement>
1313
selectedGameElement: React.RefObject<HTMLButtonElement>
14-
analysisTournamentList: Map<string, AnalysisTournamentGame[]>
14+
analysisTournamentList: Map<string, WorldChampionshipGameEntry[]>
1515
loadNewTournamentGame: (
1616
id: string[],
1717
setCurrentMove?: Dispatch<SetStateAction<number>>,

src/components/Profile/GameList.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { motion } from 'framer-motion'
22
import React, { useState, useEffect, useContext } from 'react'
33

44
import { AuthContext } from 'src/contexts'
5-
import { AnalysisWebGame } from 'src/types'
5+
import { MaiaGameEntry } from 'src/types'
66
import { streamLichessGames, fetchMaiaGameList } from 'src/api'
77
import { getCustomAnalysesAsWebGames } from 'src/lib/customAnalysis'
88
import { FavoriteModal } from 'src/components/Common/FavoriteModal'
@@ -44,10 +44,10 @@ export const GameList = ({
4444
'play' | 'hb' | 'custom' | 'lichess' | 'favorites'
4545
>(showCustom ? 'favorites' : 'play')
4646
const [hbSubsection, setHbSubsection] = useState<'hand' | 'brain'>('hand')
47-
const [games, setGames] = useState<AnalysisWebGame[]>([])
47+
const [games, setGames] = useState<MaiaGameEntry[]>([])
4848

4949
const [gamesByPage, setGamesByPage] = useState<{
50-
[gameType: string]: { [page: number]: AnalysisWebGame[] }
50+
[gameType: string]: { [page: number]: MaiaGameEntry[] }
5151
}>({
5252
play: {},
5353
hand: {},
@@ -61,7 +61,7 @@ export const GameList = ({
6161
}
6262
return []
6363
})
64-
const [favoriteGames, setFavoriteGames] = useState<AnalysisWebGame[]>([])
64+
const [favoriteGames, setFavoriteGames] = useState<MaiaGameEntry[]>([])
6565
const [favoritedGameIds, setFavoritedGameIds] = useState<Set<string>>(
6666
new Set(),
6767
)
@@ -72,7 +72,7 @@ export const GameList = ({
7272
// Modal state for favoriting
7373
const [favoriteModal, setFavoriteModal] = useState<{
7474
isOpen: boolean
75-
game: AnalysisWebGame | null
75+
game: MaiaGameEntry | null
7676
}>({ isOpen: false, game: null })
7777

7878
const [fetchedCache, setFetchedCache] = useState<{
@@ -127,7 +127,7 @@ export const GameList = ({
127127
streamLichessGames(targetUser, (data) => {
128128
const result = data.pgn.match(/\[Result\s+"(.+?)"\]/)[1] || '?'
129129

130-
const game: AnalysisWebGame = {
130+
const game: MaiaGameEntry = {
131131
id: data.id,
132132
label: `${data.players.white.user?.id || 'Unknown'} vs. ${data.players.black.user?.id || 'Unknown'}`,
133133
result: result,
@@ -155,7 +155,7 @@ export const GameList = ({
155155

156156
fetchMaiaGameList(gameType, currentPage, lichessId)
157157
.then((data) => {
158-
let parsedGames: AnalysisWebGame[] = []
158+
let parsedGames: MaiaGameEntry[] = []
159159

160160
if (gameType === 'favorites') {
161161
// Handle favorites response format
@@ -309,7 +309,7 @@ export const GameList = ({
309309
setSelected(newTab)
310310
}
311311

312-
const handleFavoriteGame = (game: AnalysisWebGame) => {
312+
const handleFavoriteGame = (game: MaiaGameEntry) => {
313313
setFavoriteModal({ isOpen: true, game })
314314
}
315315

@@ -377,7 +377,7 @@ export const GameList = ({
377377
}
378378
}
379379

380-
const handleDirectUnfavorite = async (game: AnalysisWebGame) => {
380+
const handleDirectUnfavorite = async (game: MaiaGameEntry) => {
381381
await removeFavoriteGame(game.id, game.type)
382382
const updatedFavorites = await getFavoritesAsWebGames()
383383
setFavoriteGames(updatedFavorites)

src/components/Puzzles/Feedback.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { useMemo, Dispatch, SetStateAction } from 'react'
33

44
import { Markdown } from 'src/components'
55
import { useTrainingController } from 'src/hooks'
6-
import { TrainingGame, Status } from 'src/types/training'
6+
import { PuzzleGame, Status } from 'src/types/puzzle'
77

88
interface Props {
99
status: string
10-
game: TrainingGame
10+
game: PuzzleGame
1111
setAndGiveUp: () => void
1212
getNewGame: () => Promise<void>
1313
setStatus: Dispatch<SetStateAction<Status>>

src/components/Puzzles/PuzzleLog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Dispatch, SetStateAction } from 'react'
22

3-
import { TrainingGame } from 'src/types/training'
3+
import { PuzzleGame } from 'src/types/puzzle'
44

55
interface Props {
6-
previousGameResults: (TrainingGame & {
6+
previousGameResults: (PuzzleGame & {
77
result?: boolean
88
ratingDiff?: number
99
})[]

src/contexts/AnalysisListContext.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { useRouter } from 'next/router'
22
import { AuthContext } from 'src/contexts'
33
import React, { ReactNode, useContext, useEffect, useState } from 'react'
4-
import { AnalysisWebGame, AnalysisTournamentGame } from 'src/types'
4+
import { MaiaGameEntry, WorldChampionshipGameEntry } from 'src/types'
55
import {
66
fetchWorldChampionshipGameList,
77
streamLichessGames,
88
fetchMaiaGameList,
99
} from 'src/api'
1010

1111
interface IAnalysisListContext {
12-
analysisTournamentList: Map<string, AnalysisTournamentGame[]> | null
13-
analysisLichessList: AnalysisWebGame[]
14-
analysisPlayList: AnalysisWebGame[]
15-
analysisHandList: AnalysisWebGame[]
16-
analysisBrainList: AnalysisWebGame[]
12+
analysisTournamentList: Map<string, WorldChampionshipGameEntry[]> | null
13+
analysisLichessList: MaiaGameEntry[]
14+
analysisPlayList: MaiaGameEntry[]
15+
analysisHandList: MaiaGameEntry[]
16+
analysisBrainList: MaiaGameEntry[]
1717
}
1818

1919
export const AnalysisListContext = React.createContext<IAnalysisListContext>({
@@ -34,18 +34,14 @@ export const AnalysisListContextProvider: React.FC<{ children: ReactNode }> = ({
3434

3535
const [analysisTournamentList, setAnalysisTournamentList] = useState<Map<
3636
string,
37-
AnalysisTournamentGame[]
37+
WorldChampionshipGameEntry[]
3838
> | null>(null)
3939
const [analysisLichessList, setAnalysisLichessList] = useState<
40-
AnalysisWebGame[]
40+
MaiaGameEntry[]
4141
>([])
42-
const [analysisPlayList, setAnalysisPlayList] = useState<AnalysisWebGame[]>(
43-
[],
44-
)
45-
const [analysisHandList, setAnalysisHandList] = useState<AnalysisWebGame[]>(
46-
[],
47-
)
48-
const [analysisBrainList, setAnalysisBrainList] = useState<AnalysisWebGame[]>(
42+
const [analysisPlayList, setAnalysisPlayList] = useState<MaiaGameEntry[]>([])
43+
const [analysisHandList, setAnalysisHandList] = useState<MaiaGameEntry[]>([])
44+
const [analysisBrainList, setAnalysisBrainList] = useState<MaiaGameEntry[]>(
4945
[],
5046
)
5147

@@ -71,7 +67,7 @@ export const AnalysisListContextProvider: React.FC<{ children: ReactNode }> = ({
7167
streamLichessGames(user?.lichessId, (data) => {
7268
const result = data.pgn.match(/\[Result\s+"(.+?)"\]/)[1] || '?'
7369

74-
const game: AnalysisWebGame = {
70+
const game: MaiaGameEntry = {
7571
id: data.id,
7672
type: 'pgn',
7773
label: `${data.players.white.user?.id || 'Unknown'} vs. ${data.players.black.user?.id || 'Unknown'}`,

src/hooks/useTrainingController/useTrainingController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Chess } from 'chess.ts'
22
import { GameTree } from 'src/types'
3-
import { TrainingGame } from 'src/types/training'
3+
import { PuzzleGame } from 'src/types/puzzle'
44
import { useMemo, useCallback, useEffect } from 'react'
55
import { useTreeController } from '../useTreeController'
66

7-
const buildTrainingGameTree = (game: TrainingGame): GameTree => {
7+
const buildTrainingGameTree = (game: PuzzleGame): GameTree => {
88
if (!game.moves || game.moves.length === 0) {
99
return new GameTree(new Chess().fen())
1010
}
@@ -28,7 +28,7 @@ const buildTrainingGameTree = (game: TrainingGame): GameTree => {
2828
return tree
2929
}
3030

31-
export const useTrainingController = (game: TrainingGame) => {
31+
export const useTrainingController = (game: PuzzleGame) => {
3232
const gameTree = useMemo(() => buildTrainingGameTree(game), [game])
3333
const initialOrientation = useMemo(() => {
3434
const puzzleFen = game.moves[game.targetIndex].board

0 commit comments

Comments
 (0)