import { clsx } from 'clsx' import { Show, createEffect, createMemo, createSignal, on } from 'solid-js' import { useFollowing } from '../../context/following' import { useLocalize } from '../../context/localize' import { useSession } from '../../context/session' import { FollowingEntity, type Topic } from '../../graphql/schema/core.gen' import { capitalize } from '../../utils/capitalize' import { CardTopic } from '../Feed/CardTopic' import { CheckButton } from '../_shared/CheckButton' import { FollowingButton } from '../_shared/FollowingButton' import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient' import styles from './Card.module.scss' interface TopicProps { topic: Topic compact?: boolean followed?: boolean shortDescription?: boolean subscribeButtonBottom?: boolean additionalClass?: string isTopicInRow?: boolean iconButton?: boolean showPublications?: boolean showDescription?: boolean isCardMode?: boolean minimize?: boolean isNarrow?: boolean withIcon?: boolean } export const TopicCard = (props: TopicProps) => { const { t, lang } = useLocalize() const title = createMemo(() => capitalize(lang() === 'en' ? props.topic.slug.replaceAll('-', ' ') : props.topic.title || ''), ) const { author, requireAuthentication } = useSession() const { follow, unfollow, follows } = useFollowing() const [isFollowed, setIsFollowed] = createSignal(false) createEffect( on([() => follows, () => props.topic], ([flws, tpc]) => { if (flws && tpc) { const followed = follows?.topics?.some((topics) => topics.id === props.topic?.id) setIsFollowed(followed) } }), ) const handleFollowClick = () => { requireAuthentication(() => { isFollowed() ? unfollow(FollowingEntity.Topic, props.topic.slug) : follow(FollowingEntity.Topic, props.topic.slug) }, 'follow') } return (

{title()}

{props.topic.body}
} >
) }