diff --git a/frontend/package.json b/frontend/package.json index 65708326..81906d0e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,7 +21,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", - "test": "react-scripts test", + "test": "react-scripts test --coverage", "eject": "react-scripts eject" }, "eslintConfig": { diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index bae8000a..de33d644 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -8,8 +8,8 @@ import { StepDto, ProofDto } from './types'; import { LOGIC } from './constant'; function App() { - const [coloringMap, setColor] = useState(new Map()); - const [isModalOpen, setModalOpen] = useState(false); + const [colorMapping, setColorMapping] = useState(new Map()); + const [isModalOpen, setIsModalOpen] = useState(false); const [proof, setProof] = useState({ steps: [], logic: LOGIC, @@ -17,20 +17,22 @@ function App() { }); const onColorChange = (color: string, line: number) => { - const newColoringMap = new Map(coloringMap); - newColoringMap.forEach((value, key) => { - if (value === color) { - newColoringMap.delete(key); - } + setColorMapping(colorMapping => { + const newColoringMap = new Map(colorMapping); + newColoringMap.forEach((value, key) => { + if (value === color) { + newColoringMap.delete(key); + } + }); + if (line >= 0) { + newColoringMap.set(line, color); + } + return newColoringMap }); - if (line >= 0) { - newColoringMap.set(line, color); - } - setColor(newColoringMap); }; - const handleOpenModal = () => setModalOpen(true); - const handleCloseModal = () => setModalOpen(false); + const handleOpenModal = () => setIsModalOpen(true); + const handleCloseModal = () => setIsModalOpen(false); const handleNewProofSubmit = (premises: string[], goal: string) => { const steps: StepDto[] = premises.map((premise) => ({ @@ -45,6 +47,7 @@ function App() { logic: LOGIC, goal: goal, }); + setColorMapping(new Map()) }; return ( @@ -54,7 +57,7 @@ function App() { New Proof - + void, @@ -26,7 +28,6 @@ function parseAction( const name = action.split('(')[0]; const inputString = action.match(/\[\s*(.*?)\s*\]/)?.[1]; const inputs = inputString ? inputString.split(',').map(input => input.trim()) : []; - const glowingColors: string[] = ['#ffcc00', '#00f2ff', '#ff69b4']; return { name, @@ -63,6 +64,8 @@ const Menu: FC = ({ logic, onColorChange, setProof, proof }) => { const newAction = event.target.value; setSelectedAction(newAction); + glowingColors.forEach((color) => onColorChange(color,-1)); + const selectedActionObj = actions.find(action => action.name === newAction); if (selectedActionObj) { const initialSources = Array(selectedActionObj.intInputs).fill(-1); @@ -107,6 +110,7 @@ const Menu: FC = ({ logic, onColorChange, setProof, proof }) => { applyAction(logic, proof, actionDto, (response: ApplyActionResponse) => { if (response.success) { setProof(response.proof); + glowingColors.forEach((color) => onColorChange(color,-1)); } else { console.error('Action failed:', response.message); alert(`Action failed: ${response.message}`);