mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
Move sharing to special endpoint.
This makes a couple of assumptions about the shape of the endpoint: - Route is /proxy/projects/: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.
This commit is contained in:
parent
25f7f5b273
commit
3a03f10aff
2 changed files with 24 additions and 3 deletions
|
@ -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/projects/${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
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -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));
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue