Fix Topic Top Articles
This commit is contained in:
parent
5e5693332c
commit
70bc237e2c
|
@ -31,8 +31,8 @@ export const Expo = (props: Props) => {
|
||||||
const [isLoaded, setIsLoaded] = createSignal<boolean>(Boolean(props.shouts))
|
const [isLoaded, setIsLoaded] = createSignal<boolean>(Boolean(props.shouts))
|
||||||
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
||||||
|
|
||||||
const [randomTopArticles, setRandomTopArticles] = createSignal<Shout[]>([])
|
const [favoriteTopArticles, setFavoriteTopArticles] = createSignal<Shout[]>([])
|
||||||
const [randomTopMonthArticles, setRandomTopMonthArticles] = createSignal<Shout[]>([])
|
const [reactedTopMonthArticles, setReactedTopMonthArticles] = createSignal<Shout[]>([])
|
||||||
|
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export const Expo = (props: Props) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => {
|
const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => {
|
||||||
const filters = { featured: true, ...additionalFilters }
|
const filters = { ...additionalFilters }
|
||||||
|
|
||||||
if (!filters.layouts) filters.layouts = []
|
if (!filters.layouts) filters.layouts = []
|
||||||
if (props.layout) {
|
if (props.layout) {
|
||||||
|
@ -77,12 +77,12 @@ export const Expo = (props: Props) => {
|
||||||
|
|
||||||
const loadRandomTopArticles = async () => {
|
const loadRandomTopArticles = async () => {
|
||||||
const options: LoadShoutsOptions = {
|
const options: LoadShoutsOptions = {
|
||||||
filters: getLoadShoutsFilters(),
|
filters: { ...getLoadShoutsFilters(), featured: true },
|
||||||
limit: 10,
|
limit: 10,
|
||||||
random_limit: 100,
|
random_limit: 100,
|
||||||
}
|
}
|
||||||
const result = await apiClient.getRandomTopShouts({ options })
|
const result = await apiClient.getRandomTopShouts({ options })
|
||||||
setRandomTopArticles(result)
|
setFavoriteTopArticles(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadRandomTopMonthArticles = async () => {
|
const loadRandomTopMonthArticles = async () => {
|
||||||
|
@ -90,19 +90,15 @@ export const Expo = (props: Props) => {
|
||||||
const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1)))
|
const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1)))
|
||||||
|
|
||||||
const options: LoadShoutsOptions = {
|
const options: LoadShoutsOptions = {
|
||||||
filters: getLoadShoutsFilters({ after }),
|
filters: { ...getLoadShoutsFilters({ after }), reacted: true },
|
||||||
limit: 10,
|
limit: 10,
|
||||||
random_limit: 10,
|
random_limit: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await apiClient.getRandomTopShouts({ options })
|
const result = await apiClient.getRandomTopShouts({ options })
|
||||||
setRandomTopMonthArticles(result)
|
setReactedTopMonthArticles(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const pages = createMemo<Shout[][]>(() =>
|
|
||||||
splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE),
|
|
||||||
)
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (isLoaded()) {
|
if (isLoaded()) {
|
||||||
return
|
return
|
||||||
|
@ -126,8 +122,8 @@ export const Expo = (props: Props) => {
|
||||||
() => props.layout,
|
() => props.layout,
|
||||||
() => {
|
() => {
|
||||||
resetSortedArticles()
|
resetSortedArticles()
|
||||||
setRandomTopArticles([])
|
setFavoriteTopArticles([])
|
||||||
setRandomTopMonthArticles([])
|
setReactedTopMonthArticles([])
|
||||||
loadMore(PRERENDERED_ARTICLES_COUNT + LOAD_MORE_PAGE_SIZE)
|
loadMore(PRERENDERED_ARTICLES_COUNT + LOAD_MORE_PAGE_SIZE)
|
||||||
loadRandomTopArticles()
|
loadRandomTopArticles()
|
||||||
loadRandomTopMonthArticles()
|
loadRandomTopMonthArticles()
|
||||||
|
@ -140,8 +136,9 @@ export const Expo = (props: Props) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleLoadMoreClick = () => {
|
const handleLoadMoreClick = () => {
|
||||||
loadMoreWithoutScrolling(LOAD_MORE_PAGE_SIZE)
|
loadMoreWithoutScrolling(LOAD_MORE_PAGE_SIZE);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={styles.Expo}>
|
<div class={styles.Expo}>
|
||||||
|
@ -210,8 +207,8 @@ export const Expo = (props: Props) => {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
<Show when={randomTopMonthArticles()?.length > 0} keyed={true}>
|
<Show when={reactedTopMonthArticles()?.length > 0} keyed={true}>
|
||||||
<ArticleCardSwiper title={t('Top month articles')} slides={randomTopMonthArticles()} />
|
<ArticleCardSwiper title={t('Top month articles')} slides={reactedTopMonthArticles()} />
|
||||||
</Show>
|
</Show>
|
||||||
<For each={sortedArticles().slice(LOAD_MORE_PAGE_SIZE, LOAD_MORE_PAGE_SIZE * 2)}>
|
<For each={sortedArticles().slice(LOAD_MORE_PAGE_SIZE, LOAD_MORE_PAGE_SIZE * 2)}>
|
||||||
{(shout) => (
|
{(shout) => (
|
||||||
|
@ -225,8 +222,8 @@ export const Expo = (props: Props) => {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
<Show when={randomTopArticles()?.length > 0} keyed={true}>
|
<Show when={favoriteTopArticles()?.length > 0} keyed={true}>
|
||||||
<ArticleCardSwiper title={t('Favorite')} slides={randomTopArticles()} />
|
<ArticleCardSwiper title={t('Favorite')} slides={favoriteTopArticles()} />
|
||||||
</Show>
|
</Show>
|
||||||
<For each={sortedArticles().slice(LOAD_MORE_PAGE_SIZE * 2)}>
|
<For each={sortedArticles().slice(LOAD_MORE_PAGE_SIZE * 2)}>
|
||||||
{(shout) => (
|
{(shout) => (
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import type { Shout, Topic } from '../../graphql/schema/core.gen'
|
import { LoadShoutsOptions, Shout, Topic } from "../../graphql/schema/core.gen";
|
||||||
|
|
||||||
import { Meta } from '@solidjs/meta'
|
import { Meta } from '@solidjs/meta'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { For, Show, createEffect, createMemo, createSignal, onMount } from 'solid-js'
|
import { For, Show, createEffect, createMemo, createSignal, onMount, on } from "solid-js";
|
||||||
|
|
||||||
import { useLocalize } from '../../context/localize'
|
import { useLocalize } from '../../context/localize'
|
||||||
import { useRouter } from '../../stores/router'
|
import { useRouter } from '../../stores/router'
|
||||||
|
@ -22,6 +22,8 @@ import { FullTopic } from '../Topic/Full'
|
||||||
import { ArticleCardSwiper } from '../_shared/SolidSwiper/ArticleCardSwiper'
|
import { ArticleCardSwiper } from '../_shared/SolidSwiper/ArticleCardSwiper'
|
||||||
|
|
||||||
import styles from '../../styles/Topic.module.scss'
|
import styles from '../../styles/Topic.module.scss'
|
||||||
|
import { apiClient } from "../../graphql/client/core";
|
||||||
|
import { getUnixtime } from "../../utils/getServerDate";
|
||||||
|
|
||||||
type TopicsPageSearchParams = {
|
type TopicsPageSearchParams = {
|
||||||
by: 'comments' | '' | 'recent' | 'viewed' | 'rating' | 'commented'
|
by: 'comments' | '' | 'recent' | 'viewed' | 'rating' | 'commented'
|
||||||
|
@ -43,14 +45,57 @@ export const TopicView = (props: Props) => {
|
||||||
const { sortedArticles } = useArticlesStore({ shouts: props.shouts })
|
const { sortedArticles } = useArticlesStore({ shouts: props.shouts })
|
||||||
const { topicEntities } = useTopicsStore({ topics: [props.topic] })
|
const { topicEntities } = useTopicsStore({ topics: [props.topic] })
|
||||||
const { authorsByTopic } = useAuthorsStore()
|
const { authorsByTopic } = useAuthorsStore()
|
||||||
|
const [favoriteTopArticles, setFavoriteTopArticles] = createSignal<Shout[]>([])
|
||||||
|
const [reactedTopMonthArticles, setReactedTopMonthArticles] = createSignal<Shout[]>([])
|
||||||
|
|
||||||
|
|
||||||
|
console.log('%c!!! :', 'color: #bada55', sortedArticles())
|
||||||
|
|
||||||
const [topic, setTopic] = createSignal<Topic>()
|
const [topic, setTopic] = createSignal<Topic>()
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const topics = topicEntities()
|
const topics = topicEntities()
|
||||||
if (props.topicSlug && !topic() && topics) {
|
if (props.topicSlug && !topic() && topics) {
|
||||||
setTopic(topics[props.topicSlug])
|
setTopic(topics[props.topicSlug])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const loadRandomTopArticles = async (topic: string) => {
|
||||||
|
const options: LoadShoutsOptions = {
|
||||||
|
filters: { featured: true, topic: topic},
|
||||||
|
limit: 10,
|
||||||
|
random_limit: 100,
|
||||||
|
}
|
||||||
|
const result = await apiClient.getRandomTopShouts({ options })
|
||||||
|
setFavoriteTopArticles(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadRandomTopMonthArticles = async (topic: string) => {
|
||||||
|
const now = new Date()
|
||||||
|
const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1)))
|
||||||
|
|
||||||
|
const options: LoadShoutsOptions = {
|
||||||
|
filters: { after: after, featured: true, topic: topic },
|
||||||
|
limit: 10,
|
||||||
|
random_limit: 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await apiClient.getRandomTopShouts({ options })
|
||||||
|
setReactedTopMonthArticles(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
createEffect(
|
||||||
|
on(
|
||||||
|
() => topic(),
|
||||||
|
() => {
|
||||||
|
loadRandomTopArticles(topic()?.slug)
|
||||||
|
loadRandomTopMonthArticles(topic()?.slug)
|
||||||
|
},
|
||||||
|
{ defer: true },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
const title = createMemo(
|
const title = createMemo(
|
||||||
() =>
|
() =>
|
||||||
`#${capitalize(
|
`#${capitalize(
|
||||||
|
@ -170,8 +215,9 @@ export const TopicView = (props: Props) => {
|
||||||
beside={sortedArticles()[4]}
|
beside={sortedArticles()[4]}
|
||||||
wrapper={'author'}
|
wrapper={'author'}
|
||||||
/>
|
/>
|
||||||
|
<Show when={reactedTopMonthArticles()?.length > 0} keyed={true}>
|
||||||
<ArticleCardSwiper title={title()} slides={sortedArticles().slice(5, 11)} />
|
<ArticleCardSwiper title={t('Top month articles')} slides={reactedTopMonthArticles()} />
|
||||||
|
</Show>
|
||||||
<Beside
|
<Beside
|
||||||
beside={sortedArticles()[12]}
|
beside={sortedArticles()[12]}
|
||||||
title={t('Top viewed')}
|
title={t('Top viewed')}
|
||||||
|
@ -182,8 +228,10 @@ export const TopicView = (props: Props) => {
|
||||||
<Row2 articles={sortedArticles().slice(13, 15)} isEqual={true} />
|
<Row2 articles={sortedArticles().slice(13, 15)} isEqual={true} />
|
||||||
<Row1 article={sortedArticles()[15]} />
|
<Row1 article={sortedArticles()[15]} />
|
||||||
|
|
||||||
|
<Show when={favoriteTopArticles()?.length > 0} keyed={true}>
|
||||||
|
<ArticleCardSwiper title={t('Favorite')} slides={favoriteTopArticles()} />
|
||||||
|
</Show>
|
||||||
<Show when={sortedArticles().length > 15}>
|
<Show when={sortedArticles().length > 15}>
|
||||||
<ArticleCardSwiper title={t('Favorite')} slides={sortedArticles().slice(16, 22)} />
|
|
||||||
<Row3 articles={sortedArticles().slice(23, 26)} />
|
<Row3 articles={sortedArticles().slice(23, 26)} />
|
||||||
<Row2 articles={sortedArticles().slice(26, 28)} />
|
<Row2 articles={sortedArticles().slice(26, 28)} />
|
||||||
</Show>
|
</Show>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user