import { A } from '@solidjs/router' import { clsx } from 'clsx' import { For, Show, createEffect, createMemo, createSignal, on, onCleanup, onMount } from 'solid-js' import { ConditionalWrapper } from '~/components/_shared/ConditionalWrapper' import { LoadMoreItems, LoadMoreWrapper } from '~/components/_shared/LoadMoreWrapper' import { Loading } from '~/components/_shared/Loading' import { ArticleCardSwiper } from '~/components/_shared/SolidSwiper/ArticleCardSwiper' import { coreApiUrl } from '~/config' import { EXPO_LAYOUTS, SHOUTS_PER_PAGE, useFeed } from '~/context/feed' import { useLocalize } from '~/context/localize' import { useSession } from '~/context/session' import { loadShouts } from '~/graphql/api/public' import { graphqlClientCreate } from '~/graphql/client' import getRandomTopShoutsQuery from '~/graphql/query/core/articles-load-random-top' import { LoadShoutsFilters, LoadShoutsOptions, Shout } from '~/graphql/schema/core.gen' import { LayoutType } from '~/types/common' import { getUnixtime } from '~/utils/date' import { ArticleCard } from '../../Feed/ArticleCard' import styles from './Expo.module.scss' type Props = { shouts: Shout[] topMonthShouts?: Shout[] topRatedShouts?: Shout[] layout?: LayoutType } export const PRERENDERED_ARTICLES_COUNT = 36 const LOAD_MORE_PAGE_SIZE = 12 export const Expo = (props: Props) => { const { t } = useLocalize() const { session } = useSession() const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token)) const [favoriteTopArticles, setFavoriteTopArticles] = createSignal([]) const [reactedTopMonthArticles, setReactedTopMonthArticles] = createSignal([]) const [expoShouts, setExpoShouts] = createSignal([]) const { feedByLayout, expoFeed, setExpoFeed } = useFeed() const layouts = createMemo(() => (props.layout ? [props.layout] : EXPO_LAYOUTS)) const loadMoreFiltered = async () => { const limit = SHOUTS_PER_PAGE const offset = (props.layout ? feedByLayout()[props.layout] : expoFeed())?.length const filters: LoadShoutsFilters = { layouts: layouts(), featured: true } const options: LoadShoutsOptions = { filters, limit, offset } const shoutsFetcher = loadShouts(options) const result = await shoutsFetcher() result && setExpoFeed(result) return result as LoadMoreItems } const loadRandomTopArticles = async () => { const options: LoadShoutsOptions = { filters: { layouts: layouts(), featured: true }, limit: 10, random_limit: 100 } const resp = await client()?.query(getRandomTopShoutsQuery, { options }).toPromise() setFavoriteTopArticles(resp?.data?.load_shouts_random_top || []) } const loadRandomTopMonthArticles = async () => { const now = new Date() const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1))) const options: LoadShoutsOptions = { filters: { layouts: layouts(), after, reacted: true }, limit: 10, random_limit: 10 } const resp = await client()?.query(getRandomTopShoutsQuery, { options }).toPromise() setReactedTopMonthArticles(resp?.data?.load_shouts_random_top || []) } onMount(() => { loadRandomTopArticles() loadRandomTopMonthArticles() }) createEffect( on( () => props.layout, () => { setExpoShouts([]) setFavoriteTopArticles([]) setReactedTopMonthArticles([]) loadRandomTopArticles() loadRandomTopMonthArticles() } ) ) onCleanup(() => { setExpoShouts([]) }) const ExpoTabs = () => (
) const ExpoGrid = () => (
{(shout) => (
)}
0} keyed={true}> {(shout) => (
)}
0} keyed={true}> {(shout) => (
)}
) return (
0} fallback={}>
) }