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'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
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'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useLocalize } from '../../context/localize'
|
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()
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t } = useLocalize()
|
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 (
|
2023-03-10 17:42:48 +00:00
|
|
|
<div class={clsx(styles.topicHeader, 'col-md-16 col-lg-12 offset-md-4 offset-lg-6')}>
|
2023-02-17 09:21:02 +00:00
|
|
|
<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>
|
|
|
|
</Show>
|
|
|
|
<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>
|
|
|
|
</div>
|
|
|
|
<Show when={props.topic.pic}>
|
|
|
|
<img src={props.topic.pic} alt={props.topic.title} />
|
2022-11-07 21:07:42 +00:00
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|