From d55be2505d3a958ccae33b5651ab022a1764f575 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Tue, 2 Apr 2024 14:27:56 +0300 Subject: [PATCH] load Random Topics on Mount --- src/components/Views/Topic.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/Views/Topic.tsx b/src/components/Views/Topic.tsx index e3a512e1..520f8ba8 100644 --- a/src/components/Views/Topic.tsx +++ b/src/components/Views/Topic.tsx @@ -59,7 +59,7 @@ export const TopicView = (props: Props) => { } }) - const loadRandomTopArticles = async (topic: string) => { + const loadFavoriteTopArticles = async (topic: string) => { const options: LoadShoutsOptions = { filters: { featured: true, topic: topic }, limit: 10, @@ -69,7 +69,7 @@ export const TopicView = (props: Props) => { setFavoriteTopArticles(result) } - const loadRandomTopMonthArticles = async (topic: string) => { + const loadReactedTopMonthArticles = async (topic: string) => { const now = new Date() const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1))) @@ -80,16 +80,21 @@ export const TopicView = (props: Props) => { } const result = await apiClient.getRandomTopShouts({ options }) + setReactedTopMonthArticles(result) } + + const loadRandom = () => { + console.log("!!! loadRandom:"); + loadFavoriteTopArticles(topic()?.slug) + loadReactedTopMonthArticles(topic()?.slug) + } + createEffect( on( () => topic(), - () => { - loadRandomTopArticles(topic()?.slug) - loadRandomTopMonthArticles(topic()?.slug) - }, + () => loadRandom(), { defer: true }, ), ) @@ -118,6 +123,7 @@ export const TopicView = (props: Props) => { } onMount(() => { + loadRandom() if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) { loadMore() }