From 35add63ec4dce39710095f17abd86777de9e5b49 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sat, 4 Oct 2025 18:36:10 -0700 Subject: Working history state --- src/pages/Paint.tsx | 65 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'src/pages/Paint.tsx') diff --git a/src/pages/Paint.tsx b/src/pages/Paint.tsx index 5284b26..136a347 100644 --- a/src/pages/Paint.tsx +++ b/src/pages/Paint.tsx @@ -1,11 +1,66 @@ -import { useState } from 'react'; +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 { - art: string; + grid: Grid; } -export const Paint: React.FC = ({ art: initArt }) => { - const [art, setArt] = useState(initArt); +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]), + ); - return
{art}
; + 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 ( +
+ + + +
+ ); }; -- cgit v1.2.3-70-g09d2