2023-11-28 13:18:25 +00:00
|
|
|
import type { Topic } from '../../graphql/schema/core.gen'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2022-11-07 21:07:42 +00:00
|
|
|
import { clsx } from 'clsx'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { createMemo, Show } from 'solid-js'
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useLocalize } from '../../context/localize'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { useSession } from '../../context/session'
|
2023-11-28 13:18:25 +00:00
|
|
|
import { FollowingEntity } from '../../graphql/schema/core.gen'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { follow, unfollow } from '../../stores/zine/common'
|
2023-11-01 16:10:19 +00:00
|
|
|
import { Button } from '../_shared/Button'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-11-14 15:10:00 +00:00
|
|
|
import styles from './Full.module.scss'
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
type Props = {
|
|
|
|
topic: Topic
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FullTopic = (props: Props) => {
|
2023-06-14 17:19:30 +00:00
|
|
|
const {
|
2023-10-19 15:05:22 +00:00
|
|
|
subscriptions,
|
2023-11-14 15:10:00 +00:00
|
|
|
actions: { requireAuthentication, loadSubscriptions },
|
2023-06-14 17:19:30 +00:00
|
|
|
} = useSession()
|
2023-10-19 15:05:22 +00:00
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t } = useLocalize()
|
2023-10-19 15:05:22 +00:00
|
|
|
|
|
|
|
const subscribed = createMemo(() =>
|
2023-11-14 15:10:00 +00:00
|
|
|
subscriptions().topics.some((topic) => topic.slug === props.topic?.slug),
|
2023-10-19 15:05:22 +00:00
|
|
|
)
|
2023-06-14 17:19:30 +00:00
|
|
|
|
2023-11-01 16:10:19 +00:00
|
|
|
const handleSubscribe = (really: boolean) => {
|
|
|
|
requireAuthentication(async () => {
|
|
|
|
await (really
|
|
|
|
? follow({ what: FollowingEntity.Topic, slug: props.topic.slug })
|
|
|
|
: unfollow({ what: FollowingEntity.Topic, slug: props.topic.slug }))
|
|
|
|
loadSubscriptions()
|
2023-06-14 17:19:30 +00:00
|
|
|
}, 'follow')
|
|
|
|
}
|
|
|
|
|
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-12-27 22:50:42 +00:00
|
|
|
<h1>#{props.topic?.title}</h1>
|
|
|
|
<p>{props.topic?.body}</p>
|
2023-02-17 09:21:02 +00:00
|
|
|
<div class={clsx(styles.topicActions)}>
|
|
|
|
<Show when={!subscribed()}>
|
2023-11-01 16:10:19 +00:00
|
|
|
<Button variant="primary" onClick={() => handleSubscribe(true)} value={t('Follow the topic')} />
|
2023-02-17 09:21:02 +00:00
|
|
|
</Show>
|
|
|
|
<Show when={subscribed()}>
|
2023-11-01 16:10:19 +00:00
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
onClick={() => handleSubscribe(false)}
|
|
|
|
value={t('Unfollow the topic')}
|
|
|
|
/>
|
2023-02-17 09:21:02 +00:00
|
|
|
</Show>
|
2023-12-27 22:50:42 +00:00
|
|
|
<a class={styles.write} href={`/create/?topicId=${props.topic?.id}`}>
|
2023-11-01 16:10:19 +00:00
|
|
|
{t('Write about the topic')}
|
|
|
|
</a>
|
2023-02-17 09:21:02 +00:00
|
|
|
</div>
|
2023-12-27 22:50:42 +00:00
|
|
|
<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>
|
|
|
|
)
|
|
|
|
}
|