diff --git a/src/actions/projectActions.js b/src/actions/projectActions.js index 344140b..8ab01cf 100644 --- a/src/actions/projectActions.js +++ b/src/actions/projectActions.js @@ -113,7 +113,7 @@ export const deleteProject = (type, id) => (dispatch, getState) => { axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/${type}/${id}`) .then(res => { var projects = getState().project.projects; - var index = projects.findIndex(res => res._id === id || res._id._id === id); + var index = projects.findIndex(res => res._id === id); projects.splice(index, 1) dispatch({ type: GET_PROJECTS, @@ -148,10 +148,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => { if(body.projectId){ var projects = getState().project.projects; var index = projects.findIndex(res => res._id === id); - projects[index]._id = { - _id: shareContent._id, - expiresAt: shareContent.expiresAt - }; + projects[index].shared = shareContent.expiresAt; dispatch({ type: GET_PROJECTS, payload: projects diff --git a/src/components/Project/ProjectHome.js b/src/components/Project/ProjectHome.js index 66f8f0a..07e559b 100644 --- a/src/components/Project/ProjectHome.js +++ b/src/components/Project/ProjectHome.js @@ -96,7 +96,7 @@ class ProjectHome extends Component { return ( - +

{project.title}

this.props.deleteProject(this.props.projectType, this.props.project._id._id ? this.props.project._id._id : this.props.project._id)} + onClick={() => this.props.deleteProject(this.props.projectType, this.props.project._id)} > diff --git a/src/components/Workspace/SaveProject.js b/src/components/Workspace/SaveProject.js index 91bc17a..0a46cf0 100644 --- a/src/components/Workspace/SaveProject.js +++ b/src/components/Workspace/SaveProject.js @@ -124,7 +124,7 @@ class SaveProject extends Component { this.toggleMenu(e) : this.state.projectType === 'project' ? () => this.props.updateProject(this.state.projectType, this.props.project._id._id ? this.props.project._id._id : this.props.project._id) : () => {this.setState({projectType: 'project'}, () => this.saveProject())}} + onClick={this.props.user.blocklyRole !== 'user' && (!this.props.project || this.props.user.email === this.props.project.creator) ? (e) => this.toggleMenu(e) : this.state.projectType === 'project' ? () => this.props.updateProject(this.state.projectType, this.props.project._id) : () => {this.setState({projectType: 'project'}, () => this.saveProject())}} > @@ -144,12 +144,12 @@ class SaveProject extends Component { onClose={this.toggleMenu} > {this.toggleMenu(e); this.props.updateProject(this.state.projectType, this.props.project._id._id ? this.props.project._id._id : this.props.project._id)} : (e) => {this.toggleMenu(e); this.setState({projectType: 'project'}, () => this.saveProject())}} + onClick={this.state.projectType === 'project' ? (e) => {this.toggleMenu(e); this.props.updateProject(this.state.projectType, this.props.project._id)} : (e) => {this.toggleMenu(e); this.setState({projectType: 'project'}, () => this.saveProject())}} > {this.state.projectType === 'project' ? 'Projekt aktualisieren' : 'Projekt erstellen'} {this.toggleMenu(e); this.props.updateProject(this.state.projectType, this.props.project._id._id ? this.props.project._id._id : this.props.project._id)} : (e) => {this.toggleMenu(e); this.setState({ open: true, title: 'Projekbeschreibung ergänzen', content: 'Bitte gib eine Beschreibung für das Galerie-Projekt ein und bestätige deine Angabe mit einem Klick auf \'Eingabe\'.'});}} + onClick={this.state.projectType === 'gallery' ? (e) => {this.toggleMenu(e); this.props.updateProject(this.state.projectType, this.props.project._id)} : (e) => {this.toggleMenu(e); this.setState({ open: true, title: 'Projekbeschreibung ergänzen', content: 'Bitte gib eine Beschreibung für das Galerie-Projekt ein und bestätige deine Angabe mit einem Klick auf \'Eingabe\'.'});}} > {this.state.projectType === 'gallery' ? 'Galerie-Projekt aktualisieren' : 'Galerie-Projekt erstellen'} diff --git a/src/components/Workspace/ShareProject.js b/src/components/Workspace/ShareProject.js index f4ca60d..060e0e9 100644 --- a/src/components/Workspace/ShareProject.js +++ b/src/components/Workspace/ShareProject.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { shareProject } from '../../actions/projectActions'; +import { clearMessages } from '../../actions/messageActions'; import moment from 'moment'; @@ -59,30 +60,31 @@ class WorkspaceFunc extends Component { componentDidUpdate(props) { if(this.props.message !== props.message){ - if(this.props.message.id === 'SHARE_SUCCESS' && (!this.props.multiple || - (this.props.message.status === this.props.project._id || this.props.message.status === this.props.project._id._id))){ + if(this.props.message.id === 'SHARE_SUCCESS' && (!this.props.multiple || this.props.message.status === this.props.project._id)){ this.setState({ share: true, open: true, title: 'Programm teilen', id: this.props.message.status }); } - else if(this.props.message.id === 'SHARE_FAIL' && (!this.props.multiple || - (this.props.message.status === this.props.project._id || this.props.message.status === this.props.project._id._id))){ + else if(this.props.message.id === 'SHARE_FAIL' && (!this.props.multiple || this.props.message.status === this.props.project._id)){ this.setState({ snackbar: true, key: Date.now(), message: `Fehler beim Erstellen eines Links zum Teilen deines Programmes. Versuche es noch einmal.`, type: 'error' }); window.scrollTo(0, 0); } } } + componentWillUnmount(){ + this.props.clearMessages(); + } + toggleDialog = () => { this.setState({ open: !this.state, title: '', content: '' }); } - shareBlocks = () => { - if(this.props.projectType === 'project' && this.props.project._id._id){ + if(this.props.projectType === 'project' && this.props.project.shared){ // project is already shared - this.setState({ open: true, title: 'Programm teilen', id: this.props.project._id._id }); + this.setState({ open: true, title: 'Programm teilen', id: this.props.project._id }); } else { - this.props.shareProject(this.props.name || this.props.project.title, this.props.projectType, this.props.project ? this.props.project._id._id ? this.props.project._id._id : this.props.project._id : undefined); + this.props.shareProject(this.props.name || this.props.project.title, this.props.projectType, this.props.project ? this.props.project._id : undefined); } } @@ -125,13 +127,13 @@ class WorkspaceFunc extends Component { - {this.props.project && this.props.project._id._id ? + {this.props.project && this.props.project.shared && this.props.message.id !== 'SHARE_SUCCESS' ? {`Das Projekt wurde bereits geteilt. Der Link ist noch mindestens ${ - moment(this.props.project._id.expiresAt).diff(moment().utc(), 'days') === 0 ? - moment(this.props.project._id.expiresAt).diff(moment().utc(), 'hours') === 0 ? - `${moment(this.props.project._id.expiresAt).diff(moment().utc(), 'minutes')} Minuten` - : `${moment(this.props.project._id.expiresAt).diff(moment().utc(), 'hours')} Stunden` - : `${moment(this.props.project._id.expiresAt).diff(moment().utc(), 'days')} Tage`} gültig.`} + moment(this.props.project.shared).diff(moment().utc(), 'days') === 0 ? + moment(this.props.project.shared).diff(moment().utc(), 'hours') === 0 ? + `${moment(this.props.project.shared).diff(moment().utc(), 'minutes')} Minuten` + : `${moment(this.props.project.shared).diff(moment().utc(), 'hours')} Stunden` + : `${moment(this.props.project.shared).diff(moment().utc(), 'days')} Tage`} gültig.`} : {`Der Link ist nun ${process.env.REACT_APP_SHARE_LINK_EXPIRES} Tage gültig.`}} @@ -142,6 +144,7 @@ class WorkspaceFunc extends Component { WorkspaceFunc.propTypes = { shareProject: PropTypes.func.isRequired, + clearMessages: PropTypes.func.isRequired, name: PropTypes.string.isRequired, message: PropTypes.object.isRequired }; @@ -151,4 +154,4 @@ const mapStateToProps = state => ({ message: state.message }); -export default connect(mapStateToProps, { shareProject })(withStyles(styles, { withTheme: true })(WorkspaceFunc)); +export default connect(mapStateToProps, { shareProject, clearMessages })(withStyles(styles, { withTheme: true })(WorkspaceFunc)); diff --git a/src/components/Workspace/WorkspaceName.js b/src/components/Workspace/WorkspaceName.js index 33d94ab..9efe915 100644 --- a/src/components/Workspace/WorkspaceName.js +++ b/src/components/Workspace/WorkspaceName.js @@ -79,7 +79,7 @@ class WorkspaceName extends Component { if(this.state.projectType === 'gallery'){ this.saveGallery(); } else { - this.props.updateProject(this.props.projectType, this.props.project._id._id ? this.props.project._id._id : this.props.project._id); + this.props.updateProject(this.props.projectType, this.props.project._id); } } else { this.setState({ snackbar: true, type: 'success', key: Date.now(), message: `Das Projekt wurde erfolgreich in '${this.state.name}' umbenannt.` });