From 3a03f10aff3e1992b47ac60dab7e382679367240 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 13 Nov 2018 08:49:37 -0500 Subject: [PATCH] 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. --- src/redux/preview.js | 19 +++++++++++++++++++ src/views/preview/preview.jsx | 8 +++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/redux/preview.js b/src/redux/preview.js index 8b25aaf1c..d8a8d6f62 100644 --- a/src/redux/preview.js +++ b/src/redux/preview.js @@ -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 diff --git a/src/views/preview/preview.jsx b/src/views/preview/preview.jsx index 7767648db..10491040f 100644 --- a/src/views/preview/preview.jsx +++ b/src/views/preview/preview.jsx @@ -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)); },