-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* set up webpack and package.json * set up material ui (mui) components * refactor, prepare type definitions * disable dev overlay, remove validation TODOs, add error boundary, refactor * address comments
- Loading branch information
1 parent
fe4fd3b
commit 07ec7a7
Showing
7 changed files
with
466 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import SvgDisplay from "./SvgDisplay"; | ||
|
||
const DEMO_OBJECTS = [ | ||
{ | ||
isClass: true, | ||
name: "__main__", | ||
id: null, | ||
value: { lst1: 82, lst2: 84, p: 99, d: 10, t: 11 }, | ||
stack_frame: true, | ||
}, | ||
{ | ||
isClass: false, | ||
name: "str", | ||
id: 19, | ||
value: "David is cool!", | ||
style: ["highlight"], | ||
}, | ||
{ isClass: false, name: "int", id: 13, value: 7 }, | ||
]; | ||
import MemoryModelsUserInput from "./MemoryModels"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
|
||
export default function App() { | ||
const [formData, setFormData] = useState(""); | ||
const [jsonResult, setJsonResult] = useState(null); | ||
|
||
const onSubmit = async (event) => { | ||
event.preventDefault(); | ||
try { | ||
setJsonResult(JSON.parse(formData)); | ||
} catch (error) { | ||
console.error("Error parsing inputted JSON: ", error); | ||
setJsonResult(null); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<MemoryModelsUserInput | ||
formData={formData} | ||
setFormData={setFormData} | ||
onSubmit={onSubmit} | ||
/> | ||
<section> | ||
<h2>Input</h2> | ||
<pre>{JSON.stringify(DEMO_OBJECTS)}</pre> | ||
<h2>Output</h2> | ||
<ErrorBoundary fallback={<div>Something went wrong</div>}> | ||
<SvgDisplay jsonResult={jsonResult} /> | ||
</ErrorBoundary> | ||
</section> | ||
<SvgDisplay /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from "react"; | ||
import { Button, Card, CardContent, TextField, Grid } from "@mui/material"; | ||
|
||
export default function MemoryModelsUserInput(props) { | ||
const handleTextFieldChange = (event) => { | ||
props.setFormData(event.target.value); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={props.onSubmit}> | ||
<Card> | ||
<CardContent> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12}> | ||
<TextField | ||
id="multiline-textfield" | ||
label="Enter memory model JSON here" | ||
multiline | ||
fullWidth | ||
rows={10} | ||
maxRows={20} | ||
variant="outlined" | ||
value={props.formData} | ||
onChange={handleTextFieldChange} | ||
style={{ | ||
width: "100%", | ||
fontFamily: "Monospace", | ||
}} | ||
/> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<Button | ||
type="submit" | ||
variant="contained" | ||
color="primary" | ||
style={{ textTransform: "none" }} | ||
> | ||
Draw Diagram | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
</CardContent> | ||
</Card> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,20 @@ | ||
import React, { useRef, useEffect } from "react"; | ||
import mem from "../../src/index"; // TODO: replace with import of the package after it's been published | ||
|
||
const DEMO_OBJECTS = [ | ||
{ | ||
isClass: true, | ||
name: "__main__", | ||
id: null, | ||
value: { lst1: 82, lst2: 84, p: 99, d: 10, t: 11 }, | ||
stack_frame: true, | ||
}, | ||
{ | ||
isClass: false, | ||
name: "str", | ||
id: 19, | ||
value: "David is cool!", | ||
style: ["highlight"], | ||
}, | ||
{ isClass: false, name: "int", id: 13, value: 7 }, | ||
]; | ||
|
||
export default function SvgDisplay() { | ||
export default function SvgDisplay(props) { | ||
const canvasRef = useRef(null); | ||
|
||
useEffect(() => { | ||
const m = mem.draw(DEMO_OBJECTS, true, { width: 1300 }); | ||
m.render(canvasRef.current); | ||
}, []); | ||
if (props.jsonResult !== null) { | ||
const m = mem.draw(props.jsonResult, true, { width: 1300 }); | ||
m.clear(canvasRef.current); | ||
m.render(canvasRef.current); | ||
} | ||
}, [props.jsonResult]); | ||
|
||
return ( | ||
<section> | ||
<h2>Output</h2> | ||
<> | ||
<canvas ref={canvasRef} width={1000} height={1000} />; | ||
</section> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.