import { createEffect, createMemo, createSignal, onMount, Show, Suspense } from 'solid-js' import Banner from '../Discours/Banner' import NavTopics from '../Nav/Topics' import Row5 from '../Feed/Row5' 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' import type { Shout, Topic } from '../../graphql/types.gen' import Icon from '../Nav/Icon' import { t } from '../../utils/intl' import { setTopRated, topRated, topViewed, topAuthors, topTopics, topRatedMonth, topCommented } from '../../stores/zine/top' import { useTopicsStore } from '../../stores/zine/topics' import { loadMorePublished, useArticlesStore } from '../../stores/zine/articles' import { sortBy } from '../../utils/sortby' import { shuffle } from '../../utils' type HomeProps = { randomTopics: Topic[] recentPublishedArticles: Shout[] topMonthArticles: Shout[] topOverallArticles: Shout[] page?: number size?: number } const LAYOUTS = ['article', 'prose', 'music', 'video', 'image'] export const HomePage = (props: HomeProps) => { const [someLayout, setSomeLayout] = createSignal([] as Shout[]) const [selectedLayout, setSelectedLayout] = createSignal('article') const [byLayout, setByLayout] = createSignal<{ [layout: string]: Shout[] }>({}) const { getSortedArticles: articles, getArticlesByTopics: byTopic } = useArticlesStore({ sortedArticles: props.recentPublishedArticles }) const { getSortedTopics } = useTopicsStore({ topics: sortBy(props.randomTopics, 'shouts') }) createEffect(() => { if (articles() && articles().length > 0 && Object.keys(byTopic()).length === 0) { console.debug('[home] ' + articles().length.toString() + ' overall shouts loaded') console.log('[home] preparing published articles...') // get shouts lists by const bl: { [key: string]: Shout[] } = {} articles().forEach((s: Shout) => { // by layout const l = s.layout || 'article' if (!bl[l]) bl[l] = [] bl[l].push(s) }) setByLayout(bl) console.log('[home] some grouped by layout articles are ready') } }, [articles()]) createEffect(() => { if (getSortedTopics() && !selectedLayout()) { // random special layout pick const special = LAYOUTS.filter((la) => la !== 'article') const layout = special[Math.floor(Math.random() * special.length)] setSomeLayout(byLayout()[layout]) setSelectedLayout(layout) console.log(`[home] <${layout}> layout picked`) } }, [byLayout()]) onMount(() => { if (props.topOverallArticles) setTopRated(props.topOverallArticles) console.info('[home] mounted') }) const getRandomTopics = () => shuffle(getSortedTopics()).slice(0, 12) return ( {t('Top commented')}} /> } />

) }