()
| 17 | } from 'lucide-react'; |
| 18 | |
| 19 | const MovesTable = () => { |
| 20 | const [userSelectedMoveIndex, setUserSelectedMoveIndex] = useRecoilState( |
| 21 | userSelectedMoveIndexAtom, |
| 22 | ); |
| 23 | const setIsFlipped = useSetRecoilState(isBoardFlippedAtom); |
| 24 | const moves = useRecoilValue(movesAtom); |
| 25 | const movesTableRef = useRef<HTMLInputElement>(null); |
| 26 | const movesArray = moves.reduce((result, _, index: number, array: Move[]) => { |
| 27 | if (index % 2 === 0) { |
| 28 | result.push(array.slice(index, index + 2)); |
| 29 | } |
| 30 | return result; |
| 31 | }, [] as Move[][]); |
| 32 | |
| 33 | useEffect(() => { |
| 34 | if (movesTableRef && movesTableRef.current) { |
| 35 | movesTableRef.current.scrollTo({ |
| 36 | top: movesTableRef.current.scrollHeight, |
| 37 | behavior: 'smooth', |
| 38 | }); |
| 39 | } |
| 40 | }, [moves]); |
| 41 | return ( |
| 42 | <div className="text-[#C3C3C0] relative w-full "> |
| 43 | <div |
| 44 | className="text-sm h-[45vh] max-h-[45vh] overflow-y-auto" |
| 45 | ref={movesTableRef} |
| 46 | > |
| 47 | {movesArray.map((movePairs, index) => { |
| 48 | return ( |
| 49 | <div |
| 50 | key={index} |
| 51 | className={`w-full py-px px-4 font-bold items-stretch ${index % 2 !== 0 ? 'bg-[#2B2927]' : ''}`} |
| 52 | > |
| 53 | <div className="grid grid-cols-6 gap-16 w-4/5"> |
| 54 | <span className="text-[#C3C3C0] px-2 py-1.5">{`${index + 1}.`}</span> |
| 55 | |
| 56 | {movePairs.map((move, movePairIndex) => { |
| 57 | const isLastIndex = |
| 58 | movePairIndex === movePairs.length - 1 && |
| 59 | movesArray.length - 1 === index; |
| 60 | const isHighlighted = |
| 61 | userSelectedMoveIndex !== null |
| 62 | ? userSelectedMoveIndex === index * 2 + movePairIndex |
| 63 | : isLastIndex; |
| 64 | const { san } = move; |
| 65 | |
| 66 | return ( |
| 67 | <div |
| 68 | key={movePairIndex} |
| 69 | className={`col-span-2 cursor-pointer flex items-center w-full pl-1 ${isHighlighted ? 'bg-[#484644] rounded border-b-[#5A5858] border-b-[3px]' : ''}`} |
| 70 | onClick={() => { |
| 71 | setUserSelectedMoveIndex(index * 2 + movePairIndex); |
| 72 | }} |
| 73 | > |
| 74 | <span className="text-[#C3C3C0]">{san}</span> |
| 75 | </div> |
| 76 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected