add xml code changes
This commit is contained in:
		
							parent
							
								
									53b4f5dfeb
								
							
						
					
					
						commit
						d20d8b9e97
					
				| @ -19,6 +19,7 @@ | |||||||
|     "@testing-library/user-event": "^7.2.1", |     "@testing-library/user-event": "^7.2.1", | ||||||
|     "axios": "^0.21.0", |     "axios": "^0.21.0", | ||||||
|     "blockly": "^6.20210701.0", |     "blockly": "^6.20210701.0", | ||||||
|  |     "diff-js-xml": "^1.0.6", | ||||||
|     "file-saver": "^2.0.2", |     "file-saver": "^2.0.2", | ||||||
|     "mnemonic-id": "^3.2.7", |     "mnemonic-id": "^3.2.7", | ||||||
|     "moment": "^2.28.0", |     "moment": "^2.28.0", | ||||||
|  | |||||||
| @ -20,6 +20,9 @@ import Backdrop from "@material-ui/core/Backdrop"; | |||||||
| import CircularProgress from "@material-ui/core/CircularProgress"; | import CircularProgress from "@material-ui/core/CircularProgress"; | ||||||
| import Dialog from "../Dialog"; | import Dialog from "../Dialog"; | ||||||
| import Button from "@material-ui/core/Button"; | import Button from "@material-ui/core/Button"; | ||||||
|  | import { initialXml } from "../Blockly/initialXml"; | ||||||
|  | import {diffAsXml} from 'diff-js-xml'; | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| const styles = (theme) => ({ | const styles = (theme) => ({ | ||||||
|   link: { |   link: { | ||||||
| @ -130,11 +133,30 @@ class ProjectHome extends Component { | |||||||
|                         }} |                         }} | ||||||
|                       > |                       > | ||||||
|                         <div |                         <div | ||||||
|                           onClick={() => { |                           onClick={async () => { | ||||||
|                             console.log(this.props.workspaceCode.arduino); |                             const isCodeDifferent = new Promise((resolve) => { | ||||||
|                             const showDialog = |                               // resolve successfully when there is no existing workspace XML code
 | ||||||
|                               this.props.workspaceCode.arduino !== |                               if(!this.props.workspaceCode.xml) { | ||||||
|                               "void setup() { } void loop() { } "; |                                 resolve(false) | ||||||
|  |                                 return | ||||||
|  |                               } | ||||||
|  | 
 | ||||||
|  |                               // get difference of XML
 | ||||||
|  |                               // TODO: check if code of project is different to workspace code
 | ||||||
|  |                               diffAsXml( | ||||||
|  |                                 this.props.workspaceCode.xml, | ||||||
|  |                                 initialXml, | ||||||
|  |                                 undefined, | ||||||
|  |                                 undefined, | ||||||
|  |                                 (result) => { | ||||||
|  |                                   resolve(result.length !== 0); | ||||||
|  |                                 } | ||||||
|  |                               ) | ||||||
|  |                             } | ||||||
|  |                             ); | ||||||
|  | 
 | ||||||
|  |                             const showDialog = await isCodeDifferent; | ||||||
|  | 
 | ||||||
|                             if (showDialog) |                             if (showDialog) | ||||||
|                               this.setState({ |                               this.setState({ | ||||||
|                                 dialog: true, |                                 dialog: true, | ||||||
| @ -232,10 +254,10 @@ class ProjectHome extends Component { | |||||||
|               <Button |               <Button | ||||||
|                 onClick={() => { |                 onClick={() => { | ||||||
|                   this.setState({ dialog: false }); |                   this.setState({ dialog: false }); | ||||||
|  |                   // TODO: navigate to project 
 | ||||||
|                 }} |                 }} | ||||||
|                 color="secondary" |  | ||||||
|               > |               > | ||||||
|                 Schließen |                 Verwerfen | ||||||
|               </Button> |               </Button> | ||||||
|               <Button onClick={() => {}} color="primary"> |               <Button onClick={() => {}} color="primary"> | ||||||
|                 Speichern |                 Speichern | ||||||
| @ -243,7 +265,7 @@ class ProjectHome extends Component { | |||||||
|             </React.Fragment> |             </React.Fragment> | ||||||
|           } |           } | ||||||
|         > |         > | ||||||
|           Hello World |           Möchtest du deinen bisherigen Code als Projekt speichern? | ||||||
|         </Dialog> |         </Dialog> | ||||||
|       </div> |       </div> | ||||||
|     ); |     ); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user