diff --git a/src/components/Compile.js b/src/components/Compile.js
index 946466f..7fe5932 100644
--- a/src/components/Compile.js
+++ b/src/components/Compile.js
@@ -99,7 +99,7 @@ class Compile extends Component {
this.download();
}
else {
- this.setState({ file: true, open: true, title: 'Blöcke kompilieren', content: 'Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' });
+ this.setState({ file: true, open: true, title: 'Projekt kompilieren', content: 'Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' });
}
}
@@ -111,7 +111,7 @@ class Compile extends Component {
return (
{this.props.iconButton ?
-
+ this.compile()}
diff --git a/src/components/Gallery/gallery.json b/src/components/Gallery/gallery.json
deleted file mode 100644
index 0ff72ae..0000000
--- a/src/components/Gallery/gallery.json
+++ /dev/null
@@ -1,37 +0,0 @@
-[
- {
- "id": 15212,
- "title": "Das senseBox Buch Kapitel 1",
- "name": "Mario",
- "text": "Die Blöcke findest du in der Kategorie \"Schleifen\". Die einfachste Schleife, die du Verwenden kannst, ist der Block \"Wiederhole 10 mal\". Bei diesem Block kannst du die Blöcke, die eine bestimmte Zahl wiederholt werden soll einfach in den offenen Block abschnitt ziehen. ",
- "xml": "\n \n \n \n 10\n \n \n \n"
- },
- {
- "id": 25451,
- "title": "Das senseBox Buch Kapitel 2",
- "name": "Mario",
- "text": "",
- "xml": "\n \n \n \n 1\n HIGH\n \n \n \n \n 1000\n \n \n \n \n 1\n LOW\n \n \n \n \n 1000\n \n \n \n \n \n \n \n \n \n \n \n"
- },
- {
- "id": 3541512,
- "title": "Das senseBox Buch Kapitel 3",
- "name": "Mario",
- "text": "",
- "xml": "\n \n \n \n \n \n \n \n \n WHITE,BLACK\n \n \n 1\n \n \n \n \n 0\n \n \n \n \n 0\n \n \n \n \n \n \n \n Helligkeit:\n \n \n \n \n Illuminance\n \n \n \n \n \n \n \n \n \n"
- },
- {
- "id": 7487454,
- "title": "Das senseBox Buch Kapitel 4",
- "name": "Mario",
- "text": "",
- "xml": "\n \n \n \n \n \n \n \n \n WHITE,BLACK\n \n \n 1\n \n \n \n \n 0\n \n \n \n \n 0\n \n \n \n \n \n \n \n Helligkeit:\n \n \n \n \n Illuminance\n \n \n \n \n \n \n \n \n \n"
- },
- {
- "id": 54541251,
- "title": "Das senseBox Buch Kapitel 5",
- "name": "Mario",
- "text": "",
- "xml": ""
- }
-]
\ No newline at end of file
diff --git a/src/components/Home.js b/src/components/Home.js
index 432ec06..3bce82c 100644
--- a/src/components/Home.js
+++ b/src/components/Home.js
@@ -4,23 +4,19 @@ import { connect } from 'react-redux';
import { clearStats, workspaceName } from '../actions/workspaceActions';
import * as Blockly from 'blockly/core';
-
-import axios from 'axios';
+import { createNameId } from 'mnemonic-id';
import WorkspaceStats from './WorkspaceStats';
import WorkspaceFunc from './WorkspaceFunc';
import BlocklyWindow from './Blockly/BlocklyWindow';
import CodeViewer from './CodeViewer';
import TrashcanButtons from './TrashcanButtons';
-import { createNameId } from 'mnemonic-id';
import HintTutorialExists from './Tutorial/HintTutorialExists';
import Grid from '@material-ui/core/Grid';
import IconButton from '@material-ui/core/IconButton';
import Tooltip from '@material-ui/core/Tooltip';
import { withStyles } from '@material-ui/core/styles';
-import Backdrop from '@material-ui/core/Backdrop';
-import CircularProgress from '@material-ui/core/CircularProgress';
import { faCode } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -51,22 +47,17 @@ class Home extends Component {
state = {
codeOn: false,
- gallery: [],
- share: [],
- projectToLoad: undefined,
- progress: false,
- stats: window.localStorage.getItem('stats'),
+ stats: window.localStorage.getItem('stats')
}
componentDidMount() {
- this.setState({ stats: window.localStorage.getItem('stats') })
- this.getProject();
+ this.setState({ stats: window.localStorage.getItem('stats') });
+ if(!this.props.project){
+ this.props.workspaceName(createNameId());
+ }
}
componentDidUpdate(props) {
- if(props.location.path !== this.props.location.path){
- this.getProject();
- }
/* Resize and reposition all of the workspace chrome (toolbox, trash,
scrollbars etc.) This should be called when something changes that requires
recalculating dimensions and positions of the trash, zoom, toolbox, etc.
@@ -80,37 +71,6 @@ class Home extends Component {
this.props.workspaceName(null);
}
- getProject = () => {
- if(this.props.match.params.shareId || this.props.match.params.galleryId){
- var param = this.props.match.params.shareId ? 'share' : 'gallery';
- var id = this.props.match.params[`${param}Id`];
- this.setState({progress: true});
- axios.get(`${process.env.REACT_APP_BLOCKLY_API}/${param}/${id}`)
- .then(res => {
- var data = param === 'share' ? 'content' : param;
- if(res.data[data]){
- this.props.workspaceName(res.data[data].name ? res.data[data].name : res.data[data].title);
- this.setState({ projectToLoad: res.data[data], progress: false });
- }
- else {
- this.props.workspaceName(createNameId());
- this.setState({ progress: false });
- this.props.history.push('/');
- }
- })
- .catch(err => {
- // TODO:
- this.setState({ progress: false, snackbar: true, key: Date.now(), message: `Fehler beim Aufrufen des angeforderten Programms. Versuche es noch einmal.`, type: 'error' });
- this.props.workspaceName(createNameId());
- this.props.history.push('/');
- window.scrollTo(0, 0);
- });
- }
- else {
- this.props.workspaceName(createNameId());
- }
- }
-
onChange = () => {
this.setState({ codeOn: !this.state.codeOn });
const workspace = Blockly.getMainWorkspace();
@@ -123,44 +83,35 @@ class Home extends Component {
render() {
return (
diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js
index ae3af26..86b3a55 100644
--- a/src/components/WorkspaceFunc.js
+++ b/src/components/WorkspaceFunc.js
@@ -5,6 +5,7 @@ import { clearStats, onChangeCode, workspaceName } from '../actions/workspaceAct
import * as Blockly from 'blockly/core';
+import { withRouter } from 'react-router-dom';
import axios from 'axios';
import { saveAs } from 'file-saver';
@@ -14,6 +15,7 @@ import { initialXml } from './Blockly/initialXml.js';
import Compile from './Compile';
import SolutionCheck from './Tutorial/SolutionCheck';
import Snackbar from './Snackbar';
+import Dialog from './Dialog';
import { Link } from 'react-router-dom';
@@ -25,17 +27,7 @@ import Tooltip from '@material-ui/core/Tooltip';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
-
-import Dialog from './Dialog';
-// import Dialog from '@material-ui/core/Dialog';
-import DialogActions from '@material-ui/core/DialogActions';
-import DialogContent from '@material-ui/core/DialogContent';
-import DialogContentText from '@material-ui/core/DialogContentText';
-import DialogTitle from '@material-ui/core/DialogTitle';
-
-
-
-import { faPen, faSave, faUpload, faCamera, faShare, faShareAlt, faCopy } from "@fortawesome/free-solid-svg-icons";
+import { faPen, faSave, faUpload, faFileDownload, faCamera, faShare, faShareAlt, faCopy } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
const styles = (theme) => ({
@@ -101,7 +93,23 @@ class WorkspaceFunc extends Component {
this.setState({ open: !this.state, share: false, file: false, saveFile: false, title: '', content: '' });
}
- saveXmlFile = () => {
+ saveProject = () => {
+ var body = {
+ xml: this.props.xml,
+ title: this.props.name
+ };
+ axios.post(`${process.env.REACT_APP_BLOCKLY_API}/project`, body)
+ .then(res => {
+ var project = res.data.project;
+ this.props.history.push(`/project/${project._id}`);
+ })
+ .catch(err => {
+ this.setState({ snackbar: true, key: Date.now(), message: `Fehler beim Speichern des Projektes. Versuche es noch einmal.`, type: 'error' });
+ window.scrollTo(0, 0);
+ });
+ }
+
+ downloadXmlFile = () => {
var code = this.props.xml;
this.toggleDialog();
var fileName = detectWhitespacesAndReturnReadableResult(this.state.name);
@@ -173,10 +181,10 @@ class WorkspaceFunc extends Component {
createFileName = (filetype) => {
this.setState({ file: filetype }, () => {
if (this.state.name) {
- this.state.file === 'xml' ? this.saveXmlFile() : this.getSvg()
+ this.state.file === 'xml' ? this.downloadXmlFile() : this.getSvg()
}
else {
- this.setState({ saveFile: true, file: filetype, open: true, title: this.state.file === 'xml' ? 'Blöcke speichern' : 'Screenshot erstellen', content: `Bitte gib einen Namen für die Bennenung der ${this.state.file === 'xml' ? 'XML' : 'SVG'}-Datei ein und bestätige diesen mit einem Klick auf 'Eingabe'.` });
+ this.setState({ saveFile: true, file: filetype, open: true, title: this.state.file === 'xml' ? 'Projekt herunterladen' : 'Screenshot erstellen', content: `Bitte gib einen Namen für die Bennenung der ${this.state.file === 'xml' ? 'XML' : 'SVG'}-Datei ein und bestätige diesen mit einem Klick auf 'Eingabe'.` });
}
});
}
@@ -247,7 +255,7 @@ class WorkspaceFunc extends Component {
return (
{!this.props.assessment ?
-
+
{ this.setState({ file: true, open: true, saveFile: false, title: 'Projekt benennen', content: 'Bitte gib einen Namen für das Projekt ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }) }}>
{this.props.name && !isWidthDown('xs', this.props.width) ? {this.props.name} : null}