mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
Fixed comments order
This commit is contained in:
parent
771fd15f27
commit
fdeed0eeec
@ -5,8 +5,9 @@ async function loadMoreComments({state, api}) {
|
||||
}
|
||||
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 {
|
||||
comments: [...data.comments, ...state.comments],
|
||||
comments: [...state.comments, ...data.comments],
|
||||
pagination: data.meta.pagination
|
||||
};
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class CommentsBox extends React.Component {
|
||||
}
|
||||
|
||||
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' : '';
|
||||
|
||||
|
@ -78,8 +78,9 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
|
||||
api.comments = {
|
||||
browse({page, 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({
|
||||
url,
|
||||
method: 'GET',
|
||||
@ -89,7 +90,7 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
|
||||
credentials: 'same-origin'
|
||||
}).then(function (res) {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
return res.json()
|
||||
} else {
|
||||
throw new Error('Failed to fetch comments');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user