add author name to sketches
This commit is contained in:
parent
accf8e2504
commit
c3486af031
6 changed files with 47 additions and 17 deletions
|
@ -8,12 +8,14 @@ export function getProject(id) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
|
axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
console.log(response.data);
|
||||||
browserHistory.push(`/projects/${id}`);
|
browserHistory.push(`/projects/${id}`);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionTypes.SET_PROJECT,
|
type: ActionTypes.SET_PROJECT,
|
||||||
project: response.data,
|
project: response.data,
|
||||||
files: response.data.files,
|
files: response.data.files,
|
||||||
selectedFile: response.data.selectedFile
|
selectedFile: response.data.selectedFile,
|
||||||
|
owner: response.data.user
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(response => dispatch({
|
.catch(response => dispatch({
|
||||||
|
@ -61,6 +63,7 @@ export function saveProject() {
|
||||||
type: ActionTypes.NEW_PROJECT,
|
type: ActionTypes.NEW_PROJECT,
|
||||||
name: response.data.name,
|
name: response.data.name,
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
|
owner: response.data.user,
|
||||||
selectedFile: response.data.selectedFile,
|
selectedFile: response.data.selectedFile,
|
||||||
files: response.data.files
|
files: response.data.files
|
||||||
});
|
});
|
||||||
|
@ -78,11 +81,13 @@ export function createProject() {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
axios.post(`${ROOT_URL}/projects`, {}, { withCredentials: true })
|
axios.post(`${ROOT_URL}/projects`, {}, { withCredentials: true })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
console.log(response.data);
|
||||||
browserHistory.push(`/projects/${response.data.id}`);
|
browserHistory.push(`/projects/${response.data.id}`);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionTypes.NEW_PROJECT,
|
type: ActionTypes.NEW_PROJECT,
|
||||||
name: response.data.name,
|
name: response.data.name,
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
|
owner: response.data.user,
|
||||||
selectedFile: response.data.selectedFile,
|
selectedFile: response.data.selectedFile,
|
||||||
files: response.data.files
|
files: response.data.files
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,6 +40,13 @@ function Toolbar(props) {
|
||||||
>
|
>
|
||||||
{props.projectName}
|
{props.projectName}
|
||||||
</span>
|
</span>
|
||||||
|
{(() => { // eslint-disable-line
|
||||||
|
if (props.owner) {
|
||||||
|
return (
|
||||||
|
<p className="toolbar__project-owner">by <span>{props.owner.username}</span></p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
<button className={preferencesButtonClass} onClick={props.openPreferences}>
|
<button className={preferencesButtonClass} onClick={props.openPreferences}>
|
||||||
<Isvg src={preferencesUrl} alt="Show Preferences" />
|
<Isvg src={preferencesUrl} alt="Show Preferences" />
|
||||||
|
@ -55,7 +62,8 @@ Toolbar.propTypes = {
|
||||||
stopSketch: PropTypes.func.isRequired,
|
stopSketch: PropTypes.func.isRequired,
|
||||||
setProjectName: PropTypes.func.isRequired,
|
setProjectName: PropTypes.func.isRequired,
|
||||||
projectName: PropTypes.string.isRequired,
|
projectName: PropTypes.string.isRequired,
|
||||||
openPreferences: PropTypes.func.isRequired
|
openPreferences: PropTypes.func.isRequired,
|
||||||
|
owner: PropTypes.string.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Toolbar;
|
export default Toolbar;
|
||||||
|
|
|
@ -39,6 +39,7 @@ class IDEView extends React.Component {
|
||||||
setProjectName={this.props.setProjectName}
|
setProjectName={this.props.setProjectName}
|
||||||
openPreferences={this.props.openPreferences}
|
openPreferences={this.props.openPreferences}
|
||||||
isPreferencesVisible={this.props.preferences.isVisible}
|
isPreferencesVisible={this.props.preferences.isVisible}
|
||||||
|
owner={this.props.project.owner}
|
||||||
/>
|
/>
|
||||||
<Preferences
|
<Preferences
|
||||||
isVisible={this.props.preferences.isVisible}
|
isVisible={this.props.preferences.isVisible}
|
||||||
|
@ -108,7 +109,10 @@ IDEView.propTypes = {
|
||||||
startSketch: PropTypes.func.isRequired,
|
startSketch: PropTypes.func.isRequired,
|
||||||
stopSketch: PropTypes.func.isRequired,
|
stopSketch: PropTypes.func.isRequired,
|
||||||
project: PropTypes.shape({
|
project: PropTypes.shape({
|
||||||
name: PropTypes.string.isRequired
|
name: PropTypes.string.isRequired,
|
||||||
|
owner: PropTypes.shape({
|
||||||
|
username: PropTypes.string
|
||||||
|
})
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
setProjectName: PropTypes.func.isRequired,
|
setProjectName: PropTypes.func.isRequired,
|
||||||
openPreferences: PropTypes.func.isRequired,
|
openPreferences: PropTypes.func.isRequired,
|
||||||
|
|
|
@ -7,18 +7,18 @@ const initialState = {
|
||||||
const project = (state = initialState, action) => {
|
const project = (state = initialState, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionTypes.SET_PROJECT_NAME:
|
case ActionTypes.SET_PROJECT_NAME:
|
||||||
return {
|
return Object.assign({}, { ...state }, { name: action.name });
|
||||||
name: action.name
|
|
||||||
};
|
|
||||||
case ActionTypes.NEW_PROJECT:
|
case ActionTypes.NEW_PROJECT:
|
||||||
return {
|
return {
|
||||||
id: action.id,
|
id: action.id,
|
||||||
name: action.name
|
name: action.name,
|
||||||
|
owner: action.owner
|
||||||
};
|
};
|
||||||
case ActionTypes.SET_PROJECT:
|
case ActionTypes.SET_PROJECT:
|
||||||
return {
|
return {
|
||||||
id: action.project.id,
|
id: action.project.id,
|
||||||
name: action.project.name
|
name: action.project.name,
|
||||||
|
owner: action.owner
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
|
@ -54,3 +54,7 @@
|
||||||
color: $light-inactive-text-color;
|
color: $light-inactive-text-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toolbar__project-owner {
|
||||||
|
margin-left: #{5 / $base-font-size}rem;
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,12 @@ export function createProject(req, res) {
|
||||||
|
|
||||||
Project.create(projectValues, (err, newProject) => {
|
Project.create(projectValues, (err, newProject) => {
|
||||||
if (err) { return res.json({ success: false }); }
|
if (err) { return res.json({ success: false }); }
|
||||||
return res.json(newProject);
|
Project.populate(newProject,
|
||||||
|
{path: 'user', select: 'username'},
|
||||||
|
(innerErr, newProjectWithUser) => {
|
||||||
|
if (innerErr) { return res.json({ success: false }); }
|
||||||
|
return res.json(newProjectWithUser);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,14 +22,18 @@ export function updateProject(req, res) {
|
||||||
Project.findByIdAndUpdate(req.params.project_id,
|
Project.findByIdAndUpdate(req.params.project_id,
|
||||||
{
|
{
|
||||||
$set: req.body
|
$set: req.body
|
||||||
}, (err, updatedProject) => {
|
})
|
||||||
|
.populate('user', 'username')
|
||||||
|
.exec((err, updatedProject) => {
|
||||||
if (err) { return res.json({ success: false }); }
|
if (err) { return res.json({ success: false }); }
|
||||||
return res.json(updatedProject);
|
return res.json(updatedProject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProject(req, res) {
|
export function getProject(req, res) {
|
||||||
Project.findById(req.params.project_id, (err, project) => {
|
Project.findById(req.params.project_id)
|
||||||
|
.populate('user', 'username')
|
||||||
|
.exec((err, project) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(404).send({ message: 'Project with that id does not exist' });
|
return res.status(404).send({ message: 'Project with that id does not exist' });
|
||||||
}
|
}
|
||||||
|
@ -37,7 +46,7 @@ export function getProjects(req, res) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle
|
Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle
|
||||||
.sort('-createdAt')
|
.sort('-createdAt')
|
||||||
.select('name file _id createdAt updatedAt')
|
.select('name files _id createdAt updatedAt')
|
||||||
.exec((err, projects) => {
|
.exec((err, projects) => {
|
||||||
res.json(projects);
|
res.json(projects);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue