// --------------------------------------------------------------------------------------------------------------------- //! Imports // --------------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------- Styles -------------------------------------------------------- import { useEffect, useRef } from 'react'; import './styles.scss'; import { useRecoilState } from 'recoil'; import { gameStateAtom } from '../../contexts/gameState'; import localforage from 'localforage'; // --------------------------------------------------------------------------------------------------------------------- const store = localforage.createInstance({ name: 'leaderboard', driver: localforage.INDEXEDDB, version: 1.0, storeName: 'leaderboard', description: 'Store 10 best game time', }); const Home = () => { const difficultyRef = useRef(null); const sizeRef = useRef(null); const [, setGameState] = useRecoilState(gameStateAtom); useEffect(() => { const initIDB = async () => { if ((await store.getItem('leaderboard')) === null) { await store.setItem('leaderboard', []); } }; initIDB(); }, []); const onClick = () => { if (difficultyRef.current !== null && sizeRef.current !== null) { const difficulty = difficultyRef.current.value; const size = sizeRef.current.value; setGameState((prev) => ({ ...prev, difficulty: difficulty, gridSize: parseInt(size), status: 'idle', })); } }; return (

Démineur

Taille de la grille

Difficulté

); }; export default Home;