improve code reset
This commit is contained in:
		
							parent
							
								
									8616a7d732
								
							
						
					
					
						commit
						f388828c88
					
				| @ -9,7 +9,8 @@ import { saveAs } from "file-saver"; | |||||||
| import Drawer from "@material-ui/core/Drawer"; | import Drawer from "@material-ui/core/Drawer"; | ||||||
| import Sidebar from "./Sidebar"; | import Sidebar from "./Sidebar"; | ||||||
| import Dialog from "../Dialog"; | import Dialog from "../Dialog"; | ||||||
| import SaveIcon from './SaveIcon' | import SaveIcon from "./SaveIcon"; | ||||||
|  | import store from "../../store"; | ||||||
| 
 | 
 | ||||||
| const CodeEditor = (props) => { | const CodeEditor = (props) => { | ||||||
|   const [fileHandle, setFileHandle] = useState(); |   const [fileHandle, setFileHandle] = useState(); | ||||||
| @ -22,6 +23,8 @@ const CodeEditor = (props) => { | |||||||
|   const [autoSave, setAutoSave] = useState(false); |   const [autoSave, setAutoSave] = useState(false); | ||||||
|   const [time, setTime] = useState(null); |   const [time, setTime] = useState(null); | ||||||
|   const [value, setValue] = useState(""); |   const [value, setValue] = useState(""); | ||||||
|  |   const [resetDialog, setResetDialog] = useState(false); | ||||||
|  |   const [blocklyCode, setBlocklyCode] = useState(""); | ||||||
|   const [defaultValue, setDefaultValue] = useState( |   const [defaultValue, setDefaultValue] = useState( | ||||||
|     sessionStorage.getItem("ArduinoCode") |     sessionStorage.getItem("ArduinoCode") | ||||||
|       ? sessionStorage.getItem("ArduinoCode") |       ? sessionStorage.getItem("ArduinoCode") | ||||||
| @ -101,7 +104,18 @@ void loop() { | |||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   const resetCode = () => { |   const resetCode = () => { | ||||||
|     editorRef.current.setValue(defaultValue); |     const resetCode = ` | ||||||
|  | #include <senseBoxIO.h> //needs to be always included
 | ||||||
|  |      | ||||||
|  | void setup () { | ||||||
|  |               | ||||||
|  | } | ||||||
|  |                | ||||||
|  | void loop() { | ||||||
|  |                | ||||||
|  | }`;
 | ||||||
|  | 
 | ||||||
|  |     editorRef.current.setValue(resetCode); | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   const resetTimeout = (id, newID) => { |   const resetTimeout = (id, newID) => { | ||||||
| @ -128,6 +142,11 @@ void loop() { | |||||||
|     setOpen(false); |     setOpen(false); | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  |   const getBlocklyCode = () => { | ||||||
|  |     var code = store.getState().workspace.code.arduino; | ||||||
|  |     editorRef.current.setValue(code); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|   return ( |   return ( | ||||||
|     <div> |     <div> | ||||||
|       <Grid container spacing={2}> |       <Grid container spacing={2}> | ||||||
| @ -167,7 +186,7 @@ void loop() { | |||||||
|           </p> |           </p> | ||||||
|         </Drawer> |         </Drawer> | ||||||
|         <Grid item lg={8}> |         <Grid item lg={8}> | ||||||
|           <div style={{display: "flex", alignItems: "center"}}> |           <div style={{ display: "flex", alignItems: "center" }}> | ||||||
|             <h1>Code Editor</h1> |             <h1>Code Editor</h1> | ||||||
|             <SaveIcon loading={autoSave} /> |             <SaveIcon loading={autoSave} /> | ||||||
|           </div> |           </div> | ||||||
| @ -214,12 +233,19 @@ void loop() { | |||||||
|             style={{ padding: "1rem", margin: "1rem" }} |             style={{ padding: "1rem", margin: "1rem" }} | ||||||
|             variant="contained" |             variant="contained" | ||||||
|             color="primary" |             color="primary" | ||||||
|             onClick={() => resetCode()} |             onClick={() => setResetDialog(true)} | ||||||
|           > |           > | ||||||
|             Reset Editor |             Reset Editor | ||||||
|           </Button> |           </Button> | ||||||
|  |           <Button | ||||||
|  |             style={{ padding: "1rem", margin: "1rem" }} | ||||||
|  |             variant="contained" | ||||||
|  |             color="primary" | ||||||
|  |             onClick={() => getBlocklyCode()} | ||||||
|  |           > | ||||||
|  |             getBlocklyCode | ||||||
|  |           </Button> | ||||||
|           <Sidebar /> |           <Sidebar /> | ||||||
| 
 |  | ||||||
|           <Dialog |           <Dialog | ||||||
|             style={{ zIndex: 9999999 }} |             style={{ zIndex: 9999999 }} | ||||||
|             fullWidth |             fullWidth | ||||||
| @ -232,6 +258,32 @@ void loop() { | |||||||
|               Dein Code wird nun kompiliert und anschließend auf deinen Computer |               Dein Code wird nun kompiliert und anschließend auf deinen Computer | ||||||
|               heruntergeladen |               heruntergeladen | ||||||
|             </div> |             </div> | ||||||
|  |           </Dialog>{" "} | ||||||
|  |           <Dialog | ||||||
|  |             open={resetDialog} | ||||||
|  |             title={Blockly.Msg.resetDialog_headline} | ||||||
|  |             content={Blockly.Msg.resetDialog_text} | ||||||
|  |             onClose={() => { | ||||||
|  |               setResetDialog(false); | ||||||
|  |             }} | ||||||
|  |             onClick={() => { | ||||||
|  |               setResetDialog(false); | ||||||
|  |             }} | ||||||
|  |             button={Blockly.Msg.button_cancel} | ||||||
|  |           > | ||||||
|  |             {" "} | ||||||
|  |             <div style={{ marginTop: "10px" }}> | ||||||
|  |               <Button | ||||||
|  |                 variant="contained" | ||||||
|  |                 color="primary" | ||||||
|  |                 onClick={() => { | ||||||
|  |                   resetCode(); | ||||||
|  |                   setResetDialog(false); | ||||||
|  |                 }} | ||||||
|  |               > | ||||||
|  |                 Zurücksetzen | ||||||
|  |               </Button> | ||||||
|  |             </div> | ||||||
|           </Dialog> |           </Dialog> | ||||||
|         </Grid> |         </Grid> | ||||||
|       </Grid> |       </Grid> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user