adjustment of the project object property 'shared'

This commit is contained in:
Delucse 2020-12-08 20:15:54 +01:00
parent 3cf7f10d34
commit a4cf0d32b0
6 changed files with 26 additions and 26 deletions

View File

@ -113,7 +113,7 @@ export const deleteProject = (type, id) => (dispatch, getState) => {
axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/${type}/${id}`) axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/${type}/${id}`)
.then(res => { .then(res => {
var projects = getState().project.projects; 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) projects.splice(index, 1)
dispatch({ dispatch({
type: GET_PROJECTS, type: GET_PROJECTS,
@ -148,10 +148,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => {
if(body.projectId){ if(body.projectId){
var projects = getState().project.projects; var projects = getState().project.projects;
var index = projects.findIndex(res => res._id === id); var index = projects.findIndex(res => res._id === id);
projects[index]._id = { projects[index].shared = shareContent.expiresAt;
_id: shareContent._id,
expiresAt: shareContent.expiresAt
};
dispatch({ dispatch({
type: GET_PROJECTS, type: GET_PROJECTS,
payload: projects payload: projects

View File

@ -96,7 +96,7 @@ class ProjectHome extends Component {
return ( return (
<Grid item xs={12} sm={6} md={4} xl={3} key={i}> <Grid item xs={12} sm={6} md={4} xl={3} key={i}>
<Paper style={{ padding: '1rem', position: 'relative', overflow: 'hidden' }}> <Paper style={{ padding: '1rem', position: 'relative', overflow: 'hidden' }}>
<Link to={`/${data === 'Projekte' ? 'project' : 'gallery'}/${project._id._id ? project._id._id : project._id}`} style={{ textDecoration: 'none', color: 'inherit' }}> <Link to={`/${data === 'Projekte' ? 'project' : 'gallery'}/${project._id}`} style={{ textDecoration: 'none', color: 'inherit' }}>
<h3 style={{marginTop: 0}}>{project.title}</h3> <h3 style={{marginTop: 0}}>{project.title}</h3>
<Divider style={{marginTop: '1rem', marginBottom: '10px'}}/> <Divider style={{marginTop: '1rem', marginBottom: '10px'}}/>
<BlocklyWindow <BlocklyWindow

View File

@ -59,7 +59,7 @@ class DeleteProject extends Component {
<Tooltip title='Projekt löschen' arrow> <Tooltip title='Projekt löschen' arrow>
<IconButton <IconButton
className={this.props.classes.buttonTrash} className={this.props.classes.buttonTrash}
onClick={() => 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)}
> >
<FontAwesomeIcon icon={faTrashAlt} size="xs" /> <FontAwesomeIcon icon={faTrashAlt} size="xs" />
</IconButton> </IconButton>

View File

@ -124,7 +124,7 @@ class SaveProject extends Component {
<Tooltip title={this.state.projectType === 'project'? 'Projekt aktualisieren':'Projekt speichern'} arrow> <Tooltip title={this.state.projectType === 'project'? 'Projekt aktualisieren':'Projekt speichern'} arrow>
<IconButton <IconButton
className={this.props.classes.button} className={this.props.classes.button}
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._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())}}
> >
<FontAwesomeIcon icon={faSave} size="xs" /> <FontAwesomeIcon icon={faSave} size="xs" />
</IconButton> </IconButton>
@ -144,12 +144,12 @@ class SaveProject extends Component {
onClose={this.toggleMenu} onClose={this.toggleMenu}
> >
<MenuItem <MenuItem
onClick={this.state.projectType === 'project' ? (e) => {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.state.projectType === 'project' ? 'Projekt aktualisieren' : 'Projekt erstellen'}
</MenuItem> </MenuItem>
<MenuItem <MenuItem
onClick={this.state.projectType === 'gallery' ? (e) => {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'} {this.state.projectType === 'gallery' ? 'Galerie-Projekt aktualisieren' : 'Galerie-Projekt erstellen'}
</MenuItem> </MenuItem>

View File

@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { shareProject } from '../../actions/projectActions'; import { shareProject } from '../../actions/projectActions';
import { clearMessages } from '../../actions/messageActions';
import moment from 'moment'; import moment from 'moment';
@ -59,30 +60,31 @@ class WorkspaceFunc extends Component {
componentDidUpdate(props) { componentDidUpdate(props) {
if(this.props.message !== props.message){ if(this.props.message !== props.message){
if(this.props.message.id === 'SHARE_SUCCESS' && (!this.props.multiple || 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 || this.props.message.status === this.props.project._id._id))){
this.setState({ share: true, open: true, title: 'Programm teilen', id: this.props.message.status }); 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 || 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 || this.props.message.status === this.props.project._id._id))){
this.setState({ snackbar: true, key: Date.now(), message: `Fehler beim Erstellen eines Links zum Teilen deines Programmes. Versuche es noch einmal.`, type: 'error' }); 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); window.scrollTo(0, 0);
} }
} }
} }
componentWillUnmount(){
this.props.clearMessages();
}
toggleDialog = () => { toggleDialog = () => {
this.setState({ open: !this.state, title: '', content: '' }); this.setState({ open: !this.state, title: '', content: '' });
} }
shareBlocks = () => { shareBlocks = () => {
if(this.props.projectType === 'project' && this.props.project._id._id){ if(this.props.projectType === 'project' && this.props.project.shared){
// project is already 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 { 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 {
<FontAwesomeIcon icon={faCopy} size="xs" /> <FontAwesomeIcon icon={faCopy} size="xs" />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
{this.props.project && this.props.project._id._id ? {this.props.project && this.props.project.shared && this.props.message.id !== 'SHARE_SUCCESS' ?
<Typography variant='body2' style={{marginTop: '20px'}}>{`Das Projekt wurde bereits geteilt. Der Link ist noch mindestens ${ <Typography variant='body2' style={{marginTop: '20px'}}>{`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.shared).diff(moment().utc(), 'days') === 0 ?
moment(this.props.project._id.expiresAt).diff(moment().utc(), 'hours') === 0 ? moment(this.props.project.shared).diff(moment().utc(), 'hours') === 0 ?
`${moment(this.props.project._id.expiresAt).diff(moment().utc(), 'minutes')} Minuten` `${moment(this.props.project.shared).diff(moment().utc(), 'minutes')} Minuten`
: `${moment(this.props.project._id.expiresAt).diff(moment().utc(), 'hours')} Stunden` : `${moment(this.props.project.shared).diff(moment().utc(), 'hours')} Stunden`
: `${moment(this.props.project._id.expiresAt).diff(moment().utc(), 'days')} Tage`} gültig.`}</Typography> : `${moment(this.props.project.shared).diff(moment().utc(), 'days')} Tage`} gültig.`}</Typography>
: <Typography variant='body2' style={{marginTop: '20px'}}>{`Der Link ist nun ${process.env.REACT_APP_SHARE_LINK_EXPIRES} Tage gültig.`}</Typography>} : <Typography variant='body2' style={{marginTop: '20px'}}>{`Der Link ist nun ${process.env.REACT_APP_SHARE_LINK_EXPIRES} Tage gültig.`}</Typography>}
</div> </div>
</Dialog> </Dialog>
@ -142,6 +144,7 @@ class WorkspaceFunc extends Component {
WorkspaceFunc.propTypes = { WorkspaceFunc.propTypes = {
shareProject: PropTypes.func.isRequired, shareProject: PropTypes.func.isRequired,
clearMessages: PropTypes.func.isRequired,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
message: PropTypes.object.isRequired message: PropTypes.object.isRequired
}; };
@ -151,4 +154,4 @@ const mapStateToProps = state => ({
message: state.message message: state.message
}); });
export default connect(mapStateToProps, { shareProject })(withStyles(styles, { withTheme: true })(WorkspaceFunc)); export default connect(mapStateToProps, { shareProject, clearMessages })(withStyles(styles, { withTheme: true })(WorkspaceFunc));

View File

@ -79,7 +79,7 @@ class WorkspaceName extends Component {
if(this.state.projectType === 'gallery'){ if(this.state.projectType === 'gallery'){
this.saveGallery(); this.saveGallery();
} else { } 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 { } else {
this.setState({ snackbar: true, type: 'success', key: Date.now(), message: `Das Projekt wurde erfolgreich in '${this.state.name}' umbenannt.` }); this.setState({ snackbar: true, type: 'success', key: Date.now(), message: `Das Projekt wurde erfolgreich in '${this.state.name}' umbenannt.` });