From ccf901d20bd0c974961fbe944c5df69f8329e12e Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Wed, 2 Sep 2020 11:43:17 +0200 Subject: [PATCH] error page requesting a tutorial that does not (longer) exist --- src/App.css | 2 +- src/actions/workspaceActions.js | 4 +-- src/components/Breadcrumbs.js | 2 +- src/components/Home.js | 14 +++++++++- src/components/NotFound.js | 34 +++++++++++++++++++++++-- src/components/Tutorial/Tutorial.js | 21 +++++++++------ src/components/Tutorial/TutorialHome.js | 2 +- src/components/Tutorial/tutorials.json | 12 ++++++++- src/components/WorkspaceStats.js | 4 +-- src/reducers/workspaceReducer.js | 4 +-- 10 files changed, 78 insertions(+), 21 deletions(-) diff --git a/src/App.css b/src/App.css index adadb75..0241c45 100644 --- a/src/App.css +++ b/src/App.css @@ -1,5 +1,5 @@ .wrapper { - min-height: 100vh; /* will cover the 100% of viewport */ + min-height: calc(100vh - 60px); /* will cover the 100% of viewport - height of footer (padding-bottom) */ overflow: hidden; display: block; position: relative; diff --git a/src/actions/workspaceActions.js b/src/actions/workspaceActions.js index e7e08ab..be36338 100644 --- a/src/actions/workspaceActions.js +++ b/src/actions/workspaceActions.js @@ -58,10 +58,10 @@ export const onChangeWorkspace = (event) => (dispatch, getState) => { export const clearStats = () => (dispatch) => { var stats = { - create: 0, + create: -1, // initialXML is created automatically, Block is not part of the statistics change: 0, delete: 0, - move: 0 + move: -1 // initialXML is moved automatically, Block is not part of the statistics }; dispatch({ type: CLEAR_STATS, diff --git a/src/components/Breadcrumbs.js b/src/components/Breadcrumbs.js index cf41351..bc3874d 100644 --- a/src/components/Breadcrumbs.js +++ b/src/components/Breadcrumbs.js @@ -9,7 +9,7 @@ class MyBreadcrumbs extends Component { render() { return ( this.props.content && this.props.content.length > 1 ? - + {this.props.content.splice(0, this.props.content.length-1).map((content, i) => ( {content.title} diff --git a/src/components/Home.js b/src/components/Home.js index 3779d3b..5b6f71f 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -1,4 +1,7 @@ import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import { clearStats } from '../actions/workspaceActions'; import * as Blockly from 'blockly/core'; @@ -53,6 +56,10 @@ class Home extends Component { Blockly.svgResize(workspace); } + componentWillUnmount(){ + this.props.clearStats(); + } + onChange = () => { this.setState({ codeOn: !this.state.codeOn }); const workspace = Blockly.getMainWorkspace(); @@ -92,4 +99,9 @@ class Home extends Component { }; } -export default withStyles(styles, { withTheme: true })(Home); +Home.propTypes = { + clearStats: PropTypes.func.isRequired +}; + + +export default connect(null, { clearStats })(withStyles(styles, { withTheme: true })(Home)); diff --git a/src/components/NotFound.js b/src/components/NotFound.js index 132451a..44b3ddb 100644 --- a/src/components/NotFound.js +++ b/src/components/NotFound.js @@ -1,11 +1,41 @@ import React, { Component } from 'react'; +import Breadcrumbs from './Breadcrumbs'; + +import { withRouter } from 'react-router-dom'; + +import Button from '@material-ui/core/Button'; +import Typography from '@material-ui/core/Typography'; + class NotFound extends Component { render() { return ( -

404 Not Found

+
+ + Die von Ihnen angeforderte Seite kann nicht gefunden werden. + Die gesuchte Seite wurde möglicherweise entfernt, ihr Name wurde geändert oder sie ist vorübergehend nicht verfügbar. + {this.props.button ? + + : + + } +
); }; } -export default NotFound; +export default withRouter(NotFound); diff --git a/src/components/Tutorial/Tutorial.js b/src/components/Tutorial/Tutorial.js index 8b4cfa2..1f85ba8 100644 --- a/src/components/Tutorial/Tutorial.js +++ b/src/components/Tutorial/Tutorial.js @@ -1,10 +1,11 @@ import React, { Component } from 'react'; -import { withRouter, Link } from 'react-router-dom'; +import { withRouter } from 'react-router-dom'; import Breadcrumbs from '../Breadcrumbs'; import BlocklyWindow from '../Blockly/BlocklyWindow'; import CodeViewer from '../CodeViewer'; +import NotFound from '../NotFound'; import tutorials from './tutorials.json'; @@ -47,29 +48,33 @@ class Tutorial extends Component { } render() { + var tutorialId = Number(this.props.match.params.tutorialId); return ( + !Number.isInteger(tutorialId) || tutorialId < 1 || tutorialId > tutorials.length ? + + :
- + {/* Stepper */}
- -

Tutorial {this.props.match.params.tutorialId}

+

{tutorials[tutorialId-1].title}

diff --git a/src/components/Tutorial/TutorialHome.js b/src/components/Tutorial/TutorialHome.js index edd125d..323f5f1 100644 --- a/src/components/Tutorial/TutorialHome.js +++ b/src/components/Tutorial/TutorialHome.js @@ -20,7 +20,7 @@ class TutorialHome extends Component { {tutorials.map((tutorial, i) => ( - Tutorial {i+1} + {tutorials[i].title} ))} diff --git a/src/components/Tutorial/tutorials.json b/src/components/Tutorial/tutorials.json index d4bd5f9..7b96432 100644 --- a/src/components/Tutorial/tutorials.json +++ b/src/components/Tutorial/tutorials.json @@ -1 +1,11 @@ -[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}] +[ + { + "title": "erste Schritte" + }, + { + "title": "if-Bedingung" + }, + { + "title": "for-Schleife" + } +] diff --git a/src/components/WorkspaceStats.js b/src/components/WorkspaceStats.js index c3cacee..b18d4e3 100644 --- a/src/components/WorkspaceStats.js +++ b/src/components/WorkspaceStats.js @@ -42,7 +42,7 @@ class WorkspaceStats extends Component { style={{ marginRight: '1rem' }} color="primary" avatar={} - label={this.props.create}> + label={this.props.create > 0 ? this.props.create : 0}> // initialXML is created automatically, Block is not part of the statistics @@ -58,7 +58,7 @@ class WorkspaceStats extends Component { style={{ marginRight: '1rem' }} color="primary" avatar={} - label={this.props.move}> + label={this.props.move > 0 ? this.props.move : 0}> // initialXML is moved automatically, Block is not part of the statistics diff --git a/src/reducers/workspaceReducer.js b/src/reducers/workspaceReducer.js index c5bc543..dc4987f 100644 --- a/src/reducers/workspaceReducer.js +++ b/src/reducers/workspaceReducer.js @@ -7,10 +7,10 @@ const initialState = { xml: '' }, stats: { - create: 0, + create: -1, // initialXML is created automatically, Block is not part of the statistics change: 0, delete: 0, - move: 0 + move: -1 // initialXML is moved automatically, Block is not part of the statistics }, change: 0 };