Unverified Commit 476578cf authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub

Merge pull request #2304 from paulkaplan/update-share-endpoint

Move sharing to special endpoint.
parents 805bd877 f8d59854
......@@ -55,6 +55,10 @@ module.exports.previewReducer = (state, action) => {
projectInfo: action.info ? action.info : {},
projectNotAvailable: !action.info
});
case 'UPDATE_PROJECT_INFO':
return Object.assign({}, state, {
projectInfo: Object.assign({}, state.projectInfo, action.info)
});
case 'SET_REMIXES':
return Object.assign({}, state, {
remixes: action.items
......@@ -182,6 +186,11 @@ module.exports.setProjectInfo = info => ({
info: info
});
module.exports.updateProjectInfo = info => ({
type: 'UPDATE_PROJECT_INFO',
info: info
});
module.exports.setOriginalInfo = info => ({
type: 'SET_ORIGINAL',
info: info
......@@ -770,6 +779,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.updateProjectInfo(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
......
......@@ -329,10 +329,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
);
}
......@@ -552,6 +550,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({
......@@ -708,6 +707,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));
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment