import { createMemo, createSignal, 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 { useTopicsStore } from '../../stores/zine/topics' import { loadPublishedArticles, useArticlesStore } from '../../stores/zine/articles' import { useAuthorsStore } from '../../stores/zine/authors' import { router } from '../../stores/router' type HomeProps = { randomTopics: Topic[] recentPublishedArticles: Shout[] topMonthArticles: Shout[] topOverallArticles: Shout[] limit?: number offset?: 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({} as { [layout: string]: Shout[] }) const [byTopic, setByTopic] = createSignal({} as { [topic: string]: Shout[] }) const { getSortedArticles, getTopRatedArticles, getTopRatedMonthArticles, getTopViewedArticles, getTopCommentedArticles } = useArticlesStore({ sortedArticles: props.recentPublishedArticles, topRatedArticles: props.topOverallArticles, topRatedMonthArticles: props.topMonthArticles }) const articles = createMemo(() => getSortedArticles()) const { getRandomTopics, getSortedTopics, getTopTopics } = useTopicsStore({ randomTopics: props.randomTopics }) const { getTopAuthors } = useAuthorsStore() // FIXME // createEffect(() => { // if (articles() && articles().length > 0 && Object.keys(byTopic()).length === 0) { // console.debug('[home] ' + getRandomTopics().length.toString() + ' random topics loaded') // console.debug('[home] ' + articles().length.toString() + ' overall shouts loaded') // console.log('[home] preparing published articles...') // // get shouts lists by // const bl: { [key: string]: Shout[] } = {} // const bt: { [key: string]: Shout[] } = {} // articles().forEach((s: Shout) => { // // by topic // s.topics?.forEach(({ slug }: any) => { // if (!bt[slug || '']) bt[slug || ''] = [] // bt[slug as string].push(s) // }) // // by layout // const l = s.layout || 'article' // if (!bl[l]) bl[l] = [] // bl[l].push(s) // }) // setByLayout(bl) // setByTopic(bt) // console.log('[home] some grouped articles are ready') // } // }, [articles()]) // FIXME // createEffect(() => { // if (Object.keys(byLayout()).length > 0 && getSortedTopics()) { // // 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()]) const loadMore = () => { const limit = props.limit || 50 const offset = props.offset || 0 loadPublishedArticles({ limit, offset }) } return ( 0}> {t('Top commented')}} /> } />

) }