import type { Author } from '../../../graphql/types.gen' import { Userpic } from '../Userpic' import { Icon } from '../../_shared/Icon' import styles from './AuthorCard.module.scss' import { createEffect, createMemo, createSignal, For, Match, Show, Switch } from 'solid-js' import { translit } from '../../../utils/ru2en' import { follow, unfollow } from '../../../stores/zine/common' import { clsx } from 'clsx' import { useSession } from '../../../context/session' import { ShowOnlyOnClient } from '../../_shared/ShowOnlyOnClient' import { FollowingEntity, Topic } from '../../../graphql/types.gen' import { router, useRouter } from '../../../stores/router' import { openPage, redirectPage } from '@nanostores/router' import { useLocalize } from '../../../context/localize' import { ConditionalWrapper } from '../../_shared/ConditionalWrapper' import { Modal } from '../../Nav/Modal' import { SubscriptionFilter } from '../../../pages/types' import { isAuthor } from '../../../utils/isAuthor' import { AuthorBadge } from '../AuthorBadge' import { TopicBadge } from '../../Topic/TopicBadge' import { Button } from '../../_shared/Button' import { getShareUrl, SharePopup } from '../../Article/SharePopup' import stylesHeader from '../../Nav/Header/Header.module.scss' type Props = { caption?: string hideWriteButton?: boolean hideDescription?: boolean hideFollow?: boolean hasLink?: boolean subscribed?: boolean author: Author isAuthorPage?: boolean noSocialButtons?: boolean isAuthorsList?: boolean truncateBio?: boolean liteButtons?: boolean isTextButton?: boolean isComments?: boolean isFeedMode?: boolean isNowrap?: boolean class?: string followers?: Author[] following?: Array showPublicationsCounter?: boolean hideBio?: boolean isCurrentUser?: boolean } export const AuthorCard = (props: Props) => { const { t, lang } = useLocalize() const { session, isSessionLoaded, actions: { loadSession, requireAuthentication } } = useSession() const [isSubscribing, setIsSubscribing] = createSignal(false) const [following, setFollowing] = createSignal>(props.following) const [subscriptionFilter, setSubscriptionFilter] = createSignal('all') const [userpicUrl, setUserpicUrl] = createSignal() const subscribed = createMemo(() => { return session()?.news?.authors?.some((u) => u === props.author.slug) || false }) const subscribe = async (really = true) => { setIsSubscribing(true) await (really ? follow({ what: FollowingEntity.Author, slug: props.author.slug }) : unfollow({ what: FollowingEntity.Author, slug: props.author.slug })) await loadSession() setIsSubscribing(false) } const canFollow = createMemo(() => !props.hideFollow && session()?.user?.slug !== props.author.slug) const name = createMemo(() => { if (lang() !== 'ru') { if (props.author.name === 'Дискурс') { return 'Discours' } return translit(props.author.name) } return props.author.name }) // TODO: reimplement AuthorCard const { changeSearchParam } = useRouter() const initChat = () => { requireAuthentication(() => { openPage(router, `inbox`) changeSearchParam({ initChat: props.author.id.toString() }) }, 'discussions') } const handleSubscribe = () => { requireAuthentication(() => { subscribe(true) }, 'subscribe') } createEffect(() => { if (props.following) { if (subscriptionFilter() === 'users') { setFollowing(props.following.filter((s) => 'name' in s)) } else if (subscriptionFilter() === 'topics') { setFollowing(props.following.filter((s) => 'title' in s)) } else { setFollowing(props.following) } } }) if (props.isAuthorPage && props.author.userpic?.includes('assets.discours.io')) { setUserpicUrl(props.author.userpic.replace('100x', '500x500')) } return (
} >
( {children} )} > {name()}
{t('PublicationsWithCount', { count: props.author.stat?.shouts ?? 0 })}
) : ( '' ) } > 0}>
{t('Follow')} } >
<>

{t('Followers')}

{(follower: Author) => }
<>

{t('Subscriptions')}

  • {props.following.length}
  • {props.following.filter((s) => 'name' in s).length}
  • {props.following.filter((s) => 'title' in s).length}

{(subscription) => isAuthor(subscription) ? ( ) : ( ) }
) }