From 172915f9d935a6e9f3325678eb67dbb8f49892cb Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 29 Nov 2018 09:55:45 -0500 Subject: [PATCH] Add project thumbnail update action --- src/redux/preview.js | 21 +++++++++++++++++++++ src/views/preview/project-view.jsx | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/src/redux/preview.js b/src/redux/preview.js index fccdc0830..f677895b3 100644 --- a/src/redux/preview.js +++ b/src/redux/preview.js @@ -863,3 +863,24 @@ module.exports.reportProject = (id, jsonData, token) => (dispatch => { dispatch(module.exports.setFetchStatus('report', module.exports.Status.FETCHED)); }); }); + +module.exports.updateProjectThumbnail = (id, blob) => (dispatch => { + dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.FETCHING)); + api({ + uri: `/internalapi/project/thumbnail/${id}/set/`, + method: 'POST', + headers: { + 'Content-Type': 'image/png' + }, + withCredentials: true, + useCsrf: true, + body: blob, + host: '' // Not handled by the API, use existing infrastructure + }, (err, body, res) => { + if (err || res.statusCode !== 200) { + dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.ERROR)); + return; + } + dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.FETCHED)); + }); +}); diff --git a/src/views/preview/project-view.jsx b/src/views/preview/project-view.jsx index cc70c42fc..bfc903edf 100644 --- a/src/views/preview/project-view.jsx +++ b/src/views/preview/project-view.jsx @@ -519,6 +519,7 @@ class Preview extends React.Component { onShare={this.handleShare} onToggleLoginOpen={this.props.handleToggleLoginOpen} onUpdateProjectId={this.handleUpdateProjectId} + onUpdateProjectThumbnail={this.props.handleUpdateProjectThumbnail} onUpdateProjectTitle={this.handleUpdateProjectTitle} /> @@ -569,6 +570,7 @@ Preview.propTypes = { handleRestoreComment: PropTypes.func, handleSeeAllComments: PropTypes.func, handleToggleLoginOpen: PropTypes.func, + handleUpdateProjectThumbnail: PropTypes.func, isAdmin: PropTypes.bool, isEditable: PropTypes.bool, isLoggedIn: PropTypes.bool, @@ -717,6 +719,9 @@ const mapDispatchToProps = dispatch => ({ dispatch(previewActions.resetComments()); dispatch(previewActions.getTopLevelComments(id, 0, isAdmin, token)); }, + handleUpdateProjectThumbnail: (id, blob) => { + dispatch(previewActions.updateProjectThumbnail(id, blob)); + }, getOriginalInfo: id => { dispatch(previewActions.getOriginalInfo(id)); },