update project
This commit is contained in:
parent
a30747c608
commit
c5fd5c6239
@ -60,9 +60,33 @@ export const getProjects = (type) => (dispatch) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const updateProject = () => (dispatch, getState) => {
|
||||
var workspace = getState().workspace;
|
||||
var body = {
|
||||
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)
|
||||
.then(res => {
|
||||
var project = res.data.project;
|
||||
dispatch({
|
||||
type: GET_PROJECT,
|
||||
payload: project
|
||||
});
|
||||
dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_UPDATE_SUCCESS'));
|
||||
})
|
||||
.catch(err => {
|
||||
if(err.response){
|
||||
dispatch(returnErrors(err.response.data.message, err.response.status, 'PROJECT_UPDATE_FAIL'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const resetProject = () => (dispatch) => {
|
||||
dispatch({
|
||||
type: GET_PROJECTS,
|
||||
payload: []
|
||||
});
|
||||
dispatch(setType(''));
|
||||
};
|
||||
|
@ -2,6 +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 } from '../actions/projectActions';
|
||||
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
@ -87,6 +88,14 @@ class WorkspaceFunc extends Component {
|
||||
if (props.name !== this.props.name) {
|
||||
this.setState({ name: this.props.name });
|
||||
}
|
||||
if(this.props.message !== props.message){
|
||||
if(this.props.message.id === 'PROJECT_UPDATE_SUCCESS'){
|
||||
this.setState({ snackbar: true, key: Date.now(), message: `Das Projekt wurde erfolgreich aktualisiert.`, type: 'success' });
|
||||
}
|
||||
else if (this.props.message.id === 'PROJECT_UPDATE_FAIL'){
|
||||
this.setState({ snackbar: true, key: Date.now(), message: `Fehler beim Aktualisieren des Projektes. Versuche es noch einmal.`, type: 'error' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toggleDialog = () => {
|
||||
@ -265,10 +274,10 @@ class WorkspaceFunc extends Component {
|
||||
</Tooltip>
|
||||
: null}
|
||||
{this.props.assessment ? <SolutionCheck /> : <Compile iconButton />}
|
||||
<Tooltip title='Projekt speichern' arrow style={{ marginRight: '5px' }}>
|
||||
<Tooltip title={this.props.projectType === 'project'? 'Projekt aktualisieren':'Projekt speichern'} arrow style={{ marginRight: '5px' }}>
|
||||
<IconButton
|
||||
className={this.props.classes.button}
|
||||
onClick={() => this.saveProject()}
|
||||
onClick={this.props.projectType === 'project' ? () => this.props.updateProject() : () => this.saveProject()}
|
||||
>
|
||||
<FontAwesomeIcon icon={faSave} size="xs" />
|
||||
</IconButton>
|
||||
@ -376,18 +385,23 @@ class WorkspaceFunc extends Component {
|
||||
}
|
||||
|
||||
WorkspaceFunc.propTypes = {
|
||||
clearStats: PropTypes.func.isRequired,
|
||||
onChangeCode: PropTypes.func.isRequired,
|
||||
workspaceName: PropTypes.func.isRequired,
|
||||
updateProject: PropTypes.func.isRequired,
|
||||
arduino: PropTypes.string.isRequired,
|
||||
xml: PropTypes.string.isRequired,
|
||||
name: PropTypes.string,
|
||||
clearStats: PropTypes.func.isRequired,
|
||||
onChangeCode: PropTypes.func.isRequired,
|
||||
workspaceName: PropTypes.func.isRequired
|
||||
projectType: PropTypes.string.isRequired,
|
||||
message: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
arduino: state.workspace.code.arduino,
|
||||
xml: state.workspace.code.xml,
|
||||
name: state.workspace.name
|
||||
name: state.workspace.name,
|
||||
projectType: state.project.type,
|
||||
message: state.message
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, { clearStats, onChangeCode, workspaceName })(withStyles(styles, { withTheme: true })(withWidth()(withRouter(WorkspaceFunc))));
|
||||
export default connect(mapStateToProps, { clearStats, onChangeCode, workspaceName, updateProject })(withStyles(styles, { withTheme: true })(withWidth()(withRouter(WorkspaceFunc))));
|
||||
|
Loading…
x
Reference in New Issue
Block a user