cleanup code
This commit is contained in:
parent
00a0436835
commit
dd4065036f
|
@ -1,5 +1,5 @@
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { Show, createMemo, createSignal } from 'solid-js'
|
import { Show, createEffect, createMemo, createSignal } from 'solid-js'
|
||||||
|
|
||||||
import { useFollowing } from '../../context/following'
|
import { useFollowing } from '../../context/following'
|
||||||
import { useLocalize } from '../../context/localize'
|
import { useLocalize } from '../../context/localize'
|
||||||
|
@ -38,14 +38,18 @@ export const TopicCard = (props: TopicProps) => {
|
||||||
capitalize(lang() === 'en' ? props.topic.slug.replaceAll('-', ' ') : props.topic.title || ''),
|
capitalize(lang() === 'en' ? props.topic.slug.replaceAll('-', ' ') : props.topic.title || ''),
|
||||||
)
|
)
|
||||||
const { author, requireAuthentication } = useSession()
|
const { author, requireAuthentication } = useSession()
|
||||||
const { setFollowing, loading: subLoading } = useFollowing()
|
const [isSubscribed, setIsSubscribed] = createSignal()
|
||||||
const [followed, setFollowed] = createSignal()
|
const { follow, unfollow, subscriptions, subscribeInAction } = useFollowing()
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (!subscriptions || !props.topic) return
|
||||||
|
const subscribed = subscriptions.topics?.some((topics) => topics.id === props.topic?.id)
|
||||||
|
setIsSubscribed(subscribed)
|
||||||
|
})
|
||||||
|
|
||||||
const handleFollowClick = () => {
|
const handleFollowClick = () => {
|
||||||
const value = !followed()
|
|
||||||
requireAuthentication(() => {
|
requireAuthentication(() => {
|
||||||
setFollowed(value)
|
follow(FollowingEntity.Topic, props.topic.slug)
|
||||||
setFollowing(FollowingEntity.Topic, props.topic.slug, value)
|
|
||||||
}, 'subscribe')
|
}, 'subscribe')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,12 +57,12 @@ export const TopicCard = (props: TopicProps) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Show when={props.iconButton}>
|
<Show when={props.iconButton}>
|
||||||
<Show when={followed()} fallback="+">
|
<Show when={isSubscribed()} fallback="+">
|
||||||
<Icon name="check-subscribed" />
|
<Icon name="check-subscribed" />
|
||||||
</Show>
|
</Show>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={!props.iconButton}>
|
<Show when={!props.iconButton}>
|
||||||
<Show when={followed()} fallback={t('Follow')}>
|
<Show when={isSubscribed()} fallback={t('Follow')}>
|
||||||
<span class={stylesButton.buttonSubscribeLabelHovered}>{t('Unfollow')}</span>
|
<span class={stylesButton.buttonSubscribeLabelHovered}>{t('Unfollow')}</span>
|
||||||
<span class={stylesButton.buttonSubscribeLabel}>{t('Following')}</span>
|
<span class={stylesButton.buttonSubscribeLabel}>{t('Following')}</span>
|
||||||
</Show>
|
</Show>
|
||||||
|
@ -130,7 +134,7 @@ export const TopicCard = (props: TopicProps) => {
|
||||||
fallback={
|
fallback={
|
||||||
<CheckButton
|
<CheckButton
|
||||||
text={t('Follow')}
|
text={t('Follow')}
|
||||||
checked={Boolean(followed())}
|
checked={Boolean(isSubscribed())}
|
||||||
onClick={handleFollowClick}
|
onClick={handleFollowClick}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
@ -142,10 +146,10 @@ export const TopicCard = (props: TopicProps) => {
|
||||||
onClick={handleFollowClick}
|
onClick={handleFollowClick}
|
||||||
isSubscribeButton={true}
|
isSubscribeButton={true}
|
||||||
class={clsx(styles.actionButton, {
|
class={clsx(styles.actionButton, {
|
||||||
[styles.isSubscribing]: subLoading(),
|
[styles.isSubscribing]:
|
||||||
[stylesButton.subscribed]: followed(),
|
subscribeInAction()?.slug === props.topic.slug ? subscribeInAction().type : undefined,
|
||||||
|
[stylesButton.subscribed]: isSubscribed(),
|
||||||
})}
|
})}
|
||||||
// disabled={subLoading()}
|
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
|
@ -9,8 +9,6 @@ import { FollowingEntity, Topic } from '../../../graphql/schema/core.gen'
|
||||||
import { capitalize } from '../../../utils/capitalize'
|
import { capitalize } from '../../../utils/capitalize'
|
||||||
import { getImageUrl } from '../../../utils/getImageUrl'
|
import { getImageUrl } from '../../../utils/getImageUrl'
|
||||||
import { BadgeSubscribeButton } from '../../_shared/BadgeSubscribeButton'
|
import { BadgeSubscribeButton } from '../../_shared/BadgeSubscribeButton'
|
||||||
import { Button } from '../../_shared/Button'
|
|
||||||
import { CheckButton } from '../../_shared/CheckButton'
|
|
||||||
import styles from './TopicBadge.module.scss'
|
import styles from './TopicBadge.module.scss'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -29,7 +27,7 @@ export const TopicBadge = (props: Props) => {
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (!subscriptions || !props.topic) return
|
if (!subscriptions || !props.topic) return
|
||||||
const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.topic?.id)
|
const subscribed = subscriptions.topics?.some((topics) => topics.id === props.topic?.id)
|
||||||
setIsSubscribed(subscribed)
|
setIsSubscribed(subscribed)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -186,10 +186,7 @@ export const AllTopics = (props: Props) => {
|
||||||
<For each={filteredResults().slice(0, limit())}>
|
<For each={filteredResults().slice(0, limit())}>
|
||||||
{(topic) => (
|
{(topic) => (
|
||||||
<>
|
<>
|
||||||
<TopicBadge
|
<TopicBadge topic={topic} showStat={true} />
|
||||||
topic={topic}
|
|
||||||
showStat={true}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user