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 (

{data}

{this.props.progress ? ( ) : (
{this.props.projects.length > 0 ? ( {this.props.projects.map((project, i) => { return (

{project.title}

{project.description} {this.props.user && this.props.user.email === project.creator ? (
) : null}
); })}
) : (
Es sind aktuell keine Projekte vorhanden. {this.props.location.pathname.replace("/", "") === "project" ? ( Erstelle jetzt dein{" "} eigenes Projekt {" "} oder lasse dich von Projektbeispielen in der{" "} Galerie {" "} inspirieren. ) : null}
)}
)}
); } } ProjectHome.propTypes = { getProjects: PropTypes.func.isRequired, resetProject: PropTypes.func.isRequired, clearMessages: PropTypes.func.isRequired, projects: PropTypes.array.isRequired, progress: PropTypes.bool.isRequired, user: PropTypes.object, message: PropTypes.object.isRequired, }; const mapStateToProps = (state) => ({ projects: state.project.projects, progress: state.project.progress, user: state.auth.user, message: state.message, }); export default connect(mapStateToProps, { getProjects, resetProject, clearMessages, })(withStyles(styles, { withTheme: true })(withRouter(ProjectHome)));