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 => { ...@@ -884,3 +884,20 @@ module.exports.updateProjectThumbnail = (id, blob) => (dispatch => {
dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.FETCHED)); 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 = ({ ...@@ -85,6 +85,7 @@ const PreviewPresentation = ({
onCopyProjectLink, onCopyProjectLink,
onDeleteComment, onDeleteComment,
onFavoriteClicked, onFavoriteClicked,
onGreenFlag,
onLoadMore, onLoadMore,
onLoveClicked, onLoveClicked,
onOpenAdminPanel, onOpenAdminPanel,
...@@ -281,6 +282,7 @@ const PreviewPresentation = ({ ...@@ -281,6 +282,7 @@ const PreviewPresentation = ({
previewInfoVisible="false" previewInfoVisible="false"
projectHost={projectHost} projectHost={projectHost}
projectId={projectId} projectId={projectId}
onGreenFlag={onGreenFlag}
onRemixing={onRemixing} onRemixing={onRemixing}
onUpdateProjectId={onUpdateProjectId} onUpdateProjectId={onUpdateProjectId}
/> />
...@@ -615,6 +617,7 @@ PreviewPresentation.propTypes = { ...@@ -615,6 +617,7 @@ PreviewPresentation.propTypes = {
onCopyProjectLink: PropTypes.func, onCopyProjectLink: PropTypes.func,
onDeleteComment: PropTypes.func, onDeleteComment: PropTypes.func,
onFavoriteClicked: PropTypes.func, onFavoriteClicked: PropTypes.func,
onGreenFlag: PropTypes.func,
onLoadMore: PropTypes.func, onLoadMore: PropTypes.func,
onLoveClicked: PropTypes.func, onLoveClicked: PropTypes.func,
onOpenAdminPanel: PropTypes.func, onOpenAdminPanel: PropTypes.func,
......
...@@ -59,6 +59,7 @@ class Preview extends React.Component { ...@@ -59,6 +59,7 @@ class Preview extends React.Component {
'handleRestoreComment', 'handleRestoreComment',
'handleAddToStudioClick', 'handleAddToStudioClick',
'handleAddToStudioClose', 'handleAddToStudioClose',
'handleGreenFlag',
'handleRemix', 'handleRemix',
'handleSeeAllComments', 'handleSeeAllComments',
'handleSeeInside', 'handleSeeInside',
...@@ -341,6 +342,9 @@ class Preview extends React.Component { ...@@ -341,6 +342,9 @@ class Preview extends React.Component {
handleReportSubmit (formData) { handleReportSubmit (formData) {
this.props.reportProject(this.state.projectId, formData, this.props.user.token); 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 () { handlePopState () {
const path = window.location.pathname.toLowerCase(); const path = window.location.pathname.toLowerCase();
const playerMode = path.indexOf('editor') === -1; const playerMode = path.indexOf('editor') === -1;
...@@ -587,6 +591,7 @@ class Preview extends React.Component { ...@@ -587,6 +591,7 @@ class Preview extends React.Component {
onCopyProjectLink={this.handleCopyProjectLink} onCopyProjectLink={this.handleCopyProjectLink}
onDeleteComment={this.handleDeleteComment} onDeleteComment={this.handleDeleteComment}
onFavoriteClicked={this.handleFavoriteToggle} onFavoriteClicked={this.handleFavoriteToggle}
onGreenFlag={this.handleGreenFlag}
onLoadMore={this.handleLoadMore} onLoadMore={this.handleLoadMore}
onLoveClicked={this.handleLoveToggle} onLoveClicked={this.handleLoveToggle}
onOpenAdminPanel={this.handleOpenAdminPanel} onOpenAdminPanel={this.handleOpenAdminPanel}
...@@ -630,6 +635,7 @@ class Preview extends React.Component { ...@@ -630,6 +635,7 @@ class Preview extends React.Component {
projectId={this.state.projectId} projectId={this.state.projectId}
projectTitle={this.props.projectInfo.title} projectTitle={this.props.projectInfo.title}
renderLogin={this.renderLogin} renderLogin={this.renderLogin}
onGreenFlag={this.handleGreenFlag}
onLogOut={this.props.handleLogOut} onLogOut={this.props.handleLogOut}
onOpenRegistration={this.props.handleOpenRegistration} onOpenRegistration={this.props.handleOpenRegistration}
onRemixing={this.handleIsRemixing} onRemixing={this.handleIsRemixing}
...@@ -696,6 +702,7 @@ Preview.propTypes = { ...@@ -696,6 +702,7 @@ Preview.propTypes = {
isNewScratcher: PropTypes.bool, isNewScratcher: PropTypes.bool,
isScratcher: PropTypes.bool, isScratcher: PropTypes.bool,
isShared: PropTypes.bool, isShared: PropTypes.bool,
logProjectView: PropTypes.func,
loved: PropTypes.bool, loved: PropTypes.bool,
moreCommentsToLoad: PropTypes.bool, moreCommentsToLoad: PropTypes.bool,
original: projectShape, original: projectShape,
...@@ -888,6 +895,9 @@ const mapDispatchToProps = dispatch => ({ ...@@ -888,6 +895,9 @@ const mapDispatchToProps = dispatch => ({
getLovedStatus: (id, username, token) => { getLovedStatus: (id, username, token) => {
dispatch(previewActions.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) => { setLovedStatus: (loved, id, username, token) => {
dispatch(previewActions.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