diff --git a/src/components/Views/AuthorView.tsx b/src/components/Views/AuthorView.tsx index b6c15041..7d09381a 100644 --- a/src/components/Views/AuthorView.tsx +++ b/src/components/Views/AuthorView.tsx @@ -147,17 +147,31 @@ export const AuthorView = (props: AuthorViewProps) => { const [loadMoreHidden, setLoadMoreHidden] = createSignal(false) const loadMore = async () => { saveScrollPosition() - const authorhoutsFetcher = loadShouts({ + const authorShoutsFetcher = loadShouts({ filters: { author: props.authorSlug }, limit: SHOUTS_PER_PAGE, offset: feedByAuthor()?.[props.authorSlug]?.length || 0 }) - const result = await authorhoutsFetcher() - result && addFeed(result) + const result = await authorShoutsFetcher() + if (result) { + addFeed(result) + } restoreScrollPosition() return result as LoadMoreItems } + // Function to chunk the sortedFeed into arrays of 3 shouts each + const chunkArray = (array: Shout[], chunkSize: number): Shout[][] => { + const chunks: Shout[][] = [] + for (let i = 0; i < array.length; i += chunkSize) { + chunks.push(array.slice(i, i + chunkSize)) + } + return chunks + } + + // Memoize the chunked feed + const feedChunks = createMemo(() => chunkArray(sortedFeed(), 3)) + // fx to update author's feed createEffect( on( @@ -188,29 +202,48 @@ export const AuthorView = (props: AuthorViewProps) => { offset: commentsByAuthor()[aid]?.length || 0 }) const result = await authorCommentsFetcher() - result && addShoutReactions(result) + if (result) { + addShoutReactions(result) + } restoreScrollPosition() return result as LoadMoreItems } createEffect(() => setCurrentTab(params.tab)) + // Update commented when author or commentsByAuthor changes createEffect( - on([author, commentsByAuthor], ([a, ccc]) => a && ccc && ccc[a.id] && setCommented(ccc[a.id]), {}) + on( + [author, commentsByAuthor], + ([a, ccc]) => { + if (a && ccc && ccc[a.id]) { + setCommented(ccc[a.id]) + } + }, + {} + ) ) createEffect( on( [author, commented], - ([a, ccc]) => a && ccc && setLoadMoreCommentsHidden((ccc || []).length === a.stat?.comments) + ([a, ccc]) => { + if (a && ccc) { + setLoadMoreCommentsHidden((ccc || []).length === a.stat?.comments) + } + }, + {} ) ) createEffect( on( [author, feedByAuthor], - ([a, feed]) => - a && feed[props.authorSlug] && setLoadMoreHidden(feed[props.authorSlug]?.length === a.stat?.shouts), + ([a, feed]) => { + if (a && feed[props.authorSlug]) { + setLoadMoreHidden(feed[props.authorSlug]?.length === a.stat?.shouts) + } + }, {} ) ) @@ -230,7 +263,7 @@ export const AuthorView = (props: AuthorViewProps) => {