2022-09-22 09:37:49 +00:00
|
|
|
import { createMemo, 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-09-09 11:53:35 +00:00
|
|
|
import Row3 from '../Feed/Row3'
|
|
|
|
import Row2 from '../Feed/Row2'
|
|
|
|
import Row1 from '../Feed/Row1'
|
|
|
|
import Hero from '../Discours/Hero'
|
|
|
|
import Beside from '../Feed/Beside'
|
|
|
|
import RowShort from '../Feed/RowShort'
|
|
|
|
import Slider from '../Feed/Slider'
|
|
|
|
import Group from '../Feed/Group'
|
2022-09-22 09:37:49 +00:00
|
|
|
import { getLogger } from '../../utils/logger'
|
2022-09-09 11:53:35 +00:00
|
|
|
import type { Shout, Topic } from '../../graphql/types.gen'
|
2022-09-22 09:37:49 +00:00
|
|
|
import { Icon } from '../Nav/Icon'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { t } from '../../utils/intl'
|
|
|
|
import { useTopicsStore } from '../../stores/zine/topics'
|
2022-09-22 09:37:49 +00:00
|
|
|
import {
|
|
|
|
loadPublishedArticles,
|
|
|
|
loadTopArticles,
|
|
|
|
loadTopMonthArticles,
|
|
|
|
useArticlesStore
|
|
|
|
} from '../../stores/zine/articles'
|
|
|
|
import { useTopAuthorsStore } from '../../stores/zine/topAuthors'
|
|
|
|
|
|
|
|
const log = getLogger('home view')
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
type HomeProps = {
|
|
|
|
randomTopics: Topic[]
|
|
|
|
recentPublishedArticles: Shout[]
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
const CLIENT_LOAD_ARTICLES_COUNT = 30
|
|
|
|
const LOAD_MORE_ARTICLES_COUNT = 30
|
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 {
|
|
|
|
getSortedArticles,
|
2022-09-22 09:37:49 +00:00
|
|
|
getTopArticles,
|
|
|
|
getTopMonthArticles,
|
2022-09-13 09:59:04 +00:00
|
|
|
getTopViewedArticles,
|
2022-09-22 09:37:49 +00:00
|
|
|
getTopCommentedArticles,
|
|
|
|
getArticlesByLayout
|
2022-09-13 09:59:04 +00:00
|
|
|
} = useArticlesStore({
|
2022-09-22 09:37:49 +00:00
|
|
|
sortedArticles: props.recentPublishedArticles
|
2022-09-13 08:05:11 +00:00
|
|
|
})
|
2022-09-22 09:37:49 +00:00
|
|
|
const { getRandomTopics, getTopTopics } = useTopicsStore({
|
2022-09-13 09:59:04 +00:00
|
|
|
randomTopics: props.randomTopics
|
|
|
|
})
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
const { getTopAuthors } = useTopAuthorsStore()
|
2022-09-13 09:59:04 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
onMount(() => {
|
|
|
|
loadTopArticles()
|
|
|
|
loadTopMonthArticles()
|
|
|
|
loadPublishedArticles({ limit: CLIENT_LOAD_ARTICLES_COUNT, offset: getSortedArticles().length })
|
|
|
|
})
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
const randomLayout = createMemo(() => {
|
|
|
|
const articlesByLayout = getArticlesByLayout()
|
|
|
|
const filledLayouts = Object.keys(articlesByLayout).filter(
|
|
|
|
// FIXME: is 7 ok? or more complex logic needed?
|
|
|
|
(layout) => articlesByLayout[layout].length > 7
|
|
|
|
)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
const randomLayout =
|
|
|
|
filledLayouts.length > 0 ? filledLayouts[Math.floor(Math.random() * filledLayouts.length)] : ''
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Show when={Boolean(randomLayout)}>
|
2022-09-09 11:53:35 +00:00
|
|
|
<Group
|
2022-09-22 09:37:49 +00:00
|
|
|
articles={articlesByLayout[randomLayout]}
|
2022-09-09 11:53:35 +00:00
|
|
|
header={
|
|
|
|
<div class="layout-icon">
|
2022-09-22 09:37:49 +00:00
|
|
|
<Icon name={randomLayout} />
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
2022-09-22 09:37:49 +00:00
|
|
|
</Show>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
const loadMore = () => {
|
|
|
|
loadPublishedArticles({ limit: LOAD_MORE_ARTICLES_COUNT, offset: getSortedArticles().length })
|
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<NavTopics topics={getRandomTopics()} />
|
|
|
|
|
|
|
|
<Row5 articles={getSortedArticles().slice(0, 5)} />
|
|
|
|
|
|
|
|
<Hero />
|
|
|
|
|
|
|
|
<Beside
|
|
|
|
beside={getSortedArticles().slice(4, 5)[0]}
|
|
|
|
title={t('Top viewed')}
|
|
|
|
values={getTopViewedArticles().slice(0, 5)}
|
|
|
|
wrapper={'top-article'}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Row3 articles={getSortedArticles().slice(6, 9)} />
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
{/*FIXME: ?*/}
|
|
|
|
<Show when={getTopAuthors().length === 5}>
|
2022-09-09 11:53:35 +00:00
|
|
|
<Beside
|
2022-09-22 09:37:49 +00:00
|
|
|
beside={getSortedArticles().slice(8, 9)[0]}
|
|
|
|
title={t('Top authors')}
|
|
|
|
values={getTopAuthors()}
|
|
|
|
wrapper={'author'}
|
2022-09-09 11:53:35 +00:00
|
|
|
/>
|
|
|
|
</Show>
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
<Slider title={t('Top month articles')} articles={getTopMonthArticles()} />
|
|
|
|
|
|
|
|
<Row2 articles={getSortedArticles().slice(10, 12)} />
|
|
|
|
|
|
|
|
<RowShort articles={getSortedArticles().slice(12, 16)} />
|
|
|
|
|
|
|
|
<Row1 article={getSortedArticles().slice(15, 16)[0]} />
|
|
|
|
<Row3 articles={getSortedArticles().slice(17, 20)} />
|
|
|
|
<Row3 articles={getTopCommentedArticles()} header={<h2>{t('Top commented')}</h2>} />
|
|
|
|
|
|
|
|
{randomLayout()}
|
|
|
|
|
|
|
|
<Slider title={t('Favorite')} articles={getTopArticles()} />
|
|
|
|
|
|
|
|
<Beside
|
|
|
|
beside={getSortedArticles().slice(19, 20)[0]}
|
|
|
|
title={t('Top topics')}
|
|
|
|
values={getTopTopics().slice(0, 5)}
|
|
|
|
wrapper={'topic'}
|
|
|
|
isTopicCompact={true}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Row3 articles={getSortedArticles().slice(21, 24)} />
|
|
|
|
|
|
|
|
<Banner />
|
|
|
|
|
|
|
|
<Row2 articles={getSortedArticles().slice(24, 26)} />
|
|
|
|
<Row3 articles={getSortedArticles().slice(26, 29)} />
|
|
|
|
<Row2 articles={getSortedArticles().slice(29, 31)} />
|
|
|
|
<Row3 articles={getSortedArticles().slice(31, 34)} />
|
|
|
|
|
|
|
|
<For each={getSortedArticles().slice(35)}>{(article) => <Row1 article={article} />}</For>
|
|
|
|
|
|
|
|
<p class="load-more-container">
|
|
|
|
<button class="button" onClick={loadMore}>
|
|
|
|
{t('Load more')}
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</>
|
2022-09-09 11:53:35 +00:00
|
|
|
)
|
|
|
|
}
|