File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use client' ;
22
3- import React , { useState } from 'react' ;
3+ import React , { useState , useEffect } from 'react' ;
44import Chessboard from "@/app/_client_components/Chessboard" ;
55import RightSidePanel from "@/app/_client_components/RightSidePanel" ;
6+ import { ChessService } from "@/app/_services/ChessService" ;
7+ import { ChessGame } from "@/app/_models/ChessGame" ;
68
7- export default function ChessGameWrapper ( { gameInfo} : any ) {
9+ const gameService = new ChessService ( ) ;
10+
11+ export default function ChessGameWrapper ( { gameInfo : initialGameInfo } : { gameInfo : ChessGame | null } ) {
812 const [ isBotMode , setIsBotMode ] = useState ( false ) ;
13+ const [ gameInfo , setGameInfo ] = useState < ChessGame | null > ( initialGameInfo ) ;
14+
15+ // If no initial game info, fetch it on the client side
16+ useEffect ( ( ) => {
17+ if ( ! gameInfo ) {
18+ gameService . getChessGame ( ) . then ( info => {
19+ if ( info ) {
20+ setGameInfo ( info ) ;
21+ }
22+ } ) . catch ( error => {
23+ console . error ( "Failed to fetch game info:" , error ) ;
24+ } ) ;
25+ }
26+ } , [ gameInfo ] ) ;
27+
28+ // Show loading state if game info isn't available yet
29+ if ( ! gameInfo ) {
30+ return (
31+ < >
32+ < div className = "left-panel" >
33+ < div > Loading chess game...</ div >
34+ </ div >
35+ < div className = "right-panel" >
36+ < div > Loading...</ div >
37+ </ div >
38+ </ >
39+ ) ;
40+ }
941
1042 return (
1143 < >
Original file line number Diff line number Diff line change @@ -6,12 +6,22 @@ import {ChessGame} from "@/app/_models/ChessGame";
66import { metadata } from "@/app/layout" ;
77import ChessGameWrapper from "@/app/_client_components/ChessGameWrapper" ;
88
9+ // Force dynamic rendering to avoid build-time fetch issues
10+ export const dynamic = 'force-dynamic' ;
911
1012export default async function Home ( ) {
1113 let title : 'Chess' ;
1214 let description : 'Chess Engine' ;
1315 let gameService : ChessService = new ChessService ( ) ;
14- let gameInfo : ChessGame = await gameService . getChessGame ( ) ;
16+ let gameInfo : ChessGame | null = null ;
17+
18+ try {
19+ gameInfo = await gameService . getChessGame ( ) ;
20+ } catch ( error ) {
21+ console . error ( "Failed to fetch initial game state:" , error ) ;
22+ // gameInfo will remain null, client components will handle it
23+ }
24+
1525 let currentDate = new Date ( ) ;
1626
1727 return (
You can’t perform that action at this time.
0 commit comments