From c1356d77aa3226a58c9c3946753c31d92aa30a7d Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Mon, 18 Dec 2023 14:22:20 +0100 Subject: [PATCH] expo top fix, feed right column loading state (#339) Co-authored-by: Igor Lobanov --- src/components/Views/Expo/Expo.tsx | 6 +- src/components/Views/Feed/Feed.tsx | 144 +++++++++++++++-------------- 2 files changed, 78 insertions(+), 72 deletions(-) diff --git a/src/components/Views/Expo/Expo.tsx b/src/components/Views/Expo/Expo.tsx index 1d347b82..76a06530 100644 --- a/src/components/Views/Expo/Expo.tsx +++ b/src/components/Views/Expo/Expo.tsx @@ -45,8 +45,8 @@ export const Expo = (props: Props) => { shouts: isLoaded() ? props.shouts : [], }) - const getLoadShoutsFilters = (filters: LoadShoutsFilters = {}): LoadShoutsFilters => { - const result = { ...filters } + const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => { + const filters = { ...additionalFilters } if (props.layout) { filters.layout = props.layout @@ -54,7 +54,7 @@ export const Expo = (props: Props) => { filters.excludeLayout = 'article' } - return result + return filters } const loadMore = async (count: number) => { diff --git a/src/components/Views/Feed/Feed.tsx b/src/components/Views/Feed/Feed.tsx index a2253965..3ac8822e 100644 --- a/src/components/Views/Feed/Feed.tsx +++ b/src/components/Views/Feed/Feed.tsx @@ -55,8 +55,8 @@ export const Feed = (props: Props) => { const { t } = useLocalize() const { page, searchParams } = useRouter() const [isLoading, setIsLoading] = createSignal(false) + const [isRightColumnLoaded, setIsRightColumnLoaded] = createSignal(false) - // state const { sortedArticles } = useArticlesStore() const { topTopics } = useTopicsStore() const { topAuthors } = useTopAuthorsStore() @@ -73,9 +73,15 @@ export const Feed = (props: Props) => { setUnratedArticles(result) } + const loadTopComments = async () => { + const comments = await loadReactionsBy({ by: { comment: true }, limit: 5 }) + setTopComments(comments) + } + onMount(() => { loadMore() - loadUnratedArticles() + // eslint-disable-next-line promise/catch-or-return + Promise.all([loadUnratedArticles(), loadTopComments()]).finally(() => setIsRightColumnLoaded(true)) }) createEffect( @@ -118,12 +124,6 @@ export const Feed = (props: Props) => { setIsLoadMoreButtonVisible(hasMore) } - onMount(async () => { - // load 5 recent comments overall - const comments = await loadReactionsBy({ by: { comment: true }, limit: 5 }) - setTopComments(comments) - }) - const ogImage = getImageUrl('production/image/logo_image.png') const description = t( 'Independent media project about culture, science, art and society with horizontal editing', @@ -221,70 +221,76 @@ export const Feed = (props: Props) => {