refacto : global refacto
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||
|
||||
type SetValue<T> = Dispatch<SetStateAction<T>>;
|
||||
|
||||
export function useLocalStorage<T>(
|
||||
export function useLocalStorage<T = string | number | boolean | undefined>(
|
||||
key: string,
|
||||
initialValue: T
|
||||
): [T | null, SetValue<T>] {
|
||||
@@ -15,7 +15,7 @@ export function useLocalStorage<T>(
|
||||
} else {
|
||||
setStoredValue(initialValue);
|
||||
}
|
||||
}, [key]);
|
||||
}, [key, initialValue]);
|
||||
|
||||
const setValue: SetValue<T> = (value) => {
|
||||
if (storedValue === null)
|
||||
|
||||
Reference in New Issue
Block a user