import type { Author, Topic } from '~/graphql/schema/core.gen' import { clsx } from 'clsx' import { Show, createEffect, createMemo, createSignal } from 'solid-js' import { useFollowing } from '~/context/following' import { useLocalize } from '~/context/localize' import { useSession } from '~/context/session' import { FollowingEntity } from '~/graphql/schema/core.gen' import { Button } from '../_shared/Button' import { capitalize } from '~/utils/capitalize' import { FollowingCounters } from '../_shared/FollowingCounters/FollowingCounters' import { Icon } from '../_shared/Icon' import styles from './Full.module.scss' type Props = { topic: Topic followers?: Author[] authors?: Author[] } export const FullTopic = (props: Props) => { const { t, lang } = useLocalize() const { follows, changeFollowing } = useFollowing() const { requireAuthentication } = useSession() const [followed, setFollowed] = createSignal() const title = createMemo( () => // FIXME: use title translation `#${capitalize( lang() === 'en' ? props.topic.slug.replace(/-/, ' ') : props.topic.title || props.topic.slug.replace(/-/, ' '), true )}` ) createEffect(() => { if (follows?.topics?.length !== 0) { const items = follows.topics || [] setFollowed(items.some((x: Topic) => x?.slug === props.topic?.slug)) } }) const handleFollowClick = (_ev?: MouseEvent | undefined) => { const really = !followed() setFollowed(really) requireAuthentication(() => { changeFollowing(FollowingEntity.Topic, props.topic.slug, really) }, 'follow') } return (
) }