From 6d7f0fe60935979c6c368dd520b25bf43a09b6df Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Fri, 18 Sep 2020 16:21:00 +0200 Subject: [PATCH] blockly example creator --- package.json | 1 + .../Tutorial/Builder/BlocklyExample.js | 115 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 src/components/Tutorial/Builder/BlocklyExample.js diff --git a/package.json b/package.json index 9f78c9a..2139487 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@testing-library/user-event": "^7.2.1", "blockly": "^3.20200625.2", "file-saver": "^2.0.2", + "moment": "^2.28.0", "prismjs": "^1.20.0", "react": "^16.13.1", "react-dom": "^16.13.1", diff --git a/src/components/Tutorial/Builder/BlocklyExample.js b/src/components/Tutorial/Builder/BlocklyExample.js new file mode 100644 index 0000000..9029bec --- /dev/null +++ b/src/components/Tutorial/Builder/BlocklyExample.js @@ -0,0 +1,115 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import { changeContent, deleteProperty } from '../../../actions/tutorialBuilderActions'; + +import moment from 'moment'; +import localization from 'moment/locale/de'; + +import BlocklyWindow from '../../Blockly/BlocklyWindow'; + +import { withStyles } from '@material-ui/core/styles'; +import Switch from '@material-ui/core/Switch'; +import FormControlLabel from '@material-ui/core/FormControlLabel'; +import FormLabel from '@material-ui/core/FormLabel'; +import Button from '@material-ui/core/Button'; +import Grid from '@material-ui/core/Grid'; + +const styles = (theme) => ({ + errorColor: { + color: theme.palette.error.dark + }, + errorBorder: { + border: `1px solid ${theme.palette.error.dark}` + }, + errorButton: { + marginTop: '5px', + height: '40px', + backgroundColor: theme.palette.error.dark, + '&:hover':{ + backgroundColor: theme.palette.error.dark + } + } +}); + +class BlocklyExample extends Component { + + constructor(props){ + super(props); + this.state={ + checked: props.task ? props.task : props.value ? true : false, + input: null, + }; + } + + componentDidUpdate(props){ + if(props.task !== this.props.task || props.value !== this.props.value){ + this.setState({checked: this.props.task ? this.props.task : this.props.value ? true : false}); + } + } + + onChange = (value) => { + var oldValue = this.state.checked; + this.setState({checked: value}); + console.log(!value); + if(oldValue !== value && !value){ + this.props.deleteProperty(this.props.index, 'xml'); + } + } + + render() { + moment.locale('de', localization); + return ( +
+ this.onChange(e.target.checked)} + color="primary" + /> + } + /> + {this.state.checked ? !this.props.value ? + Es ist noch keine Eingabe gemacht worden. + : Die letzte Einreichung erfolgte um {this.state.input} Uhr. + : null} + {this.state.checked ? +
+ + + + + + +
+ : null} +
+ ); + }; +} + +BlocklyExample.propTypes = { + changeContent: PropTypes.func.isRequired, + deleteProperty: PropTypes.func.isRequired, + xml: PropTypes.string.isRequired +}; + +const mapStateToProps = state => ({ + xml: state.workspace.code.xml +}); + + +export default connect(mapStateToProps, { changeContent, deleteProperty })(withStyles(styles, {withTheme: true})(BlocklyExample));