import { Show, createMemo, createSignal, For, onMount } from 'solid-js' import type { Author, Shout } from '../../graphql/types.gen' import { Row2 } from '../Feed/Row2' import { Row3 } from '../Feed/Row3' import { AuthorFull } from '../Author/Full' import { t } from '../../utils/intl' import { useAuthorsStore } from '../../stores/zine/authors' import { loadShouts, useArticlesStore } from '../../stores/zine/articles' import { useTopicsStore } from '../../stores/zine/topics' import { useRouter } from '../../stores/router' import { Beside } from '../Feed/Beside' import { restoreScrollPosition, saveScrollPosition } from '../../utils/scroll' import { splitToPages } from '../../utils/splitToPages' // TODO: load reactions on client type AuthorProps = { shouts: Shout[] author: Author authorSlug: string // FIXME author topics from server // topics: Topic[] } type AuthorPageSearchParams = { by: '' | 'viewed' | 'rating' | 'commented' | 'recent' | 'followed' } export const PRERENDERED_ARTICLES_COUNT = 12 const LOAD_MORE_PAGE_SIZE = 9 // Row3 + Row3 + Row3 export const AuthorView = (props: AuthorProps) => { const { sortedArticles } = useArticlesStore({ shouts: props.shouts }) const { authorEntities } = useAuthorsStore({ authors: [props.author] }) const { topicsByAuthor } = useTopicsStore() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const author = createMemo(() => authorEntities()[props.authorSlug]) const { searchParams, changeSearchParam } = useRouter() const loadMore = async () => { saveScrollPosition() const { hasMore } = await loadShouts({ filters: { author: author().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 (
{t('Loading')}
}>
{`${t('Show')} `} {t('All posts')}
{(page) => ( <> )}

) }