From 9b485cd16cbda2445dd9840a8869ec25d3ef9f95 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Thu, 4 Apr 2019 15:04:27 -0400 Subject: [PATCH 1/3] Revert "Merge pull request #2871 from benjiwheeler/pass-ownerusername-to-comment-replies-endpoint" This reverts commit afe6d6f4a4988509b12a4072d0fc181e74559dab, reversing changes made to c00b4fb1896d9b24eb82bd8fc986adb7c828c266. --- src/redux/preview.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/redux/preview.js b/src/redux/preview.js index 97a7ade52..4b8ca6d66 100644 --- a/src/redux/preview.js +++ b/src/redux/preview.js @@ -481,7 +481,7 @@ module.exports.getTopLevelComments = (id, offset, ownerUsername, isAdmin, token) } dispatch(module.exports.setFetchStatus('comments', module.exports.Status.FETCHED)); dispatch(module.exports.setComments(body)); - dispatch(module.exports.getReplies(id, body.map(comment => comment.id), 0, ownerUsername, isAdmin, token)); + dispatch(module.exports.getReplies(id, body.map(comment => comment.id), 0, isAdmin, token)); // If we loaded a full page of comments, assume there are more to load. // This will be wrong (1 / COMMENT_LIMIT) of the time, but does not require @@ -511,13 +511,13 @@ module.exports.getCommentById = (projectId, commentId, ownerUsername, isAdmin, t if (body.parent_id) { // If the comment is a reply, load the parent - return dispatch(module.exports.getCommentById(projectId, body.parent_id, ownerUsername, isAdmin, token)); + return dispatch(module.exports.getCommentById(projectId, body.parent_id, isAdmin, token)); } // If the comment is not a reply, show it as top level and load replies dispatch(module.exports.setFetchStatus('comments', module.exports.Status.FETCHED)); dispatch(module.exports.setComments([body])); - dispatch(module.exports.getReplies(projectId, [body.id], 0, ownerUsername, isAdmin, token)); + dispatch(module.exports.getReplies(projectId, [body.id], 0, isAdmin, token)); }); }); From 8d38d7d4e501d98fc6dfb07237e632810c497ed7 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Thu, 4 Apr 2019 15:04:36 -0400 Subject: [PATCH 2/3] Revert "Merge pull request #2859 from benjiwheeler/comments-for-project-endpoint" This reverts commit 07417846a97f531a3bff5325279e25658698bcdd, reversing changes made to 32484656ba7bdedbbacaa7d0e3f0ea999f224c31. --- src/redux/preview.js | 32 +++++++++++++++--------------- src/views/preview/project-view.jsx | 31 +++++++++++++++++------------ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/redux/preview.js b/src/redux/preview.js index 4b8ca6d66..4fbf21241 100644 --- a/src/redux/preview.js +++ b/src/redux/preview.js @@ -462,19 +462,19 @@ module.exports.getFavedStatus = (id, username, token) => (dispatch => { }); }); -module.exports.getTopLevelComments = (id, offset, ownerUsername, isAdmin, token) => (dispatch => { +module.exports.getTopLevelComments = (id, offset, isAdmin, token) => (dispatch => { dispatch(module.exports.setFetchStatus('comments', module.exports.Status.FETCHING)); api({ - uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${id}/comments`, - authentication: token ? token : null, + uri: `${isAdmin ? '/admin' : ''}/projects/${id}/comments`, + authentication: isAdmin ? token : null, params: {offset: offset || 0, limit: COMMENT_LIMIT} - }, (err, body, res) => { + }, (err, body) => { if (err) { dispatch(module.exports.setFetchStatus('comments', module.exports.Status.ERROR)); dispatch(module.exports.setError(err)); return; } - if (typeof body === 'undefined' || res.statusCode >= 400) { // NotFound + if (typeof body === 'undefined') { dispatch(module.exports.setFetchStatus('comments', module.exports.Status.ERROR)); dispatch(module.exports.setError('No comment info')); return; @@ -492,18 +492,18 @@ module.exports.getTopLevelComments = (id, offset, ownerUsername, isAdmin, token) }); }); -module.exports.getCommentById = (projectId, commentId, ownerUsername, isAdmin, token) => (dispatch => { +module.exports.getCommentById = (projectId, commentId, isAdmin, token) => (dispatch => { dispatch(module.exports.setFetchStatus('comments', module.exports.Status.FETCHING)); api({ - uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${projectId}/comments/${commentId}`, - authentication: token ? token : null - }, (err, body, res) => { + uri: `${isAdmin ? '/admin' : ''}/projects/${projectId}/comments/${commentId}`, + authentication: isAdmin ? token : null + }, (err, body) => { if (err) { dispatch(module.exports.setFetchStatus('comments', module.exports.Status.ERROR)); dispatch(module.exports.setError(err)); return; } - if (!body || res.statusCode >= 400) { // NotFound + if (!body) { dispatch(module.exports.setFetchStatus('comments', module.exports.Status.ERROR)); dispatch(module.exports.setError('No comment info')); return; @@ -521,19 +521,19 @@ module.exports.getCommentById = (projectId, commentId, ownerUsername, isAdmin, t }); }); -module.exports.getReplies = (projectId, commentIds, offset, ownerUsername, isAdmin, token) => (dispatch => { +module.exports.getReplies = (projectId, commentIds, offset, isAdmin, token) => (dispatch => { dispatch(module.exports.setFetchStatus('replies', module.exports.Status.FETCHING)); const fetchedReplies = {}; async.eachLimit(commentIds, 10, (parentId, callback) => { api({ - uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${projectId}/comments/${parentId}/replies`, - authentication: token ? token : null, + uri: `${isAdmin ? '/admin' : ''}/projects/${projectId}/comments/${parentId}/replies`, + authentication: isAdmin ? token : null, params: {offset: offset || 0, limit: COMMENT_LIMIT} - }, (err, body, res) => { + }, (err, body) => { if (err) { return callback(`Error fetching comment replies: ${err}`); } - if (typeof body === 'undefined' || res.statusCode >= 400) { // NotFound + if (typeof body === 'undefined') { return callback('No comment reply information'); } fetchedReplies[parentId] = body; @@ -767,7 +767,7 @@ module.exports.getProjectStudios = (id, ownerUsername, isAdmin, token) => (dispa dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.FETCHING)); api({ uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${id}/studios`, - authentication: token ? token : null + authentication: token }, (err, body, res) => { if (err) { dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.ERROR)); diff --git a/src/views/preview/project-view.jsx b/src/views/preview/project-view.jsx index 762d59915..28a941c06 100644 --- a/src/views/preview/project-view.jsx +++ b/src/views/preview/project-view.jsx @@ -171,13 +171,6 @@ class Preview extends React.Component { ) { this.props.getOriginalInfo(this.props.projectInfo.remix.root); } - if (this.state.singleCommentId) { - this.props.getCommentById(this.state.projectId, this.state.singleCommentId, - this.props.authorUsername, this.props.isAdmin, token); - } else { - this.props.getTopLevelComments(this.state.projectId, this.props.comments.length, - this.props.authorUsername, this.props.isAdmin, token); - } } } if (this.props.faved !== prevProps.faved || this.props.loved !== prevProps.loved) { @@ -216,12 +209,24 @@ class Preview extends React.Component { if (this.props.userPresent) { const username = this.props.user.username; const token = this.props.user.token; + if (this.state.singleCommentId) { + this.props.getCommentById(this.state.projectId, this.state.singleCommentId, + this.props.isAdmin, token); + } else { + this.props.getTopLevelComments(this.state.projectId, this.props.comments.length, + this.props.isAdmin, token); + } this.props.getProjectInfo(this.state.projectId, token); this.props.getRemixes(this.state.projectId, token); this.props.getCuratedStudios(username); this.props.getFavedStatus(this.state.projectId, username, token); this.props.getLovedStatus(this.state.projectId, username, token); } else { + if (this.state.singleCommentId) { + this.props.getCommentById(this.state.projectId, this.state.singleCommentId); + } else { + this.props.getTopLevelComments(this.state.projectId, this.props.comments.length); + } this.props.getProjectInfo(this.state.projectId); this.props.getRemixes(this.state.projectId); } @@ -989,14 +994,14 @@ const mapDispatchToProps = dispatch => ({ dispatch(previewActions.leaveStudio(studioId, id, token)); } }, - getTopLevelComments: (id, offset, ownerUsername, isAdmin, token) => { - dispatch(previewActions.getTopLevelComments(id, offset, ownerUsername, isAdmin, token)); + getTopLevelComments: (id, offset, isAdmin, token) => { + dispatch(previewActions.getTopLevelComments(id, offset, isAdmin, token)); }, - getCommentById: (projectId, commentId, ownerUsername, isAdmin, token) => { - dispatch(previewActions.getCommentById(projectId, commentId, ownerUsername, isAdmin, token)); + getCommentById: (projectId, commentId, isAdmin, token) => { + dispatch(previewActions.getCommentById(projectId, commentId, isAdmin, token)); }, - getMoreReplies: (projectId, commentId, offset, ownerUsername, isAdmin, token) => { - dispatch(previewActions.getReplies(projectId, [commentId], offset, ownerUsername, isAdmin, token)); + getMoreReplies: (projectId, commentId, offset, isAdmin, token) => { + dispatch(previewActions.getReplies(projectId, [commentId], offset, isAdmin, token)); }, getFavedStatus: (id, username, token) => { dispatch(previewActions.getFavedStatus(id, username, token)); From c3002be4a696b7179d4419286ab9e1ca2ca8f224 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Thu, 4 Apr 2019 15:04:46 -0400 Subject: [PATCH 3/3] Revert "Merge pull request #2858 from benjiwheeler/studios-for-project-endpoint" This reverts commit a3902acfd12ba285c7071339ec143f4ef8eee079, reversing changes made to 9e7a14cb768ef3bc74510b79022cced84961611a. --- src/redux/preview.js | 5 ++--- src/views/preview/project-view.jsx | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/redux/preview.js b/src/redux/preview.js index 4fbf21241..0a3eb2a5d 100644 --- a/src/redux/preview.js +++ b/src/redux/preview.js @@ -763,11 +763,10 @@ module.exports.getRemixes = id => (dispatch => { }); }); -module.exports.getProjectStudios = (id, ownerUsername, isAdmin, token) => (dispatch => { +module.exports.getProjectStudios = id => (dispatch => { dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.FETCHING)); api({ - uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${id}/studios`, - authentication: token + uri: `/projects/${id}/studios` }, (err, body, res) => { if (err) { dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.ERROR)); diff --git a/src/views/preview/project-view.jsx b/src/views/preview/project-view.jsx index 28a941c06..abcd8971e 100644 --- a/src/views/preview/project-view.jsx +++ b/src/views/preview/project-view.jsx @@ -159,10 +159,7 @@ class Preview extends React.Component { if (typeof this.props.projectInfo.id === 'undefined') { this.initCounts(0, 0); } else { - const token = this.props.user ? this.props.user.token : null; this.initCounts(this.props.projectInfo.stats.favorites, this.props.projectInfo.stats.loves); - this.props.getProjectStudios(this.props.projectInfo.id, - this.props.authorUsername, this.props.isAdmin, token); if (this.props.projectInfo.remix.parent !== null) { this.props.getParentInfo(this.props.projectInfo.remix.parent); } @@ -218,6 +215,7 @@ class Preview extends React.Component { } this.props.getProjectInfo(this.state.projectId, token); this.props.getRemixes(this.state.projectId, token); + this.props.getProjectStudios(this.state.projectId, token); this.props.getCuratedStudios(username); this.props.getFavedStatus(this.state.projectId, username, token); this.props.getLovedStatus(this.state.projectId, username, token); @@ -229,6 +227,7 @@ class Preview extends React.Component { } this.props.getProjectInfo(this.state.projectId); this.props.getRemixes(this.state.projectId); + this.props.getProjectStudios(this.state.projectId); } } setScreenFromOrientation () { @@ -981,8 +980,8 @@ const mapDispatchToProps = dispatch => ({ getRemixes: id => { dispatch(previewActions.getRemixes(id)); }, - getProjectStudios: (id, ownerUsername, isAdmin, token) => { - dispatch(previewActions.getProjectStudios(id, ownerUsername, isAdmin, token)); + getProjectStudios: id => { + dispatch(previewActions.getProjectStudios(id)); }, getCuratedStudios: (username, token) => { dispatch(previewActions.getCuratedStudios(username, token));