import React, { useContext, useEffect } from 'react'; import { Button, Flex, ScrollArea, Tooltip, createStyles } from '@mantine/core'; import { IconChevronLeft, IconChevronRight } from '@tabler/icons-react'; import { ChessGameContext } from '../context/chess-game-context'; const useStyles = createStyles(() => { return { movebtn: { fontSize: '14px', padding: '5px', backgroundColor: 'transparent', width: '63px', ':hover': { backgroundColor: 'transparent', } }, actionbtn: { borderRadius: '5px', backgroundColor: '#444444', ':hover': { backgroundColor: '#555555', } } }; }); const GameHistory = () => { let { classes } = useStyles(); const { gameHistory, jumpTo, goBack, goAhead } = useContext(ChessGameContext); // event listeners for keyboard keys useEffect(() => { const handleKeyDown = (event) => { if (event.key === 'ArrowLeft') { // console.log('left arrow clicked') goBack(); } else if (event.key === 'ArrowRight') { // console.log('right arrow clicked') goAhead(); } }; window.addEventListener('keydown', handleKeyDown); // event listener will cleanup when the component unmounts return () => { window.removeEventListener('keydown', handleKeyDown); }; }, [goBack, goAhead]); let gameHistoryJSX = []; for (let i = 0; i < gameHistory.length;) { let move1 = null, move2 = null; let index = i; move1 = if (i < gameHistory.length) { let index = i; move2 = } let srno = Math.ceil(i / 2); gameHistoryJSX.push(
{Math.ceil(i / 2)}.
{move1} {move2}
) } return (
{gameHistoryJSX}
); }; export default GameHistory;