From a8c52bc3df3e491ed489e0e4c90900b9bd8284d8 Mon Sep 17 00:00:00 2001 From: Wadim Kalmykov Date: Mon, 12 Oct 2020 13:24:54 +0700 Subject: [PATCH 1/2] Fix loadRange doesn't return all posts --- framework/core/js/src/forum/states/PostStreamState.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/framework/core/js/src/forum/states/PostStreamState.js b/framework/core/js/src/forum/states/PostStreamState.js index add0cf5e5..a56132352 100644 --- a/framework/core/js/src/forum/states/PostStreamState.js +++ b/framework/core/js/src/forum/states/PostStreamState.js @@ -282,7 +282,13 @@ class PostStreamState { } }); - return loadIds.length ? app.store.find('posts', loadIds) : Promise.resolve(loaded); + if (loadIds.length) { + return app.store.find('posts', loadIds).then((newPosts) => { + return loaded.concat(newPosts).sort((a, b) => a.id() - b.id()); + }); + } + + return Promise.resolve(loaded); } /** From ae01ea679bc57ef59bab09980a833e1a4079adbd Mon Sep 17 00:00:00 2001 From: Wadim Kalmykov Date: Tue, 13 Oct 2020 21:33:50 +0700 Subject: [PATCH 2/2] order posts by creation date --- framework/core/js/src/forum/components/DiscussionPage.js | 2 +- framework/core/js/src/forum/states/PostStreamState.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/js/src/forum/components/DiscussionPage.js b/framework/core/js/src/forum/components/DiscussionPage.js index 6adb835ae..c5812bf39 100644 --- a/framework/core/js/src/forum/components/DiscussionPage.js +++ b/framework/core/js/src/forum/components/DiscussionPage.js @@ -155,7 +155,7 @@ export default class DiscussionPage extends Page { record.relationships.discussion.data.id === discussionId ) .map((record) => app.store.getById('posts', record.id)) - .sort((a, b) => a.id() - b.id()) + .sort((a, b) => a.createdAt() - b.createdAt()) .slice(0, 20); } diff --git a/framework/core/js/src/forum/states/PostStreamState.js b/framework/core/js/src/forum/states/PostStreamState.js index a56132352..d4d73b5fb 100644 --- a/framework/core/js/src/forum/states/PostStreamState.js +++ b/framework/core/js/src/forum/states/PostStreamState.js @@ -284,7 +284,7 @@ class PostStreamState { if (loadIds.length) { return app.store.find('posts', loadIds).then((newPosts) => { - return loaded.concat(newPosts).sort((a, b) => a.id() - b.id()); + return loaded.concat(newPosts).sort((a, b) => a.createdAt() - b.createdAt()); }); }