import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { getProjects, resetProject } from "../../actions/projectActions"; import { clearMessages } from "../../actions/messageActions"; import { Link, withRouter } from "react-router-dom"; import Breadcrumbs from "../Breadcrumbs"; import BlocklyWindow from "../Blockly/BlocklyWindow"; import Snackbar from "../Snackbar"; import WorkspaceFunc from "../Workspace/WorkspaceFunc"; import { withStyles } from "@material-ui/core/styles"; import Grid from "@material-ui/core/Grid"; import Paper from "@material-ui/core/Paper"; import Divider from "@material-ui/core/Divider"; import Typography from "@material-ui/core/Typography"; import Backdrop from "@material-ui/core/Backdrop"; import CircularProgress from "@material-ui/core/CircularProgress"; import DeviceSelection from "../DeviceSelection"; const styles = (theme) => ({ link: { color: theme.palette.primary.main, textDecoration: "none", "&:hover": { color: theme.palette.primary.main, textDecoration: "underline", }, }, }); class ProjectHome extends Component { state = { snackbar: false, type: "", key: "", message: "", }; componentDidMount() { var type = this.props.location.pathname.replace("/", ""); this.props.getProjects(type); if (this.props.message) { if (this.props.message.id === "PROJECT_DELETE_SUCCESS") { this.setState({ snackbar: true, key: Date.now(), message: `Dein Projekt wurde erfolgreich gelöscht.`, type: "success", }); } else if (this.props.message.id === "GALLERY_DELETE_SUCCESS") { this.setState({ snackbar: true, key: Date.now(), message: `Dein Galerie-Projekt wurde erfolgreich gelöscht.`, type: "success", }); } else if (this.props.message.id === "GET_PROJECT_FAIL") { this.setState({ snackbar: true, key: Date.now(), message: `Dein angefragtes ${type === "gallery" ? "Galerie-" : "" }Projekt konnte nicht gefunden werden.`, type: "error", }); } } } componentDidUpdate(props) { if (props.location.pathname !== this.props.location.pathname) { this.setState({ snackbar: false }); this.props.getProjects(this.props.location.pathname.replace("/", "")); } if (props.message !== this.props.message) { if (this.props.message.id === "PROJECT_DELETE_SUCCESS") { this.setState({ snackbar: true, key: Date.now(), message: `Dein Projekt wurde erfolgreich gelöscht.`, type: "success", }); } else if (this.props.message.id === "GALLERY_DELETE_SUCCESS") { this.setState({ snackbar: true, key: Date.now(), message: `Dein Galerie-Projekt wurde erfolgreich gelöscht.`, type: "success", }); } } } componentWillUnmount() { this.props.resetProject(); this.props.clearMessages(); } render() { var data = this.props.location.pathname === "/project" ? "Projekte" : "Galerie"; return (