import type { Author, Shout, Topic } from '../../../graphql/schema/core.gen' import { getPagePath } from '@nanostores/router' import { Meta } from '@solidjs/meta' import { clsx } from 'clsx' import { Show, createMemo, createSignal, Switch, onMount, For, Match, createEffect } from 'solid-js' import { useLocalize } from '../../../context/localize' import { apiClient } from '../../../graphql/client/core' import { router, useRouter } from '../../../stores/router' import { loadShouts, useArticlesStore } from '../../../stores/zine/articles' import { useAuthorsStore } from '../../../stores/zine/authors' import { getImageUrl } from '../../../utils/getImageUrl' import { getDescription } from '../../../utils/meta' import { restoreScrollPosition, saveScrollPosition } from '../../../utils/scroll' import { splitToPages } from '../../../utils/splitToPages' import { Loading } from '../../_shared/Loading' import { Comment } from '../../Article/Comment' import { AuthorCard } from '../../Author/AuthorCard' import { AuthorRatingControl } from '../../Author/AuthorRatingControl' import { Row1 } from '../../Feed/Row1' import { Row2 } from '../../Feed/Row2' import { Row3 } from '../../Feed/Row3' import styles from './Author.module.scss' import stylesArticle from '../../Article/Article.module.scss' type Props = { shouts: Shout[] author: Author authorSlug: string } export const PRERENDERED_ARTICLES_COUNT = 12 const LOAD_MORE_PAGE_SIZE = 9 export const AuthorView = (props: Props) => { const { t } = useLocalize() const { sortedArticles } = useArticlesStore({ shouts: props.shouts }) const { authorEntities } = useAuthorsStore({ authors: [props.author] }) const { page: getPage } = useRouter() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [isBioExpanded, setIsBioExpanded] = createSignal(false) const [followers, setFollowers] = createSignal([]) const [following, setFollowing] = createSignal>([]) const [showExpandBioControl, setShowExpandBioControl] = createSignal(false) const author = createMemo(() => authorEntities()[props.authorSlug]) createEffect(async () => { if (author() && !author().stat) { await apiClient.getAuthor({ author_id: author().id }) } }) const bioContainerRef: { current: HTMLDivElement } = { current: null } const bioWrapperRef: { current: HTMLDivElement } = { current: null } const fetchSubscriptions = async (): Promise<{ authors: Author[]; topics: Topic[] }> => { try { const [getAuthors, getTopics] = await Promise.all([ apiClient.getAuthorFollowingUsers({ slug: props.authorSlug }), apiClient.getAuthorFollowingTopics({ slug: props.authorSlug }), ]) const authors = getAuthors const topics = getTopics return { authors, topics } } catch (error) { console.error('[fetchSubscriptions] :', error) throw error } } const checkBioHeight = () => { if (bioContainerRef.current) { setShowExpandBioControl(bioContainerRef.current.offsetHeight > bioWrapperRef.current.offsetHeight) } } onMount(async () => { checkBioHeight() // pagination if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) { await loadMore() } }) createEffect(async () => { console.error('[AuthorView] load subscriptions') try { const { authors, topics } = await fetchSubscriptions() setFollowing([...(authors || []), ...(topics || [])]) const userSubscribers = await apiClient.getAuthorFollowers({ slug: author().slug }) setFollowers(userSubscribers) } catch (error) { console.error('[AuthorView] error:', error) } }) createEffect(() => { document.title = author()?.name }) const loadMore = async () => { saveScrollPosition() const { hasMore } = await loadShouts({ filters: { author: props.authorSlug }, limit: LOAD_MORE_PAGE_SIZE, offset: sortedArticles().length, }) setIsLoadMoreButtonVisible(hasMore) restoreScrollPosition() } // TODO: use title // 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), ) const [commented, setCommented] = createSignal([]) createEffect(async () => { if (getPage().route === 'authorComments' && props.author) { try { const data = await apiClient.getReactionsBy({ by: { comment: true, created_by: props.author.id }, }) setCommented(data) } catch (error) { console.error('[getReactionsBy comment]', error) } } }) const ogImage = props.author?.pic ? getImageUrl(props.author.pic, { width: 1200 }) : getImageUrl('production/image/logo_image.png') const description = getDescription(props.author?.bio) const ogTitle = props.author?.name return (
(bioWrapperRef.current = el)} class={styles.longBio} classList={{ [styles.longBioExpanded]: isBioExpanded() }} >
(bioContainerRef.current = el)} innerHTML={author().about} />
    {(comment) => }
3}> {(page) => ( <> )}

) }