import { clsx } from 'clsx' import styles from './AuthorBadge.module.scss' import { Userpic } from '../Userpic' import { Author, FollowingEntity } from '../../../graphql/types.gen' import { createMemo, createSignal, Show } from 'solid-js' import { formatDate } from '../../../utils' import { useLocalize } from '../../../context/localize' import { Button } from '../../_shared/Button' import { useSession } from '../../../context/session' import { follow, unfollow } from '../../../stores/zine/common' import { CheckButton } from '../../_shared/CheckButton' type Props = { author: Author minimizeSubscribeButton?: boolean } export const AuthorBadge = (props: Props) => { const [isSubscribing, setIsSubscribing] = createSignal(false) const { session, actions: { loadSession, requireAuthentication } } = useSession() const { t } = useLocalize() 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 handleSubscribe = (really: boolean) => { requireAuthentication(() => { subscribe(really) }, 'subscribe') } return (
{props.author.name}
{t('Registered since {{date}}', { date: formatDate(new Date(props.author.createdAt)) })}
} >
handleSubscribe(!subscribed())} /> } > handleSubscribe(true)} /> } >
) }