Skip to content

Commit

Permalink
Move sharing to special endpoint.
Browse files Browse the repository at this point in the history
This makes a couple of assumptions about the shape of the endpoint:
- Route is /proxy/project/:id/share.
- Returns the full (updated) project info on success, just like the project update endpoint does.

I reviewed these with colby since this is frontrunning the actual API, but I can update once the API is finalized.
  • Loading branch information
paulkaplan committed Nov 13, 2018
1 parent 25f7f5b commit 29eec05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/redux/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,25 @@ module.exports.restoreComment = (projectId, commentId, topLevelCommentId, token)
});
});

module.exports.shareProject = (projectId, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('project', module.exports.Status.FETCHING));
api({
uri: `/proxy/project/${projectId}/share`,
authentication: token,
withCredentials: true,
method: 'PUT',
useCsrf: true
}, (err, body, res) => {
if (err || res.statusCode !== 200) {
dispatch(module.exports.setFetchStatus('project', module.exports.Status.ERROR));
dispatch(module.exports.setError(err));
return;
}
dispatch(module.exports.setFetchStatus('project', module.exports.Status.FETCHED));
dispatch(module.exports.setProjectInfo(body));
});
});

module.exports.reportProject = (id, jsonData, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('report', module.exports.Status.FETCHING));
// scratchr2 will fail if no thumbnail base64 string provided. We don't yet have
Expand Down
8 changes: 5 additions & 3 deletions src/views/preview/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,8 @@ class Preview extends React.Component {
this.props.setPlayer(false);
}
handleShare () {
this.props.updateProject(
this.props.shareProject(
this.props.projectInfo.id,
{isPublished: true},
this.props.user.username,
this.props.user.token
);
}
Expand Down Expand Up @@ -542,6 +540,7 @@ Preview.propTypes = {
setFullScreen: PropTypes.func.isRequired,
setLovedStatus: PropTypes.func.isRequired,
setPlayer: PropTypes.func.isRequired,
shareProject: PropTypes.func.isRequired,
toggleStudio: PropTypes.func.isRequired,
updateProject: PropTypes.func.isRequired,
user: PropTypes.shape({
Expand Down Expand Up @@ -694,6 +693,9 @@ const mapDispatchToProps = dispatch => ({
setLovedStatus: (loved, id, username, token) => {
dispatch(previewActions.setLovedStatus(loved, id, username, token));
},
shareProject: (id, token) => {
dispatch(previewActions.shareProject(id, token));
},
reportProject: (id, formData, token) => {
dispatch(previewActions.reportProject(id, formData, token));
},
Expand Down

0 comments on commit 29eec05

Please sign in to comment.