Skip to content

Commit ac32cd4

Browse files
fix: turing page load bug
1 parent 6fe232a commit ac32cd4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/hooks/useTuringController/useTuringController.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useRouter } from 'next/router'
22
import { useState, useCallback, useEffect, useMemo } from 'react'
3+
import { Chess } from 'chess.ts'
34

45
import { useStats } from '../useStats'
5-
import { Color } from 'src/types'
6+
import { Color, GameTree } from 'src/types'
67
import { TuringGame } from 'src/types/turing'
78
import { useTreeController } from '../useTreeController'
89
import {
@@ -52,7 +53,8 @@ export const useTuringController = () => {
5253
[turingGames, currentIndex],
5354
)
5455

55-
const controller = useTreeController(game.tree, 'white')
56+
const fallbackTree = useMemo(() => new GameTree(new Chess().fen()), [])
57+
const controller = useTreeController(game?.tree ?? fallbackTree, 'white')
5658

5759
useEffect(() => {
5860
if (controller.tree && game) {

0 commit comments

Comments
 (0)