0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed pagination after new comments are added

This commit is contained in:
Simon Backx 2022-07-05 16:24:30 +02:00
parent 5841241a42
commit 0390995d76

View file

@ -75,9 +75,14 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
};
// To fix pagination when we create new comments (or people post comments after you loaded the page, we need to only load comments creatd AFTER the page load)
let firstCommentsLoadedAt = null;
api.comments = {
browse({page, postId}) {
const filter = encodeURIComponent('post_id:' + postId);
firstCommentsLoadedAt = firstCommentsLoadedAt ?? new Date().toISOString();
const filter = encodeURIComponent(`post_id:${postId}+created_at:<=${firstCommentsLoadedAt}`);
const order = encodeURIComponent('created_at DESC');
const url = endpointFor({type: 'members', resource: 'comments', params: `?limit=5&include=member&order=${order}&filter=${filter}&page=${page}`});