2022-10-28 21:21:47 +00:00
|
|
|
import { createMemo, createSignal, For, onMount, Show } from 'solid-js'
|
2022-09-09 11:53:35 +00:00
|
|
|
import Banner from '../Discours/Banner'
|
2022-09-22 09:37:49 +00:00
|
|
|
import { NavTopics } from '../Nav/Topics'
|
|
|
|
import { Row5 } from '../Feed/Row5'
|
2022-10-28 21:21:47 +00:00
|
|
|
import { Row3 } from '../Feed/Row3'
|
|
|
|
import { Row2 } from '../Feed/Row2'
|
|
|
|
import { Row1 } from '../Feed/Row1'
|
2022-09-09 11:53:35 +00:00
|
|
|
import Hero from '../Discours/Hero'
|
2022-10-28 21:21:47 +00:00
|
|
|
import { Beside } from '../Feed/Beside'
|
2022-09-09 11:53:35 +00:00
|
|
|
import RowShort from '../Feed/RowShort'
|
2022-11-27 17:02:04 +00:00
|
|
|
import Slider from '../_shared/Slider'
|
2022-09-09 11:53:35 +00:00
|
|
|
import Group from '../Feed/Group'
|
|
|
|
import type { Shout, Topic } from '../../graphql/types.gen'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
import { useTopicsStore } from '../../stores/zine/topics'
|
2022-12-01 18:45:35 +00:00
|
|
|
import {
|
|
|
|
loadShouts,
|
|
|
|
loadTopArticles,
|
|
|
|
loadTopMonthArticles,
|
|
|
|
useArticlesStore
|
|
|
|
} from '../../stores/zine/articles'
|
2022-09-22 09:37:49 +00:00
|
|
|
import { useTopAuthorsStore } from '../../stores/zine/topAuthors'
|
2022-09-29 14:40:11 +00:00
|
|
|
import { restoreScrollPosition, saveScrollPosition } from '../../utils/scroll'
|
2022-10-28 21:21:47 +00:00
|
|
|
import { splitToPages } from '../../utils/splitToPages'
|
2023-05-01 18:32:32 +00:00
|
|
|
import { ArticleCard } from '../Feed/ArticleCard'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useLocalize } from '../../context/localize'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
type HomeProps = {
|
|
|
|
randomTopics: Topic[]
|
2022-11-15 14:24:50 +00:00
|
|
|
shouts: Shout[]
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
2022-10-28 21:21:47 +00:00
|
|
|
|
|
|
|
export const PRERENDERED_ARTICLES_COUNT = 5
|
2022-11-22 03:02:11 +00:00
|
|
|
export const RANDOM_TOPICS_COUNT = 12
|
2022-09-29 14:40:11 +00:00
|
|
|
const CLIENT_LOAD_ARTICLES_COUNT = 29
|
|
|
|
const LOAD_MORE_PAGE_SIZE = 16 // Row1 + Row3 + Row2 + Beside (3 + 1) + Row1 + Row 2 + Row3
|
2022-09-13 09:59:04 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
export const HomeView = (props: HomeProps) => {
|
2022-09-13 09:59:04 +00:00
|
|
|
const {
|
2022-09-28 20:16:44 +00:00
|
|
|
sortedArticles,
|
2022-11-15 14:24:50 +00:00
|
|
|
articlesByLayout,
|
2022-09-28 20:16:44 +00:00
|
|
|
topArticles,
|
|
|
|
topCommentedArticles,
|
2022-11-15 14:24:50 +00:00
|
|
|
topMonthArticles,
|
|
|
|
topViewedArticles
|
2022-09-13 09:59:04 +00:00
|
|
|
} = useArticlesStore({
|
2022-11-15 14:24:50 +00:00
|
|
|
shouts: props.shouts
|
2022-09-13 08:05:11 +00:00
|
|
|
})
|
2022-09-28 20:16:44 +00:00
|
|
|
const { randomTopics, topTopics } = useTopicsStore({
|
2022-09-13 09:59:04 +00:00
|
|
|
randomTopics: props.randomTopics
|
|
|
|
})
|
2022-10-28 21:21:47 +00:00
|
|
|
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
2022-09-28 20:16:44 +00:00
|
|
|
const { topAuthors } = useTopAuthorsStore()
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t } = useLocalize()
|
2022-09-13 09:59:04 +00:00
|
|
|
|
2022-10-28 21:21:47 +00:00
|
|
|
onMount(async () => {
|
2022-12-01 18:45:35 +00:00
|
|
|
loadTopArticles()
|
|
|
|
loadTopMonthArticles()
|
2022-09-29 14:40:11 +00:00
|
|
|
if (sortedArticles().length < PRERENDERED_ARTICLES_COUNT + CLIENT_LOAD_ARTICLES_COUNT) {
|
2022-11-18 02:23:04 +00:00
|
|
|
const { hasMore } = await loadShouts({
|
2022-11-27 11:00:44 +00:00
|
|
|
filters: { visibility: 'public' },
|
2022-10-28 21:21:47 +00:00
|
|
|
limit: CLIENT_LOAD_ARTICLES_COUNT,
|
|
|
|
offset: sortedArticles().length
|
|
|
|
})
|
|
|
|
|
|
|
|
setIsLoadMoreButtonVisible(hasMore)
|
2022-09-29 14:40:11 +00:00
|
|
|
}
|
2022-09-22 09:37:49 +00:00
|
|
|
})
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
const randomLayout = createMemo(() => {
|
2022-09-28 20:16:44 +00:00
|
|
|
const filledLayouts = Object.keys(articlesByLayout()).filter(
|
2022-09-22 09:37:49 +00:00
|
|
|
// FIXME: is 7 ok? or more complex logic needed?
|
2022-09-28 20:16:44 +00:00
|
|
|
(layout) => articlesByLayout()[layout].length > 7
|
2022-09-22 09:37:49 +00:00
|
|
|
)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-28 20:16:44 +00:00
|
|
|
const selectedRandomLayout =
|
2022-09-22 09:37:49 +00:00
|
|
|
filledLayouts.length > 0 ? filledLayouts[Math.floor(Math.random() * filledLayouts.length)] : ''
|
|
|
|
|
|
|
|
return (
|
2022-09-28 20:16:44 +00:00
|
|
|
<Show when={Boolean(selectedRandomLayout)}>
|
2022-11-16 21:08:04 +00:00
|
|
|
<Group articles={articlesByLayout()[selectedRandomLayout]} header={''} />
|
2022-09-22 09:37:49 +00:00
|
|
|
</Show>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-09-29 14:40:11 +00:00
|
|
|
const loadMore = async () => {
|
|
|
|
saveScrollPosition()
|
2022-10-28 21:21:47 +00:00
|
|
|
|
2022-11-18 02:23:04 +00:00
|
|
|
const { hasMore } = await loadShouts({
|
|
|
|
filters: { visibility: 'public' },
|
2022-10-28 21:21:47 +00:00
|
|
|
limit: LOAD_MORE_PAGE_SIZE,
|
|
|
|
offset: sortedArticles().length
|
|
|
|
})
|
|
|
|
setIsLoadMoreButtonVisible(hasMore)
|
|
|
|
|
2022-09-29 14:40:11 +00:00
|
|
|
restoreScrollPosition()
|
2022-09-22 09:37:49 +00:00
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-10-28 21:21:47 +00:00
|
|
|
const pages = createMemo<Shout[][]>(() =>
|
|
|
|
splitToPages(
|
|
|
|
sortedArticles(),
|
|
|
|
PRERENDERED_ARTICLES_COUNT + CLIENT_LOAD_ARTICLES_COUNT,
|
|
|
|
LOAD_MORE_PAGE_SIZE
|
|
|
|
)
|
|
|
|
)
|
2022-09-29 14:40:11 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
2023-02-17 09:21:02 +00:00
|
|
|
<Show when={sortedArticles().length > 0}>
|
2022-09-28 20:16:44 +00:00
|
|
|
<NavTopics topics={randomTopics()} />
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2023-01-24 22:15:29 +00:00
|
|
|
<Row5 articles={sortedArticles().slice(0, 5)} nodate={true} />
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
<Hero />
|
|
|
|
|
2022-10-05 11:42:13 +00:00
|
|
|
<Show when={sortedArticles().length > PRERENDERED_ARTICLES_COUNT}>
|
2022-09-09 11:53:35 +00:00
|
|
|
<Beside
|
2022-09-28 20:16:44 +00:00
|
|
|
beside={sortedArticles()[5]}
|
|
|
|
title={t('Top viewed')}
|
|
|
|
values={topViewedArticles().slice(0, 5)}
|
|
|
|
wrapper={'top-article'}
|
2023-01-24 22:15:29 +00:00
|
|
|
nodate={true}
|
2022-09-09 11:53:35 +00:00
|
|
|
/>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2023-01-24 22:15:29 +00:00
|
|
|
<Row3 articles={sortedArticles().slice(6, 9)} nodate={true} />
|
2022-09-28 20:16:44 +00:00
|
|
|
|
2022-09-29 14:40:11 +00:00
|
|
|
<Beside
|
|
|
|
beside={sortedArticles()[9]}
|
|
|
|
title={t('Top authors')}
|
|
|
|
values={topAuthors()}
|
|
|
|
wrapper={'author'}
|
2023-01-24 22:15:29 +00:00
|
|
|
nodate={true}
|
2022-09-29 14:40:11 +00:00
|
|
|
/>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-11-27 17:02:04 +00:00
|
|
|
<Slider title={t('Top month articles')}>
|
|
|
|
<For each={topMonthArticles()}>
|
|
|
|
{(a: Shout) => (
|
|
|
|
<ArticleCard
|
|
|
|
article={a}
|
|
|
|
settings={{
|
|
|
|
additionalClass: 'swiper-slide',
|
|
|
|
isFloorImportant: true,
|
|
|
|
isWithCover: true,
|
|
|
|
nodate: true
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</Slider>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2023-01-24 22:15:29 +00:00
|
|
|
<Row2 articles={sortedArticles().slice(10, 12)} nodate={true} />
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-09-28 20:16:44 +00:00
|
|
|
<RowShort articles={sortedArticles().slice(12, 16)} />
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2023-01-24 22:15:29 +00:00
|
|
|
<Row1 article={sortedArticles()[16]} nodate={true} />
|
|
|
|
<Row3 articles={sortedArticles().slice(17, 20)} nodate={true} />
|
|
|
|
<Row3
|
|
|
|
articles={topCommentedArticles().slice(0, 3)}
|
|
|
|
header={<h2>{t('Top commented')}</h2>}
|
|
|
|
nodate={true}
|
|
|
|
/>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-09-28 20:16:44 +00:00
|
|
|
{randomLayout()}
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-11-27 17:02:04 +00:00
|
|
|
<Slider title={t('Favorite')}>
|
|
|
|
<For each={topArticles()}>
|
|
|
|
{(a: Shout) => (
|
|
|
|
<ArticleCard
|
|
|
|
article={a}
|
|
|
|
settings={{
|
|
|
|
additionalClass: 'swiper-slide',
|
|
|
|
isFloorImportant: true,
|
|
|
|
isWithCover: true,
|
|
|
|
nodate: true
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</Slider>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-09-28 20:16:44 +00:00
|
|
|
<Beside
|
|
|
|
beside={sortedArticles()[20]}
|
|
|
|
title={t('Top topics')}
|
|
|
|
values={topTopics().slice(0, 5)}
|
|
|
|
wrapper={'topic'}
|
|
|
|
isTopicCompact={true}
|
2023-01-24 22:15:29 +00:00
|
|
|
nodate={true}
|
2022-09-28 20:16:44 +00:00
|
|
|
/>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2023-06-08 18:19:49 +00:00
|
|
|
<Row3 articles={sortedArticles().slice(21, 24)} nodate={true} />
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-09-28 20:16:44 +00:00
|
|
|
<Banner />
|
|
|
|
|
2023-01-24 22:15:29 +00:00
|
|
|
<Row2 articles={sortedArticles().slice(24, 26)} nodate={true} />
|
|
|
|
<Row3 articles={sortedArticles().slice(26, 29)} nodate={true} />
|
|
|
|
<Row2 articles={sortedArticles().slice(29, 31)} nodate={true} />
|
|
|
|
<Row3 articles={sortedArticles().slice(31, 34)} nodate={true} />
|
2022-09-28 20:16:44 +00:00
|
|
|
</Show>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-09-29 14:40:11 +00:00
|
|
|
<For each={pages()}>
|
|
|
|
{(page) => (
|
|
|
|
<>
|
2023-01-24 22:15:29 +00:00
|
|
|
<Row1 article={page[0]} nodate={true} />
|
|
|
|
<Row3 articles={page.slice(1, 4)} nodate={true} />
|
|
|
|
<Row2 articles={page.slice(4, 6)} nodate={true} />
|
|
|
|
<Beside values={page.slice(6, 9)} beside={page[9]} wrapper="article" nodate={true} />
|
|
|
|
<Row1 article={page[10]} nodate={true} />
|
|
|
|
<Row2 articles={page.slice(11, 13)} nodate={true} />
|
|
|
|
<Row3 articles={page.slice(13, 16)} nodate={true} />
|
2022-09-29 14:40:11 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</For>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
2022-10-28 21:21:47 +00:00
|
|
|
<Show when={isLoadMoreButtonVisible()}>
|
|
|
|
<p class="load-more-container">
|
|
|
|
<button class="button" onClick={loadMore}>
|
|
|
|
{t('Load more')}
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</Show>
|
2022-09-23 23:42:19 +00:00
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
)
|
|
|
|
}
|