Unverified Commit 9d5788cc authored by Benjamin Wheeler's avatar Benjamin Wheeler Committed by GitHub

Merge pull request #2417 from benjiwheeler/view-count

pass onGreenFlag to GUI; when called, call API to register project view
parents d20b16d7 8dd239eb
......@@ -884,3 +884,20 @@ module.exports.updateProjectThumbnail = (id, blob) => (dispatch => {
dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.FETCHED));
});
});
module.exports.logProjectView = (id, authorUsername, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('project-log-view', module.exports.Status.FETCHING));
api({
uri: `/users/${authorUsername}/projects/${id}/views`,
method: 'POST',
authentication: token,
withCredentials: true,
useCsrf: true
}, (err, body, res) => {
if (err || res.statusCode !== 200) {
dispatch(module.exports.setFetchStatus('project-log-view', module.exports.Status.ERROR));
return;
}
dispatch(module.exports.setFetchStatus('project-log-view', module.exports.Status.FETCHED));
});
});
......@@ -85,6 +85,7 @@ const PreviewPresentation = ({
onCopyProjectLink,
onDeleteComment,
onFavoriteClicked,
onGreenFlag,
onLoadMore,
onLoveClicked,
onOpenAdminPanel,
......@@ -281,6 +282,7 @@ const PreviewPresentation = ({
previewInfoVisible="false"
projectHost={projectHost}
projectId={projectId}
onGreenFlag={onGreenFlag}
onRemixing={onRemixing}
onUpdateProjectId={onUpdateProjectId}
/>
......@@ -615,6 +617,7 @@ PreviewPresentation.propTypes = {
onCopyProjectLink: PropTypes.func,
onDeleteComment: PropTypes.func,
onFavoriteClicked: PropTypes.func,
onGreenFlag: PropTypes.func,
onLoadMore: PropTypes.func,
onLoveClicked: PropTypes.func,
onOpenAdminPanel: PropTypes.func,
......
......@@ -59,6 +59,7 @@ class Preview extends React.Component {
'handleRestoreComment',
'handleAddToStudioClick',
'handleAddToStudioClose',
'handleGreenFlag',
'handleRemix',
'handleSeeAllComments',
'handleSeeInside',
......@@ -341,6 +342,9 @@ class Preview extends React.Component {
handleReportSubmit (formData) {
this.props.reportProject(this.state.projectId, formData, this.props.user.token);
}
handleGreenFlag () {
this.props.logProjectView(this.props.projectInfo.id, this.props.authorUsername, this.props.user.token);
}
handlePopState () {
const path = window.location.pathname.toLowerCase();
const playerMode = path.indexOf('editor') === -1;
......@@ -587,6 +591,7 @@ class Preview extends React.Component {
onCopyProjectLink={this.handleCopyProjectLink}
onDeleteComment={this.handleDeleteComment}
onFavoriteClicked={this.handleFavoriteToggle}
onGreenFlag={this.handleGreenFlag}
onLoadMore={this.handleLoadMore}
onLoveClicked={this.handleLoveToggle}
onOpenAdminPanel={this.handleOpenAdminPanel}
......@@ -630,6 +635,7 @@ class Preview extends React.Component {
projectId={this.state.projectId}
projectTitle={this.props.projectInfo.title}
renderLogin={this.renderLogin}
onGreenFlag={this.handleGreenFlag}
onLogOut={this.props.handleLogOut}
onOpenRegistration={this.props.handleOpenRegistration}
onRemixing={this.handleIsRemixing}
......@@ -696,6 +702,7 @@ Preview.propTypes = {
isNewScratcher: PropTypes.bool,
isScratcher: PropTypes.bool,
isShared: PropTypes.bool,
logProjectView: PropTypes.func,
loved: PropTypes.bool,
moreCommentsToLoad: PropTypes.bool,
original: projectShape,
......@@ -888,6 +895,9 @@ const mapDispatchToProps = dispatch => ({
getLovedStatus: (id, username, token) => {
dispatch(previewActions.getLovedStatus(id, username, token));
},
logProjectView: (id, authorUsername, token) => {
dispatch(previewActions.logProjectView(id, authorUsername, token));
},
setLovedStatus: (loved, id, username, token) => {
dispatch(previewActions.setLovedStatus(loved, id, username, 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