load Random Topics on Mount
This commit is contained in:
parent
e93cb76a78
commit
d55be2505d
|
@ -59,7 +59,7 @@ export const TopicView = (props: Props) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const loadRandomTopArticles = async (topic: string) => {
|
const loadFavoriteTopArticles = async (topic: string) => {
|
||||||
const options: LoadShoutsOptions = {
|
const options: LoadShoutsOptions = {
|
||||||
filters: { featured: true, topic: topic },
|
filters: { featured: true, topic: topic },
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
@ -69,7 +69,7 @@ export const TopicView = (props: Props) => {
|
||||||
setFavoriteTopArticles(result)
|
setFavoriteTopArticles(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadRandomTopMonthArticles = async (topic: string) => {
|
const loadReactedTopMonthArticles = async (topic: string) => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1)))
|
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 })
|
const result = await apiClient.getRandomTopShouts({ options })
|
||||||
|
|
||||||
setReactedTopMonthArticles(result)
|
setReactedTopMonthArticles(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const loadRandom = () => {
|
||||||
|
console.log("!!! loadRandom:");
|
||||||
|
loadFavoriteTopArticles(topic()?.slug)
|
||||||
|
loadReactedTopMonthArticles(topic()?.slug)
|
||||||
|
}
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
on(
|
on(
|
||||||
() => topic(),
|
() => topic(),
|
||||||
() => {
|
() => loadRandom(),
|
||||||
loadRandomTopArticles(topic()?.slug)
|
|
||||||
loadRandomTopMonthArticles(topic()?.slug)
|
|
||||||
},
|
|
||||||
{ defer: true },
|
{ defer: true },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -118,6 +123,7 @@ export const TopicView = (props: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
loadRandom()
|
||||||
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
|
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
|
||||||
loadMore()
|
loadMore()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user