refacto : global refacto

This commit is contained in:
GuillaumeSD
2024-02-22 23:18:02 +01:00
parent 2a74b62bae
commit 2af0959e82
24 changed files with 230 additions and 190 deletions

View File

@@ -1,4 +1,7 @@
import { Game, GameEval } from "@/types/game";
import { formatGameToDatabase } from "@/lib/chess";
import { GameEval } from "@/types/eval";
import { Game } from "@/types/game";
import { Chess } from "chess.js";
import { openDB, DBSchema, IDBPDatabase } from "idb";
import { atom, useAtom } from "jotai";
import { useCallback, useEffect, useState } from "react";
@@ -48,10 +51,11 @@ export const useGameDatabase = (shouldFetchGames?: boolean) => {
loadGames();
}, [loadGames]);
const addGame = async (game: Omit<Game, "id">) => {
const addGame = async (game: Chess) => {
if (!db) throw new Error("Database not initialized");
await db.add("games", game as Game);
const gameToAdd = formatGameToDatabase(game);
await db.add("games", gameToAdd as Game);
loadGames();
};