Commit b0ac4018 authored by Paul Kaplan's avatar Paul Kaplan

Use admin routes to include all comments when loading page

parent b7b7b079
......@@ -337,10 +337,11 @@ module.exports.getFavedStatus = (id, username, token) => (dispatch => {
});
});
module.exports.getTopLevelComments = (id, offset) => (dispatch => {
module.exports.getTopLevelComments = (id, offset, isAdmin, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('comments', module.exports.Status.FETCHING));
api({
uri: `/comments/project/${id}`,
uri: `${isAdmin ? '/admin' : ''}/comments/project/${id}`,
authentication: isAdmin ? token : null,
params: {offset: offset || 0}
}, (err, body) => {
if (err) {
......@@ -355,16 +356,17 @@ module.exports.getTopLevelComments = (id, offset) => (dispatch => {
}
dispatch(module.exports.setFetchStatus('comments', module.exports.Status.FETCHED));
dispatch(module.exports.setComments(body));
dispatch(module.exports.getReplies(id, body.map(comment => comment.id)));
dispatch(module.exports.getReplies(id, body.map(comment => comment.id), isAdmin, token));
});
});
module.exports.getReplies = (projectId, commentIds) => (dispatch => {
module.exports.getReplies = (projectId, commentIds, isAdmin, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('replies', module.exports.Status.FETCHING));
const fetchedReplies = {};
async.eachLimit(commentIds, 10, (parentId, callback) => {
api({
uri: `/comments/project/${projectId}/${parentId}`
uri: `${isAdmin ? '/admin' : ''}/comments/project/${projectId}/${parentId}`,
authentication: isAdmin ? token : null
}, (err, body) => {
if (err) {
return callback(`Error fetching comment replies: ${err}`);
......
......@@ -81,7 +81,8 @@ class Preview extends React.Component {
if (this.props.user) {
const username = this.props.user.username;
const token = this.props.user.token;
this.props.getTopLevelComments(this.state.projectId, this.props.comments.length);
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.getProjectStudios(this.state.projectId, token);
......@@ -269,7 +270,8 @@ class Preview extends React.Component {
}
}
handleLoadMore () {
this.props.getTopLevelComments(this.state.projectId, this.props.comments.length);
this.props.getTopLevelComments(this.state.projectId, this.props.comments.length,
this.props.isAdmin, this.props.user && this.props.user.token);
}
handleLoveToggle () {
this.props.setLovedStatus(
......@@ -447,6 +449,7 @@ Preview.propTypes = {
handleOpenRegistration: PropTypes.func,
handleReportComment: PropTypes.func,
handleToggleLoginOpen: PropTypes.func,
isAdmin: PropTypes.bool,
isEditable: PropTypes.bool,
isLoggedIn: PropTypes.bool,
isShared: PropTypes.bool,
......@@ -532,6 +535,7 @@ const mapStateToProps = state => {
Object.keys(state.session.session.user).length > 0;
const isLoggedIn = state.session.status === sessionActions.Status.FETCHED &&
userPresent;
const isAdmin = isLoggedIn && state.session.session.permissions.admin;
const authorPresent = projectInfoPresent && state.preview.projectInfo.author &&
Object.keys(state.preview.projectInfo.author).length > 0;
const userOwnsProject = isLoggedIn && authorPresent &&
......@@ -554,6 +558,7 @@ const mapStateToProps = state => {
((authorPresent && state.preview.projectInfo.author.username === state.session.session.user.username) ||
state.permissions.admin === true),
isLoggedIn: isLoggedIn,
isAdmin: isAdmin,
// if we don't have projectInfo, assume it's shared until we know otherwise
isShared: !projectInfoPresent || state.preview.projectInfo.is_published,
loved: state.preview.loved,
......@@ -623,8 +628,8 @@ const mapDispatchToProps = dispatch => ({
dispatch(previewActions.leaveStudio(studioId, id, token));
}
},
getTopLevelComments: (id, offset) => {
dispatch(previewActions.getTopLevelComments(id, offset));
getTopLevelComments: (id, offset, isAdmin, token) => {
dispatch(previewActions.getTopLevelComments(id, offset, isAdmin, token));
},
getFavedStatus: (id, username, token) => {
dispatch(previewActions.getFavedStatus(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