import type { Author, Reaction, Shout, Topic } from '../../../graphql/schema/core.gen' import { getPagePath } from '@nanostores/router' import { Meta, Title } from '@solidjs/meta' import { clsx } from 'clsx' import { Show, createMemo, createSignal, Switch, onMount, For, Match, createEffect } from 'solid-js' import { useFollowing } from '../../../context/following' import { useLocalize } from '../../../context/localize' import { apiClient } from '../../../graphql/client/core' import { router, useRouter } from '../../../stores/router' import { loadMyFeed, loadShouts, useArticlesStore } from '../../../stores/zine/articles' import { loadAuthor, 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 { AuthorShoutsRating } from '../../Author/AuthorShoutsRating' 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 { loadSubscriptions } = useFollowing() 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 [commented, setCommented] = createSignal() // current author const [author, setAuthor] = createSignal() createEffect(() => { try { const a = authorEntities()[props.authorSlug] setAuthor(a) } catch (error) { console.debug(error) } }) createEffect(() => { if (author() && author().id && !author().stat) { const a = loadAuthor({ slug: '', author_id: author().id }) console.debug(`[AuthorView] loaded author:`, a) } }) const bioContainerRef: { current: HTMLDivElement } = { current: null } const bioWrapperRef: { current: HTMLDivElement } = { current: null } const fetchData = async (slug) => { try { const [subscriptionsResult, followersResult] = await Promise.all([ (async () => { const [getAuthors, getTopics] = await Promise.all([ apiClient.getAuthorFollowingAuthors({ slug }), apiClient.getAuthorFollowingTopics({ slug }), ]) return { authors: getAuthors, topics: getTopics } })(), apiClient.getAuthorFollowers({ slug }), ]) const { authors, topics } = subscriptionsResult setFollowing([...(authors || []), ...(topics || [])]) setFollowers(followersResult || []) console.info('[components.Author] following data loaded') } catch (error) { console.error('[components.Author] fetch error', error) } } const checkBioHeight = () => { if (bioContainerRef.current) { setShowExpandBioControl(bioContainerRef.current.offsetHeight > bioWrapperRef.current.offsetHeight) } } onMount(() => fetchData(props.authorSlug)) const loadMore = async () => { saveScrollPosition() const { hasMore } = await loadShouts({ filters: { author: props.authorSlug }, limit: LOAD_MORE_PAGE_SIZE, offset: sortedArticles().length, }) setIsLoadMoreButtonVisible(hasMore) restoreScrollPosition() } onMount(() => { checkBioHeight() // pagination if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) { loadMore() loadSubscriptions() } }) const pages = createMemo(() => splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE), ) const fetchComments = async (commenter: Author) => { const data = await apiClient.getReactionsBy({ by: { comment: false, created_by: commenter.id }, }) console.debug(`[components.Author] fetched comments`, data) setCommented(data) } createEffect(() => { const a = author() if (a) { fetchComments(a) } }) const ogImage = createMemo(() => author()?.pic ? getImageUrl(author()?.pic, { width: 1200 }) : getImageUrl('production/image/logo_image.png'), ) const description = createMemo(() => getDescription(author()?.bio)) return (
{author().name}
(bioWrapperRef.current = el)} class={styles.longBio} classList={{ [styles.longBioExpanded]: isBioExpanded() }} >
(bioContainerRef.current = el)} innerHTML={author().about} />
    {(comment) => }
3}> {(page) => ( <> )}

) }