2023-11-14 15:10:00 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-04-25 13:55:34 +00:00
|
|
|
import { For, Show, createEffect, createSignal, on, onCleanup, onMount } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
import { A } from '@solidjs/router'
|
|
|
|
import { useGraphQL } from '~/context/graphql'
|
|
|
|
import getShoutsQuery from '~/graphql/query/core/articles-load-by'
|
|
|
|
import getRandomTopShoutsQuery from '~/graphql/query/core/articles-load-random-top'
|
2023-10-10 15:38:02 +00:00
|
|
|
import { useLocalize } from '../../../context/localize'
|
2023-12-18 01:15:49 +00:00
|
|
|
import { LoadShoutsFilters, LoadShoutsOptions, Shout } from '../../../graphql/schema/core.gen'
|
|
|
|
import { getUnixtime } from '../../../utils/getServerDate'
|
2023-10-10 15:38:02 +00:00
|
|
|
import { restoreScrollPosition, saveScrollPosition } from '../../../utils/scroll'
|
2024-02-04 11:25:21 +00:00
|
|
|
import { ArticleCard } from '../../Feed/ArticleCard'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { Button } from '../../_shared/Button'
|
2023-10-10 15:38:02 +00:00
|
|
|
import { ConditionalWrapper } from '../../_shared/ConditionalWrapper'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { Loading } from '../../_shared/Loading'
|
2023-12-13 22:57:33 +00:00
|
|
|
import { ArticleCardSwiper } from '../../_shared/SolidSwiper/ArticleCardSwiper'
|
2023-11-14 15:10:00 +00:00
|
|
|
import styles from './Expo.module.scss'
|
2023-10-10 15:38:02 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
export type LayoutType = 'music' | 'literature' | 'video' | 'article' | 'image'
|
|
|
|
|
2023-10-10 15:38:02 +00:00
|
|
|
type Props = {
|
|
|
|
shouts: Shout[]
|
2023-12-13 22:57:33 +00:00
|
|
|
layout: LayoutType
|
2023-10-10 15:38:02 +00:00
|
|
|
}
|
2023-12-13 22:57:33 +00:00
|
|
|
|
2024-03-27 00:54:15 +00:00
|
|
|
export const PRERENDERED_ARTICLES_COUNT = 36
|
|
|
|
const LOAD_MORE_PAGE_SIZE = 12
|
2023-12-13 22:57:33 +00:00
|
|
|
|
2023-10-10 15:38:02 +00:00
|
|
|
export const Expo = (props: Props) => {
|
2024-04-25 13:55:34 +00:00
|
|
|
const { t } = useLocalize()
|
2024-06-24 17:50:27 +00:00
|
|
|
const { query } = useGraphQL()
|
2023-10-10 15:38:02 +00:00
|
|
|
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
2024-03-29 17:25:07 +00:00
|
|
|
const [favoriteTopArticles, setFavoriteTopArticles] = createSignal<Shout[]>([])
|
|
|
|
const [reactedTopMonthArticles, setReactedTopMonthArticles] = createSignal<Shout[]>([])
|
2024-04-25 13:55:34 +00:00
|
|
|
const [articlesEndPage, setArticlesEndPage] = createSignal<number>(PRERENDERED_ARTICLES_COUNT)
|
|
|
|
const [expoShouts, setExpoShouts] = createSignal<Shout[]>([])
|
2023-12-18 13:22:20 +00:00
|
|
|
const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => {
|
2024-03-29 17:25:07 +00:00
|
|
|
const filters = { ...additionalFilters }
|
2023-12-14 18:45:50 +00:00
|
|
|
|
2024-01-21 09:25:38 +00:00
|
|
|
if (!filters.layouts) filters.layouts = []
|
2023-12-14 18:45:50 +00:00
|
|
|
if (props.layout) {
|
2023-12-18 01:15:49 +00:00
|
|
|
filters.layouts.push(props.layout)
|
2023-12-14 18:45:50 +00:00
|
|
|
} else {
|
2024-03-29 09:30:38 +00:00
|
|
|
filters.layouts.push('audio', 'video', 'image', 'literature')
|
2023-12-14 18:45:50 +00:00
|
|
|
}
|
|
|
|
|
2023-12-18 13:22:20 +00:00
|
|
|
return filters
|
2023-12-14 18:45:50 +00:00
|
|
|
}
|
|
|
|
|
2023-12-13 22:57:33 +00:00
|
|
|
const loadMore = async (count: number) => {
|
2023-10-10 15:38:02 +00:00
|
|
|
const options: LoadShoutsOptions = {
|
2023-12-14 18:45:50 +00:00
|
|
|
filters: getLoadShoutsFilters(),
|
2023-10-10 15:38:02 +00:00
|
|
|
limit: count,
|
2024-06-26 08:22:05 +00:00
|
|
|
offset: expoShouts().length
|
2023-10-10 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2023-12-18 01:15:49 +00:00
|
|
|
options.filters = props.layout
|
|
|
|
? { layouts: [props.layout] }
|
2023-11-28 13:18:25 +00:00
|
|
|
: { layouts: ['audio', 'video', 'image', 'literature'] }
|
2023-10-10 15:38:02 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
const resp = await query(getShoutsQuery, options).toPromise()
|
|
|
|
const result = resp?.data?.load_shouts || []
|
|
|
|
const hasMore = result.length !== options.limit + 1 && result.length !== 0
|
2023-10-10 15:38:02 +00:00
|
|
|
setIsLoadMoreButtonVisible(hasMore)
|
2024-04-25 13:55:34 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
setExpoShouts((prev) => [...prev, ...result])
|
2023-12-16 14:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const loadMoreWithoutScrolling = async (count: number) => {
|
|
|
|
saveScrollPosition()
|
|
|
|
await loadMore(count)
|
2023-10-10 15:38:02 +00:00
|
|
|
restoreScrollPosition()
|
|
|
|
}
|
|
|
|
|
2023-12-13 22:57:33 +00:00
|
|
|
const loadRandomTopArticles = async () => {
|
2023-12-18 01:15:49 +00:00
|
|
|
const options: LoadShoutsOptions = {
|
2024-03-29 17:25:07 +00:00
|
|
|
filters: { ...getLoadShoutsFilters(), featured: true },
|
2023-12-13 22:57:33 +00:00
|
|
|
limit: 10,
|
2024-06-26 08:22:05 +00:00
|
|
|
random_limit: 100
|
2023-12-13 22:57:33 +00:00
|
|
|
}
|
2024-06-24 17:50:27 +00:00
|
|
|
const resp = await query(getRandomTopShoutsQuery, { options }).toPromise()
|
|
|
|
setFavoriteTopArticles(resp?.data?.load_shouts_random_top || [])
|
2023-12-13 22:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const loadRandomTopMonthArticles = async () => {
|
|
|
|
const now = new Date()
|
2023-12-18 01:15:49 +00:00
|
|
|
const after = getUnixtime(new Date(now.setMonth(now.getMonth() - 1)))
|
2023-12-13 22:57:33 +00:00
|
|
|
|
2023-12-18 01:15:49 +00:00
|
|
|
const options: LoadShoutsOptions = {
|
2024-03-29 17:25:07 +00:00
|
|
|
filters: { ...getLoadShoutsFilters({ after }), reacted: true },
|
2023-12-13 22:57:33 +00:00
|
|
|
limit: 10,
|
2024-06-26 08:22:05 +00:00
|
|
|
random_limit: 10
|
2023-12-13 22:57:33 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
const resp = await query(getRandomTopShoutsQuery, { options }).toPromise()
|
|
|
|
setReactedTopMonthArticles(resp?.data?.load_shouts_random_top || [])
|
2023-12-13 22:57:33 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 15:38:02 +00:00
|
|
|
onMount(() => {
|
|
|
|
loadMore(PRERENDERED_ARTICLES_COUNT + LOAD_MORE_PAGE_SIZE)
|
2023-12-13 22:57:33 +00:00
|
|
|
loadRandomTopArticles()
|
|
|
|
loadRandomTopMonthArticles()
|
2023-10-10 15:38:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
createEffect(
|
|
|
|
on(
|
2023-12-13 22:57:33 +00:00
|
|
|
() => props.layout,
|
2023-10-10 15:38:02 +00:00
|
|
|
() => {
|
2024-04-25 13:55:34 +00:00
|
|
|
setExpoShouts([])
|
|
|
|
setIsLoadMoreButtonVisible(false)
|
2024-03-29 17:25:07 +00:00
|
|
|
setFavoriteTopArticles([])
|
|
|
|
setReactedTopMonthArticles([])
|
2024-04-25 13:55:34 +00:00
|
|
|
setArticlesEndPage(PRERENDERED_ARTICLES_COUNT)
|
2023-10-10 15:38:02 +00:00
|
|
|
loadMore(PRERENDERED_ARTICLES_COUNT + LOAD_MORE_PAGE_SIZE)
|
2023-12-13 22:57:33 +00:00
|
|
|
loadRandomTopArticles()
|
|
|
|
loadRandomTopMonthArticles()
|
2024-06-26 08:22:05 +00:00
|
|
|
}
|
|
|
|
)
|
2023-10-10 15:38:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
onCleanup(() => {
|
2024-04-25 13:55:34 +00:00
|
|
|
setExpoShouts([])
|
2023-10-10 15:38:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const handleLoadMoreClick = () => {
|
2024-03-29 17:25:17 +00:00
|
|
|
loadMoreWithoutScrolling(LOAD_MORE_PAGE_SIZE)
|
2024-04-25 13:55:34 +00:00
|
|
|
setArticlesEndPage((prev) => prev + LOAD_MORE_PAGE_SIZE)
|
2024-03-29 17:25:17 +00:00
|
|
|
}
|
2024-06-06 10:25:39 +00:00
|
|
|
console.log(props.layout)
|
2023-10-10 15:38:02 +00:00
|
|
|
return (
|
|
|
|
<div class={styles.Expo}>
|
2024-05-10 12:59:21 +00:00
|
|
|
<div class="wide-container">
|
|
|
|
<ul class={clsx('view-switcher')}>
|
|
|
|
<li class={clsx({ 'view-switcher__item--selected': !props.layout })}>
|
2024-06-24 17:50:27 +00:00
|
|
|
<A href={'/expo'}>
|
2024-05-10 12:59:21 +00:00
|
|
|
<span class={clsx('linkReplacement')}>{t('All')}</span>
|
2024-06-24 17:50:27 +00:00
|
|
|
</A>
|
2024-05-10 12:59:21 +00:00
|
|
|
</li>
|
|
|
|
<li class={clsx({ 'view-switcher__item--selected': props.layout === 'literature' })}>
|
|
|
|
<ConditionalWrapper
|
|
|
|
condition={props.layout !== 'literature'}
|
2024-06-24 17:50:27 +00:00
|
|
|
wrapper={(children) => <A href={'/expo/literature'}>{children}</A>}
|
2024-05-10 12:59:21 +00:00
|
|
|
>
|
|
|
|
<span class={clsx('linkReplacement')}>{t('Literature')}</span>
|
|
|
|
</ConditionalWrapper>
|
|
|
|
</li>
|
2024-06-24 17:50:27 +00:00
|
|
|
<li class={clsx({ 'view-switcher__item--selected': props.layout === ('audio' as LayoutType) })}>
|
2024-05-10 12:59:21 +00:00
|
|
|
<ConditionalWrapper
|
2024-06-24 17:50:27 +00:00
|
|
|
condition={props.layout !== ('audio' as LayoutType)}
|
|
|
|
wrapper={(children) => <A href={'/expo/audio'}>{children}</A>}
|
2024-05-10 12:59:21 +00:00
|
|
|
>
|
|
|
|
<span class={clsx('linkReplacement')}>{t('Music')}</span>
|
|
|
|
</ConditionalWrapper>
|
|
|
|
</li>
|
|
|
|
<li class={clsx({ 'view-switcher__item--selected': props.layout === 'image' })}>
|
|
|
|
<ConditionalWrapper
|
|
|
|
condition={props.layout !== 'image'}
|
2024-06-24 17:50:27 +00:00
|
|
|
wrapper={(children) => <A href={'/expo/image'}>{children}</A>}
|
2024-05-10 12:59:21 +00:00
|
|
|
>
|
|
|
|
<span class={clsx('linkReplacement')}>{t('Gallery')}</span>
|
|
|
|
</ConditionalWrapper>
|
|
|
|
</li>
|
|
|
|
<li class={clsx({ 'view-switcher__item--selected': props.layout === 'video' })}>
|
|
|
|
<ConditionalWrapper
|
|
|
|
condition={props.layout !== 'video'}
|
2024-06-24 17:50:27 +00:00
|
|
|
wrapper={(children) => <A href={'/expo/video'}>{children}</A>}
|
2024-05-10 12:59:21 +00:00
|
|
|
>
|
|
|
|
<span class={clsx('cursorPointer linkReplacement')}>{t('Video')}</span>
|
|
|
|
</ConditionalWrapper>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
2024-04-25 13:55:34 +00:00
|
|
|
<Show when={expoShouts().length > 0} fallback={<Loading />}>
|
2023-10-10 15:38:02 +00:00
|
|
|
<div class="wide-container">
|
|
|
|
<div class="row">
|
2024-04-25 13:55:34 +00:00
|
|
|
<For each={expoShouts()?.slice(0, LOAD_MORE_PAGE_SIZE)}>
|
2023-12-13 22:57:33 +00:00
|
|
|
{(shout) => (
|
|
|
|
<div class="col-md-6 mt-md-5 col-sm-8 mt-sm-3">
|
|
|
|
<ArticleCard
|
|
|
|
article={shout}
|
|
|
|
settings={{ nodate: true, nosubtitle: true, noAuthorLink: true }}
|
|
|
|
desktopCoverSize="XS"
|
2023-12-25 11:35:04 +00:00
|
|
|
withAspectRatio={true}
|
2023-12-13 22:57:33 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
2024-03-29 17:25:07 +00:00
|
|
|
<Show when={reactedTopMonthArticles()?.length > 0} keyed={true}>
|
2024-05-06 23:44:25 +00:00
|
|
|
<ArticleCardSwiper title={t('Top month')} slides={reactedTopMonthArticles()} />
|
2023-12-13 22:57:33 +00:00
|
|
|
</Show>
|
2024-04-25 13:55:34 +00:00
|
|
|
<For each={expoShouts().slice(LOAD_MORE_PAGE_SIZE, LOAD_MORE_PAGE_SIZE * 2)}>
|
2023-10-10 15:38:02 +00:00
|
|
|
{(shout) => (
|
|
|
|
<div class="col-md-6 mt-md-5 col-sm-8 mt-sm-3">
|
|
|
|
<ArticleCard
|
|
|
|
article={shout}
|
|
|
|
settings={{ nodate: true, nosubtitle: true, noAuthorLink: true }}
|
2023-11-18 14:10:02 +00:00
|
|
|
desktopCoverSize="XS"
|
2023-12-25 11:35:04 +00:00
|
|
|
withAspectRatio={true}
|
2023-10-10 15:38:02 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
2024-03-29 17:25:07 +00:00
|
|
|
<Show when={favoriteTopArticles()?.length > 0} keyed={true}>
|
|
|
|
<ArticleCardSwiper title={t('Favorite')} slides={favoriteTopArticles()} />
|
2023-12-13 22:57:33 +00:00
|
|
|
</Show>
|
2024-04-25 13:55:34 +00:00
|
|
|
<For each={expoShouts().slice(LOAD_MORE_PAGE_SIZE * 2, articlesEndPage())}>
|
2024-03-27 00:54:15 +00:00
|
|
|
{(shout) => (
|
|
|
|
<div class="col-md-6 mt-md-5 col-sm-8 mt-sm-3">
|
|
|
|
<ArticleCard
|
|
|
|
article={shout}
|
|
|
|
settings={{ nodate: true, nosubtitle: true, noAuthorLink: true }}
|
|
|
|
desktopCoverSize="XS"
|
|
|
|
withAspectRatio={true}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-10-10 15:38:02 +00:00
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
<Show when={isLoadMoreButtonVisible()}>
|
|
|
|
<div class={styles.showMore}>
|
|
|
|
<Button size="L" onClick={handleLoadMoreClick} value={t('Load more')} />
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|