import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { getTutorials, getAllTutorials, getUserTutorials, resetTutorial, tutorialProgress, } from "../../actions/tutorialActions"; import { progress } from "../../actions/tutorialBuilderActions"; import { clearMessages } from "../../actions/messageActions"; import clsx from "clsx"; import Breadcrumbs from "../Breadcrumbs"; import { Link } from "react-router-dom"; import { alpha } from "@material-ui/core/styles"; 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, faShareAlt, faEye, faUserCheck, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import * as Blockly from "blockly"; import ReactStars from "react-rating-stars-component"; import Tooltip from "@material-ui/core/Tooltip"; import IconButton from "@material-ui/core/IconButton"; import Snackbar from "../Snackbar"; import Divider from "@material-ui/core/Divider"; import DeviceSelection from "../DeviceSelection"; const styles = (theme) => ({ outerDiv: { position: "absolute", right: "-30px", bottom: "-30px", width: "160px", height: "160px", color: alpha(theme.palette.secondary.main, 0.6), }, outerDivError: { stroke: alpha(theme.palette.error.dark, 0.6), color: alpha(theme.palette.error.dark, 0.6), }, outerDivSuccess: { stroke: alpha(theme.palette.primary.main, 0.6), color: alpha(theme.palette.primary.main, 0.6), }, outerDivOther: { stroke: alpha(theme.palette.secondary.main, 0.6), }, innerDiv: { width: "inherit", height: "inherit", display: "table-cell", verticalAlign: "middle", textAlign: "center", }, button: { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, width: "40px", height: "40px", "&:hover": { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, }, }, link: { color: theme.palette.primary.main, textDecoration: "none", "&:hover": { color: theme.palette.primary.main, textDecoration: "underline", }, }, }); class TutorialHome extends Component { constructor(props) { super(props); this.state = { userTutorials: [], tutorials: [], snackbar: false, }; } componentDidMount() { this.props.tutorialProgress(); // retrieve tutorials only if a potential user is loaded - authentication // is finished (success or failed) // if (!this.props.progress) { // if (this.props.user) { // if (this.props.user.blocklyRole === "admin") { // this.props.getAllTutorials(); // } // if (this.props.user.blocklyRole === "creator") { // this.props.getUserTutorials(); // this.props.getTutorials(); // console.log("get user tutorials"); // console.log(this.props.userTutorials); // } // } else { // this.props.getTutorials(); // } // } if (!this.props.authProgress) { if (this.props.user) { if (this.props.user.role === "admin") { this.props.getAllTutorials(); } else { this.props.getUserTutorials(); //this.props.getTutorials(); } } else { this.props.getTutorials(); } } } componentDidUpdate(props, state) { if ( props.authProgress !== this.props.authProgress && !this.props.authProgress ) if (this.props.user) { if (this.props.user.role === "admin") { // authentication is completed this.props.getAllTutorials(); } else { this.props.getUserTutorials(); } } else { this.props.getTutorials(); } 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() { var userTutorials = []; const publicTutorials = this.props.tutorials.filter( (tutorial) => tutorial.public === true ); if (this.props.user && this.props.user.blocklyRole === "admin") { userTutorials = this.props.tutorials; } if (this.props.user && this.props.user.blocklyRole === "creator") { userTutorials = this.props.tutorials.filter( (tutorial) => tutorial.creator === this.props.user.email ); } return this.props.isLoading ? null : (
Creator:{tutorial.creator}