|
1 | 1 | import { Fade } from "@mui/material";
|
2 | 2 | import React, { useState, useEffect } from "react";
|
| 3 | +import { useNavigate } from "react-router-dom"; |
3 | 4 | import minimizeFunction from "../core/minimizeFunction";
|
4 |
| -export let appendStep = () => {}; |
5 |
| -export let setIsResultShown = () => {}; |
| 5 | +import varStore from "../utils/varStore"; |
| 6 | +import SelectionTable from "./SelectionTable"; |
| 7 | +import PrimeImplicants from "./PrimeImplicants"; |
| 8 | +import EssentialImplicants from "./EssentialImplicants"; |
| 9 | +import PetrickMethod from "./PetrickMethod"; |
| 10 | +import TabularTable from "./TabularTable"; |
| 11 | +import MinimizedFunction from "./MinimizedFunction"; |
| 12 | +import FunctionNotation from "./FunctionNotation"; |
6 | 13 |
|
7 |
| -export default function () { |
8 |
| - const [isShown, setIsShown] = useState(true); |
9 |
| - const [children, setChildren] = useState([]); |
10 |
| - setIsResultShown = setIsShown; |
11 |
| - appendStep = (child) => { |
12 |
| - setChildren((oldChildren) => [ |
13 |
| - ...oldChildren, |
14 |
| - <div |
15 |
| - className="grid-item" |
16 |
| - key={"_" + Math.random().toString(36).substring(2, 9)} |
17 |
| - > |
18 |
| - {child} |
19 |
| - </div> |
20 |
| - ]); |
| 14 | +const Result = () => { |
| 15 | + const [steps, setSteps] = useState(null); |
| 16 | + const navigate = useNavigate(); |
| 17 | + const handleNewFunction = () => { |
| 18 | + setSteps(null); |
| 19 | + setTimeout(() => { |
| 20 | + varStore.reset(); |
| 21 | + navigate("/"); |
| 22 | + }, 500); |
21 | 23 | };
|
22 | 24 | document.body.classList.remove("centering-root");
|
23 | 25 | document.getElementById("root").classList.remove("centered-container");
|
24 | 26 | useEffect(() => {
|
25 |
| - minimizeFunction(); |
| 27 | + setSteps(minimizeFunction()); |
26 | 28 | }, []);
|
27 | 29 | return (
|
28 | 30 | <div className="mansory">
|
29 |
| - <Fade timeout={500} in={isShown} appear={isShown}> |
30 |
| - <div>{children}</div> |
| 31 | + <Fade timeout={500} in={steps} appear={steps}> |
| 32 | + <div> |
| 33 | + <div className="grid-item"> |
| 34 | + <FunctionNotation idx={1} onNewFunction={handleNewFunction} /> |
| 35 | + </div> |
| 36 | + {steps && steps.map(({ type, ...props }, index) => { |
| 37 | + return ( |
| 38 | + <div className="grid-item" key={index}> |
| 39 | + {type === "selectionTable" ? ( |
| 40 | + <SelectionTable idx={index + 2} {...props} /> |
| 41 | + ) : type === "primeImplicants" ? ( |
| 42 | + <PrimeImplicants idx={index + 2} {...props} /> |
| 43 | + ) : type === "essentialImplicants" ? ( |
| 44 | + <EssentialImplicants idx={index + 2} {...props} /> |
| 45 | + ) : type === "petrickMethod" ? ( |
| 46 | + <PetrickMethod idx={index + 2} {...props} /> |
| 47 | + ) : type === "tabularTable" ? ( |
| 48 | + <TabularTable idx={index + 2} {...props} /> |
| 49 | + ) : type === "minimizedFunction" ? ( |
| 50 | + <MinimizedFunction idx={index + 2} {...props} /> |
| 51 | + ) : null} |
| 52 | + </div> |
| 53 | + ); |
| 54 | + })} |
| 55 | + </div> |
31 | 56 | </Fade>
|
32 | 57 | </div>
|
33 | 58 | );
|
34 | 59 | }
|
| 60 | + |
| 61 | +export default Result; |
0 commit comments