0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed comments order

This commit is contained in:
Simon Backx 2022-07-05 16:08:08 +02:00
parent 771fd15f27
commit fdeed0eeec
3 changed files with 6 additions and 4 deletions

View file

@ -5,8 +5,9 @@ async function loadMoreComments({state, api}) {
} }
const data = await api.comments.browse({page, postId: state.postId}); const data = await api.comments.browse({page, postId: state.postId});
// Note: we store the comments from new to old, and show them in reverse order
return { return {
comments: [...data.comments, ...state.comments], comments: [...state.comments, ...data.comments],
pagination: data.meta.pagination pagination: data.meta.pagination
}; };
} }

View file

@ -41,7 +41,7 @@ class CommentsBox extends React.Component {
} }
render() { render() {
const comments = !this.context.comments ? 'Loading...' : this.context.comments.map(comment => <Comment comment={comment} key={comment.id} />); const comments = !this.context.comments ? 'Loading...' : this.context.comments.slice().reverse().map(comment => <Comment comment={comment} key={comment.id} />);
const containerClass = this.darkMode() ? 'dark' : ''; const containerClass = this.darkMode() ? 'dark' : '';

View file

@ -78,8 +78,9 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
api.comments = { api.comments = {
browse({page, postId}) { browse({page, postId}) {
const filter = encodeURIComponent('post_id:' + postId); const filter = encodeURIComponent('post_id:' + postId);
const order = encodeURIComponent('created_at DESC');
const url = endpointFor({type: 'members', resource: 'comments', params: `?limit=15&include=member&filter=${filter}&page=${page}`}); const url = endpointFor({type: 'members', resource: 'comments', params: `?limit=5&include=member&order=${order}&filter=${filter}&page=${page}`});
return makeRequest({ return makeRequest({
url, url,
method: 'GET', method: 'GET',
@ -89,7 +90,7 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
credentials: 'same-origin' credentials: 'same-origin'
}).then(function (res) { }).then(function (res) {
if (res.ok) { if (res.ok) {
return res.json(); return res.json()
} else { } else {
throw new Error('Failed to fetch comments'); throw new Error('Failed to fetch comments');
} }