import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { getTutorials, resetTutorial } from '../../actions/tutorialActions'; import { clearMessages } from '../../actions/messageActions'; import clsx from 'clsx'; import Breadcrumbs from '../Breadcrumbs'; import { Link } from 'react-router-dom'; import { fade } from '@material-ui/core/styles/colorManipulator'; import { withStyles } from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; import Paper from '@material-ui/core/Paper'; import Typography from '@material-ui/core/Typography'; import { faCheck, faTimes } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const styles = (theme) => ({ outerDiv: { position: 'absolute', right: '-30px', bottom: '-30px', width: '160px', height: '160px', color: fade(theme.palette.secondary.main, 0.6) }, outerDivError: { stroke: fade(theme.palette.error.dark, 0.6), color: fade(theme.palette.error.dark, 0.6) }, outerDivSuccess: { stroke: fade(theme.palette.primary.main, 0.6), color: fade(theme.palette.primary.main, 0.6) }, outerDivOther: { stroke: fade(theme.palette.secondary.main, 0.6) }, innerDiv: { width: 'inherit', height: 'inherit', display: 'table-cell', verticalAlign: 'middle', textAlign: 'center' } }); class TutorialHome extends Component { componentDidMount() { this.props.getTutorials(); } componentDidUpdate(props, state) { if(this.props.message.id === 'GET_TUTORIALS_FAIL'){ alert(this.props.message.msg); } } componentWillUnmount() { this.props.resetTutorial(); if(this.props.message.msg){ this.props.clearMessages(); } } render() { return ( this.props.isLoading ? null :

Tutorial-Übersicht

{this.props.tutorials.map((tutorial, i) => { var status = this.props.status.filter(status => status.id === tutorial.id)[0]; var tasks = status.tasks; var error = status.tasks.filter(task => task.type === 'error').length > 0; var success = status.tasks.filter(task => task.type === 'success').length / tasks.length var tutorialStatus = success === 1 ? 'Success' : error ? 'Error' : 'Other'; return ( {tutorial.title}
{error || success === 1 ? : } {success < 1 && !error ? : null}
{error || success === 1 ? : 0 ? this.props.classes.outerDivSuccess : {}}>{Math.round(success * 100)}% }
) })}
); }; } TutorialHome.propTypes = { getTutorials: PropTypes.func.isRequired, resetTutorial: PropTypes.func.isRequired, clearMessages: PropTypes.func.isRequired, status: PropTypes.array.isRequired, change: PropTypes.number.isRequired, tutorials: PropTypes.array.isRequired, isLoading: PropTypes.bool.isRequired, message: PropTypes.object.isRequired }; const mapStateToProps = state => ({ change: state.tutorial.change, status: state.tutorial.status, tutorials: state.tutorial.tutorials, isLoading: state.tutorial.progress, message: state.message }); export default connect(mapStateToProps, { getTutorials, resetTutorial, clearMessages })(withStyles(styles, { withTheme: true })(TutorialHome));