From 589c862c3e8a7e461089ca02666071d022d388f6 Mon Sep 17 00:00:00 2001 From: Dima Alipov Date: Thu, 28 Nov 2024 16:41:09 +0200 Subject: [PATCH] fix: clicking on back button after post creation --- src/discussions/posts/data/hooks.js | 10 ++++++---- src/discussions/posts/data/slices.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/discussions/posts/data/hooks.js b/src/discussions/posts/data/hooks.js index ef434baa2..47d47425f 100644 --- a/src/discussions/posts/data/hooks.js +++ b/src/discussions/posts/data/hooks.js @@ -11,10 +11,12 @@ const usePostList = (ids) => { const sortedIds = useMemo(() => { posts.forEach((post) => { - if (post.pinned) { - pinnedPostsIds.push(post.id); - } else { - unpinnedPostsIds.push(post.id); + if (post) { + if (post.pinned) { + pinnedPostsIds.push(post.id); + } else { + unpinnedPostsIds.push(post.id); + } } }); diff --git a/src/discussions/posts/data/slices.js b/src/discussions/posts/data/slices.js index ee97cd601..d63e8b6d2 100644 --- a/src/discussions/posts/data/slices.js +++ b/src/discussions/posts/data/slices.js @@ -92,7 +92,7 @@ const threadsSlice = createSlice({ if (!updatedPages[page - 1]) { updatedPages[page - 1] = ids; } else { - updatedPages[page - 1] = [...new Set([...updatedPages[page - 1], ...ids])]; + updatedPages[page - 1] = [...new Set([updatedPages[page - 1], ...ids])]; } newState.pages = updatedPages;