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:
parent
771fd15f27
commit
fdeed0eeec
3 changed files with 6 additions and 4 deletions
|
@ -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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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' : '';
|
||||||
|
|
||||||
|
|
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue