From fa21cdb9f62959291b1b134050d238f094f4e4d2 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Sun, 5 Jan 2025 10:16:52 +0100 Subject: [PATCH] fix: discussion posts not always properly loaded --- .../src/forum/components/DiscussionPage.tsx | 31 ++----------------- .../core/src/Api/Resource/PostResource.php | 3 +- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/framework/core/js/src/forum/components/DiscussionPage.tsx b/framework/core/js/src/forum/components/DiscussionPage.tsx index 343f56e7bd..15d687fabf 100644 --- a/framework/core/js/src/forum/components/DiscussionPage.tsx +++ b/framework/core/js/src/forum/components/DiscussionPage.tsx @@ -165,40 +165,13 @@ export default class DiscussionPage - record.type === 'posts' && - record.relationships && - record.relationships.discussion && - !Array.isArray(record.relationships.discussion.data) && - record.relationships.discussion.data.id === discussionId - ) - // We can make this assertion because posts should be in the store, - // since they were in the discussion's payload. - .map((record) => app.store.getById('posts', record.id) as Post) - .sort((a: Post, b: Post) => a.number() - b.number()) - .slice(0, 20); - } - // Set up the post stream for this discussion, along with the first page of // posts we want to display. Tell the stream to scroll down and highlight // the specific post that was routed to. - this.stream = new PostStreamState(discussion, includedPosts); + this.stream = new PostStreamState(discussion); const rawNearParam = m.route.param('near'); const nearParam = rawNearParam === 'reply' ? 'reply' : parseInt(rawNearParam); - this.stream.goToNumber(nearParam || (includedPosts[0]?.number() ?? 0), true).then(() => { + this.stream.goToNumber(nearParam || 0, true).then(() => { this.discussion = discussion; app.current.set('discussion', discussion); diff --git a/framework/core/src/Api/Resource/PostResource.php b/framework/core/src/Api/Resource/PostResource.php index 824162b070..382bac8e45 100644 --- a/framework/core/src/Api/Resource/PostResource.php +++ b/framework/core/src/Api/Resource/PostResource.php @@ -123,8 +123,9 @@ public function endpoints(): array Endpoint\Index::make() ->extractOffset(function (Context $context, array $defaultExtracts): int { $queryParams = $context->request->getQueryParams(); + $near = intval(Arr::get($queryParams, 'page.near')); - if (($near = Arr::get($queryParams, 'page.near')) > 1) { + if ($near > 1) { $sort = $defaultExtracts['sort']; $filter = $defaultExtracts['filter'];