import { clsx } from 'clsx' import { Show, createEffect, createSignal } from 'solid-js' import { useFollowing } from '../../../context/following' import { useLocalize } from '../../../context/localize' import { useMediaQuery } from '../../../context/mediaQuery' import { useSession } from '../../../context/session' import { FollowingEntity, Topic } from '../../../graphql/schema/core.gen' import { capitalize } from '../../../utils/capitalize' import { getImageUrl } from '../../../utils/getImageUrl' import { BadgeSubscribeButton } from '../../_shared/BadgeSubscribeButton' import styles from './TopicBadge.module.scss' type Props = { topic: Topic minimizeSubscribeButton?: boolean showStat?: boolean subscriptionsMode?: boolean } export const TopicBadge = (props: Props) => { const { t, lang } = useLocalize() const { mediaMatches } = useMediaQuery() const [isMobileView, setIsMobileView] = createSignal(false) const { requireAuthentication } = useSession() const [isSubscribed, setIsSubscribed] = createSignal() const { follow, unfollow, subscriptions, subscribeInAction } = useFollowing() createEffect(() => { if (!(subscriptions && props.topic)) return const subscribed = subscriptions.topics?.some((topics) => topics.id === props.topic?.id) setIsSubscribed(subscribed) }) const handleFollowClick = () => { requireAuthentication(() => { isSubscribed() ? follow(FollowingEntity.Topic, props.topic.slug) : unfollow(FollowingEntity.Topic, props.topic.slug) }, 'subscribe') } createEffect(() => { setIsMobileView(!mediaMatches.sm) }) const title = () => lang() === 'en' ? capitalize(props.topic.slug.replaceAll('-', ' ')) : props.topic.title return (
{t('shoutsWithCount', { count: props.topic?.stat?.shouts })} {t('authorsWithCount', { count: props.topic?.stat?.authors })} {t('FollowersWithCount', { count: props.topic?.stat?.followers })} {t('CommentsWithCount', { count: props.topic?.stat?.comments ?? 0 })}
) }