diff --git a/src/actions/projectActions.js b/src/actions/projectActions.js index 7709ab1..28c0484 100644 --- a/src/actions/projectActions.js +++ b/src/actions/projectActions.js @@ -1,4 +1,4 @@ -import { PROJECT_PROGRESS, GET_PROJECT, GET_PROJECTS, PROJECT_TYPE } from './types'; +import { PROJECT_PROGRESS, GET_PROJECT, GET_PROJECTS, PROJECT_TYPE, PROJECT_DESCRIPTION } from './types'; import axios from 'axios'; import { workspaceName } from './workspaceActions'; @@ -11,6 +11,13 @@ export const setType = (type) => (dispatch) => { }); }; +export const setDescription = (description) => (dispatch) => { + dispatch({ + type: PROJECT_DESCRIPTION, + payload: description + }); +}; + export const getProject = (type, id) => (dispatch) => { dispatch({type: PROJECT_PROGRESS}); dispatch(setType(type)); @@ -23,6 +30,10 @@ export const getProject = (type, id) => (dispatch) => { type: GET_PROJECT, payload: project }); + dispatch({ + type: PROJECT_DESCRIPTION, + payload: project.description + }); dispatch({type: PROJECT_PROGRESS}); dispatch(returnSuccess(res.data.message, res.status, 'GET_PROJECT_SUCCESS')); } @@ -66,15 +77,24 @@ export const updateProject = () => (dispatch, getState) => { xml: workspace.code.xml, title: workspace.name } - var id = getState().project.projects[0]._id; - axios.put(`${process.env.REACT_APP_BLOCKLY_API}/project/${id}`, body) + var project = getState().project; + var id = project.projects[0]._id; + var type = project.type; + if(type==='gallery'){ + body.description = project.description; + } + axios.put(`${process.env.REACT_APP_BLOCKLY_API}/${type}/${id}`, body) .then(res => { - var project = res.data.project; + var project = res.data[type]; dispatch({ type: GET_PROJECT, payload: project }); - dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_UPDATE_SUCCESS')); + if(type === 'project'){ + dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_UPDATE_SUCCESS')); + } else { + dispatch(returnSuccess(res.data.message, res.status, 'GALLERY_UPDATE_SUCCESS')); + } }) .catch(err => { if(err.response){ @@ -110,4 +130,5 @@ export const resetProject = () => (dispatch) => { payload: [] }); dispatch(setType('')); + dispatch(setDescription('')); }; diff --git a/src/actions/types.js b/src/actions/types.js index 1afb071..32d1056 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -44,3 +44,4 @@ export const PROJECT_PROGRESS = 'PROJECT_PROGRESS'; export const GET_PROJECT = 'GET_PROJECT'; export const GET_PROJECTS = 'GET_PROJECTS'; export const PROJECT_TYPE = 'PROJECT_TYPE'; +export const PROJECT_DESCRIPTION = 'PROJECT_DESCRIPTION'; diff --git a/src/components/Project/Project.js b/src/components/Project/Project.js index 8a72713..6d467a8 100644 --- a/src/components/Project/Project.js +++ b/src/components/Project/Project.js @@ -40,9 +40,12 @@ class Project extends Component { this.props.returnErrors('', 404, 'GET_SHARE_FAIL'); } } - if(this.props.message.id === 'GET_PROJECT_SUCCESS'){ + else if(this.props.message.id === 'GET_PROJECT_SUCCESS'){ this.props.workspaceName(this.props.project.title); } + else if(this.props.message.id === 'PROJECT_DELETE_SUCCESS' || this.props.message.id === 'GALLERY_DELETE_SUCCESS'){ + this.props.history.push(`/${this.props.type}`); + } } } diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 54013d8..ef856ac 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { clearStats, onChangeCode, workspaceName } from '../actions/workspaceActions'; -import { updateProject, deleteProject } from '../actions/projectActions'; +import { updateProject, deleteProject, setDescription } from '../actions/projectActions'; import * as Blockly from 'blockly/core'; @@ -86,6 +86,7 @@ class WorkspaceFunc extends Component { saveFile: false, share: false, name: props.name, + description: props.description, snackbar: false, type: '', key: '', @@ -102,6 +103,9 @@ class WorkspaceFunc extends Component { if(this.props.message.id === 'PROJECT_UPDATE_SUCCESS'){ this.setState({ snackbar: true, key: Date.now(), message: `Das Projekt wurde erfolgreich aktualisiert.`, type: 'success' }); } + if(this.props.message.id === 'GALLERY_UPDATE_SUCCESS'){ + this.setState({ snackbar: true, key: Date.now(), message: `Das Galerie-Projekt wurde erfolgreich aktualisiert.`, type: 'success' }); + } else if(this.props.message.id === 'PROJECT_DELETE_SUCCESS'){ this.props.history.push(`/${this.props.projectType}`); } @@ -218,6 +222,10 @@ class WorkspaceFunc extends Component { this.setState({ name: e.target.value }); } + setDescription = (e) => { + this.setState({ description: e.target.value }); + } + uploadXmlFile = (xmlFile) => { if (xmlFile.type !== 'text/xml') { this.setState({ open: true, file: false, title: 'Unzulässiger Dateityp', content: 'Die übergebene Datei entsprach nicht dem geforderten Format. Es sind nur XML-Dateien zulässig.' }); @@ -255,7 +263,10 @@ class WorkspaceFunc extends Component { renameWorkspace = () => { this.props.workspaceName(this.state.name); this.toggleDialog(); - if(this.props.projectType === 'project'){ + if(this.props.projectType === 'project' || this.props.projectType === 'gallery'){ + if(this.props.projectType === 'gallery'){ + this.props.setDescription(this.state.description); + } this.props.updateProject(); } else { this.setState({ snackbar: true, type: 'success', key: Date.now(), message: `Das Projekt wurde erfolgreich in '${this.state.name}' umbenannt.` }); @@ -285,7 +296,7 @@ class WorkspaceFunc extends Component {