webapp/src/components/Topic/Full.tsx

51 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-10-31 16:40:55 +00:00
import { createMemo, Show } from 'solid-js'
2022-09-09 11:53:35 +00:00
import type { Topic } from '../../graphql/types.gen'
import { FollowingEntity } from '../../graphql/types.gen'
2022-11-07 21:07:42 +00:00
import styles from './Full.module.scss'
2022-09-09 11:53:35 +00:00
import { follow, unfollow } from '../../stores/zine/common'
import { t } from '../../utils/intl'
2022-11-07 21:07:42 +00:00
import { clsx } from 'clsx'
2022-11-14 10:02:08 +00:00
import { useSession } from '../../context/session'
2022-09-09 11:53:35 +00:00
type Props = {
topic: Topic
}
export const FullTopic = (props: Props) => {
2022-11-14 10:02:08 +00:00
const { session } = useSession()
2022-09-30 14:22:33 +00:00
2022-10-04 12:16:07 +00:00
const subscribed = createMemo(() => session()?.news?.topics?.includes(props.topic?.slug))
2022-09-09 11:53:35 +00:00
return (
2022-11-07 21:07:42 +00:00
<div class={styles.topicFull}>
<Show when={!!props.topic?.slug}>
<div class={clsx(styles.topicHeader, 'col-md-8 offset-md-2')}>
<h1>#{props.topic.title}</h1>
<p>{props.topic.body}</p>
<div class={clsx(styles.topicActions)}>
<Show when={!subscribed()}>
<button
onClick={() => follow({ what: FollowingEntity.Topic, slug: props.topic.slug })}
class="button"
>
{t('Follow the topic')}
</button>
2022-09-09 11:53:35 +00:00
</Show>
2022-11-07 21:07:42 +00:00
<Show when={subscribed()}>
<button
onClick={() => unfollow({ what: FollowingEntity.Topic, slug: props.topic.slug })}
class="button"
>
{t('Unfollow the topic')}
</button>
</Show>
<a href={`/create/${props.topic.slug}`}>{t('Write about the topic')}</a>
2022-09-09 11:53:35 +00:00
</div>
2022-11-07 21:07:42 +00:00
<Show when={props.topic.pic}>
<img src={props.topic.pic} alt={props.topic.title} />
</Show>
</div>
</Show>
2022-09-09 11:53:35 +00:00
</div>
)
}