feat : add game panel info
This commit is contained in:
28
src/hooks/useEngine.ts
Normal file
28
src/hooks/useEngine.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Stockfish16 } from "@/lib/engine/stockfish16";
|
||||
import { UciEngine } from "@/lib/engine/uciEngine";
|
||||
import { EngineName } from "@/types/enums";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const useEngine = (engineName: EngineName) => {
|
||||
const [engine, setEngine] = useState<UciEngine | null>(null);
|
||||
|
||||
const pickEngine = (engine: EngineName): UciEngine => {
|
||||
switch (engine) {
|
||||
case EngineName.Stockfish16:
|
||||
return new Stockfish16();
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const engine = pickEngine(engineName);
|
||||
engine.init().then(() => {
|
||||
setEngine(engine);
|
||||
});
|
||||
|
||||
return () => {
|
||||
engine.shutdown();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return engine;
|
||||
};
|
||||
@@ -105,10 +105,14 @@ export const useGameDatabase = (shouldFetchGames?: boolean) => {
|
||||
const { gameId } = router.query;
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof gameId === "string") {
|
||||
getGame(parseInt(gameId)).then((game) => {
|
||||
setGameFromUrl(game);
|
||||
});
|
||||
switch (typeof gameId) {
|
||||
case "string":
|
||||
getGame(parseInt(gameId)).then((game) => {
|
||||
setGameFromUrl(game);
|
||||
});
|
||||
break;
|
||||
default:
|
||||
setGameFromUrl(undefined);
|
||||
}
|
||||
}, [gameId, setGameFromUrl, getGame]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user