Add project thumbnail update action

This commit is contained in:
Paul Kaplan 2018-11-29 09:55:45 -05:00
parent 42f5674a74
commit 172915f9d9
2 changed files with 26 additions and 0 deletions

View file

@ -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));
});
});

View file

@ -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}
/>
<Registration />
@ -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));
},