From 7148d66d19f049b815733fbd8277603434922a49 Mon Sep 17 00:00:00 2001
From: Delucse <46593742+Delucse@users.noreply.github.com>
Date: Thu, 3 Sep 2020 15:22:14 +0200
Subject: [PATCH] vertical tutorial stepper
---
src/components/Tutorial/StepperHorizontal.js | 70 +++++++
src/components/Tutorial/StepperVertical.js | 185 +++++++++++++++++++
src/components/Tutorial/Tutorial.js | 143 ++++++--------
src/components/Tutorial/tutorials.json | 63 +++++++
4 files changed, 374 insertions(+), 87 deletions(-)
create mode 100644 src/components/Tutorial/StepperHorizontal.js
create mode 100644 src/components/Tutorial/StepperVertical.js
diff --git a/src/components/Tutorial/StepperHorizontal.js b/src/components/Tutorial/StepperHorizontal.js
new file mode 100644
index 0000000..510d326
--- /dev/null
+++ b/src/components/Tutorial/StepperHorizontal.js
@@ -0,0 +1,70 @@
+import React, { Component } from 'react';
+
+import { withRouter } from 'react-router-dom';
+
+import tutorials from './tutorials.json';
+
+import { fade } from '@material-ui/core/styles/colorManipulator';
+import { withStyles } from '@material-ui/core/styles';
+import Button from '@material-ui/core/Button';
+import Stepper from '@material-ui/core/Stepper';
+import Step from '@material-ui/core/Step';
+import StepLabel from '@material-ui/core/StepLabel';
+
+const styles = (theme) => ({
+ stepper: {
+ backgroundColor: fade(theme.palette.primary.main, 0.6),
+ width: 'calc(100% - 40px)',
+ borderRadius: '25px',
+ padding: '0 20px',
+ margin: '20px 0',
+ display: 'flex',
+ justifyContent: 'space-between'
+ },
+ color: {
+ backgroundColor: 'transparent '
+ }
+});
+
+class StepperHorizontal extends Component {
+
+ state={
+ tutorialId: Number(this.props.match.params.tutorialId),
+ }
+
+ componentDidUpdate(props, state){
+ if(state.tutorialId !== Number(this.props.match.params.tutorialId)){
+ this.setState({tutorialId: Number(this.props.match.params.tutorialId)})
+ }
+ }
+
+ render() {
+ var tutorialId = this.state.tutorialId;
+ return (
+
+
+
+
+
+ {tutorials[tutorialId-1].title}
+
+
+
+
+
+ );
+ };
+}
+
+export default withRouter(withStyles(styles, {withTheme: true})(StepperHorizontal));
diff --git a/src/components/Tutorial/StepperVertical.js b/src/components/Tutorial/StepperVertical.js
new file mode 100644
index 0000000..6d25d1b
--- /dev/null
+++ b/src/components/Tutorial/StepperVertical.js
@@ -0,0 +1,185 @@
+import React, { Component } from 'react';
+
+import { withRouter, Link } from 'react-router-dom';
+
+import clsx from 'clsx';
+
+import tutorials from './tutorials.json';
+
+import { fade } from '@material-ui/core/styles/colorManipulator';
+import { withStyles } from '@material-ui/core/styles';
+import Button from '@material-ui/core/Button';
+import Stepper from '@material-ui/core/Stepper';
+import Step from '@material-ui/core/Step';
+import StepLabel from '@material-ui/core/StepLabel';
+import Tooltip from '@material-ui/core/Tooltip';
+import LinearProgress from '@material-ui/core/LinearProgress';
+
+const styles = (theme) => ({
+ verticalStepper: {
+ padding: 0,
+ width: '30px',
+ },
+ stepIconSmall: {
+ border: `2px solid ${theme.palette.primary.main}`,
+ borderRadius: '50%',
+ width: '12px',
+ height: '12px',
+ margin: '0 auto'
+ },
+ stepIconMedium: {
+ border: `2px solid ${theme.palette.primary.main}`,
+ borderRadius: '50%',
+ width: '18px',
+ height: '18px',
+ margin: '0 auto'
+ },
+ stepIconLarge: {
+ border: `2px solid ${theme.palette.primary.main}`,
+ borderRadius: '50%',
+ width: '24px',
+ height: '24px'
+ },
+ stepIconTransparent: {
+ border: `2px solid transparent`,
+ cursor: 'default'
+ },
+ stepIconActive: {
+ backgroundColor: fade(theme.palette.primary.main, 0.6)
+ },
+ progress: {
+ position: 'absolute',
+ top: 0,
+ right: 0,
+ marginRight: '5px',
+ width: '3px',
+ },
+ progressForeground: {
+ backgroundColor: theme.palette.primary.main
+ },
+ progressBackground: {
+ backgroundColor: fade(theme.palette.primary.main, 0.2),
+ height: '100%'
+ }
+});
+
+class StepperVertical extends Component {
+
+ state={
+ tutorialArray: Number(this.props.match.params.tutorialId) === 1 ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-1, Number(this.props.match.params.tutorialId)+4)
+ : Number(this.props.match.params.tutorialId) === 2 ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-1-1, Number(this.props.match.params.tutorialId)+3)
+ : Number(this.props.match.params.tutorialId) === tutorials.length ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-4-1, Number(this.props.match.params.tutorialId)+4)
+ : Number(this.props.match.params.tutorialId) === tutorials.length-1 ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-3-1, Number(this.props.match.params.tutorialId)+3)
+ : tutorials.slice(Number(this.props.match.params.tutorialId)-2-1,Number(this.props.match.params.tutorialId)+2),
+ tutorialId: Number(this.props.match.params.tutorialId),
+ verticalTutorialId: Number(this.props.match.params.tutorialId)
+ }
+
+ componentDidUpdate(props, state){
+ if(state.tutorialId !== Number(this.props.match.params.tutorialId)){
+ this.setState({
+ tutorialArray: Number(this.props.match.params.tutorialId) === 1 ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-1, Number(this.props.match.params.tutorialId)+4)
+ : Number(this.props.match.params.tutorialId) === 2 ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-1-1, Number(this.props.match.params.tutorialId)+3)
+ : Number(this.props.match.params.tutorialId) === tutorials.length ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-4-1, Number(this.props.match.params.tutorialId)+4)
+ : Number(this.props.match.params.tutorialId) === tutorials.length-1 ?
+ tutorials.slice(Number(this.props.match.params.tutorialId)-3-1, Number(this.props.match.params.tutorialId)+3)
+ : tutorials.slice(Number(this.props.match.params.tutorialId)-2-1,Number(this.props.match.params.tutorialId)+2),
+ tutorialId: Number(this.props.match.params.tutorialId),
+ verticalTutorialId: Number(this.props.match.params.tutorialId)
+ })
+ }
+ }
+
+ verticalStepper = (step) => {
+ var newTutorialId = this.state.verticalTutorialId + step;
+ var tutorialArray = Number(newTutorialId) === 1 ?
+ tutorials.slice(newTutorialId-1, newTutorialId+4)
+ : newTutorialId === 2 ?
+ tutorials.slice(newTutorialId-1-1, newTutorialId+3)
+ : newTutorialId === tutorials.length ?
+ tutorials.slice(newTutorialId-4-1, newTutorialId+4)
+ : newTutorialId === tutorials.length-1 ?
+ tutorials.slice(newTutorialId-3-1, newTutorialId+3)
+ : tutorials.slice(newTutorialId-2-1, newTutorialId+2);
+ this.setState({ tutorialArray: tutorialArray, verticalTutorialId: newTutorialId });
+ }
+
+ render() {
+ var tutorialId = this.state.tutorialId;
+ var verticalTutorialId = this.state.verticalTutorialId;
+ return (
+
+
+
}
+ classes={{root: this.props.classes.verticalStepper}}
+ >
+ {this.state.tutorialArray.map((tutorial, i) => {
+ var index = this.state.tutorialArray.indexOf(tutorials[verticalTutorialId-1]);
+ return (
+
+ 0 ? tutorial.title : ''} placement='right' arrow >
+
+
+
+
+
+
+ )})}
+
+
+
+
+
+ );
+ };
+}
+
+export default withRouter(withStyles(styles, {withTheme: true})(StepperVertical));
diff --git a/src/components/Tutorial/Tutorial.js b/src/components/Tutorial/Tutorial.js
index 1f85ba8..caebc9d 100644
--- a/src/components/Tutorial/Tutorial.js
+++ b/src/components/Tutorial/Tutorial.js
@@ -1,119 +1,88 @@
import React, { Component } from 'react';
-import { withRouter } from 'react-router-dom';
-
import Breadcrumbs from '../Breadcrumbs';
+import StepperHorizontal from './StepperHorizontal';
+import StepperVertical from './StepperVertical';
import BlocklyWindow from '../Blockly/BlocklyWindow';
import CodeViewer from '../CodeViewer';
import NotFound from '../NotFound';
import tutorials from './tutorials.json';
-import { fade } from '@material-ui/core/styles/colorManipulator';
-import { withStyles } from '@material-ui/core/styles';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
-import Button from '@material-ui/core/Button';
-import Stepper from '@material-ui/core/Stepper';
-import Step from '@material-ui/core/Step';
-import StepLabel from '@material-ui/core/StepLabel';
-
-
-const styles = (theme) => ({
- stepper: {
- backgroundColor: fade(theme.palette.primary.main, 0.6),
- width: 'calc(100% - 40px)',
- // opacity: 0.6,
- borderRadius: '25px',
- padding: '0 20px',
- margin: '20px 0',
- display: 'flex',
- justifyContent: 'space-between'
- },
- color: {
- backgroundColor: 'transparent '
- }
-});
class Tutorial extends Component {
state={
- value: 'introduction'
+ value: 'introduction',
+ tutorialId: Number(this.props.match.params.tutorialId)
+ }
+
+ componentDidUpdate(props, state){
+ if(state.tutorialId !== Number(this.props.match.params.tutorialId)){
+ this.setState({tutorialId: Number(this.props.match.params.tutorialId)})
+ }
}
onChange = (e, value) => {
+ console.log(value);
this.setState({ value: value });
}
render() {
- var tutorialId = Number(this.props.match.params.tutorialId);
+ var tutorialId = this.state.tutorialId;
return (
!Number.isInteger(tutorialId) || tutorialId < 1 || tutorialId > tutorials.length ?
-
- :
-
-
+
+ :
+
+
- {/* Stepper */}
-
-
-
-
-
- {tutorials[tutorialId-1].title}
-
-
-
-
+
+
+
+
+
+ {/* width of vertical stepper is 30px*/}
+
+
+
+
+
+
+
+ {this.state.value === 'introduction' ?
+ 'Hier könnte eine Anleitung stehen.': null }
+ {this.state.value === 'assessment' ?
+
+
+
+
+
+
+ Hier könnte die Problemstellung stehen.
+
+
+
+
+
+
+ : null }
+
+
+
-
-
-
-
-
-
-
-
- {this.state.value === 'introduction' ?
- 'Hier könnte eine Anleitung stehen.': null }
- {this.state.value === 'assessment' ?
-
-
-
-
-
-
- Hier könnte die Problemstellung stehen.
-
-
-
-
-
-
- : null }
-
-
);
};
}
-export default withRouter(withStyles(styles, {withTheme: true})(Tutorial));
+export default Tutorial;
diff --git a/src/components/Tutorial/tutorials.json b/src/components/Tutorial/tutorials.json
index 7b96432..04cf6cc 100644
--- a/src/components/Tutorial/tutorials.json
+++ b/src/components/Tutorial/tutorials.json
@@ -1,4 +1,67 @@
[
+ {
+ "title": "erste Schritte"
+ },
+ {
+ "title": "if-Bedingung"
+ },
+ {
+ "title": "for-Schleife"
+ },
+ {
+ "title": "erste Schritte"
+ },
+ {
+ "title": "if-Bedingung"
+ },
+ {
+ "title": "for-Schleife"
+ },
+ {
+ "title": "erste Schritte"
+ },
+ {
+ "title": "if-Bedingung"
+ },
+ {
+ "title": "for-Schleife"
+ },
+ {
+ "title": "erste Schritte"
+ },
+ {
+ "title": "if-Bedingung"
+ },
+ {
+ "title": "for-Schleife"
+ },
+ {
+ "title": "erste Schritte"
+ },
+ {
+ "title": "if-Bedingung"
+ },
+ {
+ "title": "for-Schleife"
+ },
+ {
+ "title": "erste Schritte"
+ },
+ {
+ "title": "if-Bedingung"
+ },
+ {
+ "title": "for-Schleife"
+ },
+ {
+ "title": "erste Schritte"
+ },
+ {
+ "title": "if-Bedingung"
+ },
+ {
+ "title": "for-Schleife"
+ },
{
"title": "erste Schritte"
},