adjustment of the project object property 'shared'
This commit is contained in:
parent
3cf7f10d34
commit
a4cf0d32b0
@ -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
|
||||
|
@ -96,7 +96,7 @@ class ProjectHome extends Component {
|
||||
return (
|
||||
<Grid item xs={12} sm={6} md={4} xl={3} key={i}>
|
||||
<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>
|
||||
<Divider style={{marginTop: '1rem', marginBottom: '10px'}}/>
|
||||
<BlocklyWindow
|
||||
|
@ -59,7 +59,7 @@ class DeleteProject extends Component {
|
||||
<Tooltip title='Projekt löschen' arrow>
|
||||
<IconButton
|
||||
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" />
|
||||
</IconButton>
|
||||
|
@ -124,7 +124,7 @@ class SaveProject extends Component {
|
||||
<Tooltip title={this.state.projectType === 'project'? 'Projekt aktualisieren':'Projekt speichern'} arrow>
|
||||
<IconButton
|
||||
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" />
|
||||
</IconButton>
|
||||
@ -144,12 +144,12 @@ class SaveProject extends Component {
|
||||
onClose={this.toggleMenu}
|
||||
>
|
||||
<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'}
|
||||
</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'}
|
||||
</MenuItem>
|
||||
|
@ -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 {
|
||||
<FontAwesomeIcon icon={faCopy} size="xs" />
|
||||
</IconButton>
|
||||
</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 ${
|
||||
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.`}</Typography>
|
||||
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.`}</Typography>
|
||||
: <Typography variant='body2' style={{marginTop: '20px'}}>{`Der Link ist nun ${process.env.REACT_APP_SHARE_LINK_EXPIRES} Tage gültig.`}</Typography>}
|
||||
</div>
|
||||
</Dialog>
|
||||
@ -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));
|
||||
|
@ -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.` });
|
||||
|
Loading…
x
Reference in New Issue
Block a user