import { For, Show, createMemo, onMount, createSignal } from 'solid-js' import type { Shout, Topic } from '../../graphql/types.gen' import { Row3 } from '../Feed/Row3' import { Row2 } from '../Feed/Row2' import { Beside } from '../Feed/Beside' import styles from '../../styles/Topic.module.scss' import { FullTopic } from '../Topic/Full' import { t } from '../../utils/intl' import { useRouter } from '../../stores/router' import { useTopicsStore } from '../../stores/zine/topics' import { loadShouts, useArticlesStore } from '../../stores/zine/articles' import { useAuthorsStore } from '../../stores/zine/authors' import { restoreScrollPosition, saveScrollPosition } from '../../utils/scroll' import { splitToPages } from '../../utils/splitToPages' import { clsx } from 'clsx' import Slider from '../Feed/Slider' import { Row1 } from '../Feed/Row1' type TopicsPageSearchParams = { by: 'comments' | '' | 'recent' | 'viewed' | 'rating' | 'commented' } interface TopicProps { topic: Topic shouts: Shout[] topicSlug: string } export const PRERENDERED_ARTICLES_COUNT = 28 const LOAD_MORE_PAGE_SIZE = 9 // Row3 + Row3 + Row3 export const TopicView = (props: TopicProps) => { const { searchParams, changeSearchParam } = useRouter() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const { sortedArticles } = useArticlesStore({ shouts: props.shouts }) const { topicEntities } = useTopicsStore({ topics: [props.topic] }) const { authorsByTopic } = useAuthorsStore() const topic = createMemo(() => topicEntities()[props.topicSlug]) const loadMore = async () => { saveScrollPosition() const { hasMore } = await loadShouts({ filters: { topic: topic().slug }, limit: LOAD_MORE_PAGE_SIZE, offset: sortedArticles().length }) setIsLoadMoreButtonVisible(hasMore) restoreScrollPosition() } onMount(async () => { if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) { loadMore() } }) const title = createMemo(() => { const m = searchParams().by if (m === 'viewed') return t('Top viewed') if (m === 'rating') return t('Top rated') if (m === 'commented') return t('Top discussed') return t('Top recent') }) const pages = createMemo(() => splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE) ) return (
  • {/*TODO: server sort*/} {/*
  • */} {/* */} {/*
  • */} {/*
  • */} {/* */} {/*
  • */} {/*
  • */} {/* */} {/*
  • */}
{`${t('Show')} `} {t('All posts')}
{(page) => ( <> )}

) }