import { GridComponent } from '@/components/grid/GridComponent'; import type { AnsiTermColor, Grid, GridCell } from '@/types/grid'; import { type IZipper, ListZipper, } from '@emprespresso/pengueno'; import { useCallback, useState } from 'react'; export interface ChooseArtProps { grid: Grid; } export const Paint: React.FC = ({ grid }) => { const [selectedColor, setSelectedColor] = useState({ foreground: { r: 5, g: 5, b: 5 }, background: null, }); const [history, setHistory] = useState>( ListZipper.from([grid]), ); const cellInteractionCallback = useCallback( (cell: GridCell) => { setHistory((currentHistory) => { const currentGrid = currentHistory.read().get(); const newGrid = currentGrid.map((row) => [...row]); // Deep copy for current state newGrid[cell.y][cell.x] = { ...cell, color: selectedColor }; return currentHistory.prepend(newGrid).previous().get(); }); }, [selectedColor], ); return (
); };