Follow topic btn (#291)

* Follow topic btn
This commit is contained in:
Ilya Y 2023-11-01 19:10:19 +03:00 committed by GitHub
parent 1e0e31cf09
commit 73d8d1ef27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 23 deletions

View File

@ -15,16 +15,22 @@
.topicActions { .topicActions {
margin-top: 2.8rem; margin-top: 2.8rem;
button, .write {
a { display: inline-flex;
background: #000; align-items: center;
justify-content: center;
height: 40px;
min-width: 64px;
font-size: 17px;
padding: 8px 16px;
background: var(--background-color-invert);
color: var(--default-color-invert);
border: none; border: none;
font-weight: 500;
border-radius: 2px; border-radius: 2px;
color: #fff;
cursor: pointer; cursor: pointer;
font-size: 100%;
margin: 0 1.2rem 1em; margin: 0 1.2rem 1em;
padding: 0.8rem 1.6rem;
white-space: nowrap; white-space: nowrap;
} }
} }

View File

@ -7,6 +7,7 @@ import { follow, unfollow } from '../../stores/zine/common'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { useSession } from '../../context/session' import { useSession } from '../../context/session'
import { useLocalize } from '../../context/localize' import { useLocalize } from '../../context/localize'
import { Button } from '../_shared/Button'
type Props = { type Props = {
topic: Topic topic: Topic
@ -15,7 +16,7 @@ type Props = {
export const FullTopic = (props: Props) => { export const FullTopic = (props: Props) => {
const { const {
subscriptions, subscriptions,
actions: { requireAuthentication } actions: { requireAuthentication, loadSubscriptions }
} = useSession() } = useSession()
const { t } = useLocalize() const { t } = useLocalize()
@ -24,13 +25,12 @@ export const FullTopic = (props: Props) => {
subscriptions().topics.some((topic) => topic.slug === props.topic?.slug) subscriptions().topics.some((topic) => topic.slug === props.topic?.slug)
) )
const handleSubscribe = (isFollowed: boolean) => { const handleSubscribe = (really: boolean) => {
requireAuthentication(() => { requireAuthentication(async () => {
if (isFollowed) { await (really
unfollow({ what: FollowingEntity.Topic, slug: props.topic.slug }) ? follow({ what: FollowingEntity.Topic, slug: props.topic.slug })
} else { : unfollow({ what: FollowingEntity.Topic, slug: props.topic.slug }))
follow({ what: FollowingEntity.Topic, slug: props.topic.slug }) loadSubscriptions()
}
}, 'follow') }, 'follow')
} }
@ -40,16 +40,18 @@ export const FullTopic = (props: Props) => {
<p>{props.topic.body}</p> <p>{props.topic.body}</p>
<div class={clsx(styles.topicActions)}> <div class={clsx(styles.topicActions)}>
<Show when={!subscribed()}> <Show when={!subscribed()}>
<button onClick={() => handleSubscribe(false)} class="button"> <Button variant="primary" onClick={() => handleSubscribe(true)} value={t('Follow the topic')} />
{t('Follow the topic')}
</button>
</Show> </Show>
<Show when={subscribed()}> <Show when={subscribed()}>
<button onClick={() => handleSubscribe(true)} class="button"> <Button
{t('Unfollow the topic')} variant="primary"
</button> onClick={() => handleSubscribe(false)}
value={t('Unfollow the topic')}
/>
</Show> </Show>
<a href={`/create/?topicId=${props.topic.id}`}>{t('Write about the topic')}</a> <a class={styles.write} href={`/create/?topicId=${props.topic.id}`}>
{t('Write about the topic')}
</a>
</div> </div>
<Show when={props.topic.pic}> <Show when={props.topic.pic}>
<img src={props.topic.pic} alt={props.topic.title} /> <img src={props.topic.pic} alt={props.topic.title} />

View File

@ -8,8 +8,8 @@
white-space: nowrap; white-space: nowrap;
&.primary { &.primary {
background: #000; background: var(--background-color-invert);
color: #fff; color: var(--default-color-invert);
&:hover { &:hover {
color: #ccc; color: #ccc;