2022-09-09 11:53:35 +00:00
|
|
|
|
import { capitalize, plural } from '../../utils'
|
|
|
|
|
import { Show } from 'solid-js/web'
|
|
|
|
|
import './Card.scss'
|
|
|
|
|
import { createMemo } from 'solid-js'
|
|
|
|
|
import type { Topic } from '../../graphql/types.gen'
|
2022-09-13 09:59:04 +00:00
|
|
|
|
import { FollowingEntity } from '../../graphql/types.gen'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
import { t } from '../../utils/intl'
|
2022-09-23 23:42:19 +00:00
|
|
|
|
import { locale } from '../../stores/ui'
|
2022-09-30 14:22:33 +00:00
|
|
|
|
import { useAuthStore } from '../../stores/auth'
|
2022-09-13 09:59:04 +00:00
|
|
|
|
import { follow, unfollow } from '../../stores/zine/common'
|
2022-09-30 14:22:33 +00:00
|
|
|
|
import { getLogger } from '../../utils/logger'
|
|
|
|
|
|
|
|
|
|
const log = getLogger('TopicCard')
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
|
|
interface TopicProps {
|
|
|
|
|
topic: Topic
|
|
|
|
|
compact?: boolean
|
|
|
|
|
subscribed?: boolean
|
|
|
|
|
shortDescription?: boolean
|
|
|
|
|
subscribeButtonBottom?: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const TopicCard = (props: TopicProps) => {
|
2022-09-30 14:22:33 +00:00
|
|
|
|
const { session } = useAuthStore()
|
|
|
|
|
|
2022-09-13 09:59:04 +00:00
|
|
|
|
const subscribed = createMemo(() => {
|
2022-09-30 14:22:33 +00:00
|
|
|
|
if (!session()?.user?.slug || !session()?.info?.topics) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return props.topic.slug in session().info.topics
|
2022-09-13 09:59:04 +00:00
|
|
|
|
})
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
|
|
// FIXME use store actions
|
2022-09-13 09:59:04 +00:00
|
|
|
|
const subscribe = async (really = true) => {
|
|
|
|
|
if (really) {
|
2022-09-30 14:22:33 +00:00
|
|
|
|
follow({ what: FollowingEntity.Topic, slug: props.topic.slug })
|
2022-09-13 09:59:04 +00:00
|
|
|
|
} else {
|
2022-09-30 14:22:33 +00:00
|
|
|
|
unfollow({ what: FollowingEntity.Topic, slug: props.topic.slug })
|
2022-09-13 09:59:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
return (
|
|
|
|
|
<div class="topic" classList={{ row: !props.compact && !props.subscribeButtonBottom }}>
|
|
|
|
|
<div classList={{ 'col-md-7': !props.compact && !props.subscribeButtonBottom }}>
|
2022-09-30 14:22:33 +00:00
|
|
|
|
<Show when={props.topic.title}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<div class="topic-title">
|
2022-09-30 14:22:33 +00:00
|
|
|
|
<a href={`/topic/${props.topic.slug}`}>{capitalize(props.topic.title || '')}</a>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
2022-09-30 14:22:33 +00:00
|
|
|
|
<Show when={props.topic.pic}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<div class="topic__avatar">
|
2022-09-30 14:22:33 +00:00
|
|
|
|
<a href={props.topic.slug}>
|
|
|
|
|
<img src={props.topic.pic} alt={props.topic.title} />
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
|
2022-09-30 14:22:33 +00:00
|
|
|
|
<Show when={!props.compact && props.topic?.body}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<div class="topic-description" classList={{ 'topic-description--short': props.shortDescription }}>
|
2022-09-30 14:22:33 +00:00
|
|
|
|
{props.topic.body}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
|
2022-09-30 14:22:33 +00:00
|
|
|
|
<Show when={props.topic?.stat}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<div class="topic-details">
|
|
|
|
|
<Show when={!props.compact}>
|
|
|
|
|
<span class="topic-details__item" classList={{ compact: props.compact }}>
|
2022-09-30 14:22:33 +00:00
|
|
|
|
{props.topic.stat?.shouts +
|
2022-09-09 11:53:35 +00:00
|
|
|
|
' ' +
|
|
|
|
|
t('post') +
|
2022-09-30 14:22:33 +00:00
|
|
|
|
plural(
|
|
|
|
|
props.topic.stat?.shouts || 0,
|
|
|
|
|
locale() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's']
|
|
|
|
|
)}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</span>
|
|
|
|
|
<span class="topic-details__item" classList={{ compact: props.compact }}>
|
2022-09-30 14:22:33 +00:00
|
|
|
|
{props.topic.stat?.authors +
|
2022-09-09 11:53:35 +00:00
|
|
|
|
' ' +
|
|
|
|
|
t('author') +
|
2022-09-30 14:22:33 +00:00
|
|
|
|
plural(
|
|
|
|
|
props.topic.stat?.authors || 0,
|
|
|
|
|
locale() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's']
|
|
|
|
|
)}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</span>
|
2022-09-20 08:26:12 +00:00
|
|
|
|
<span class="topic-details__item" classList={{ compact: props.compact }}>
|
2022-09-30 14:22:33 +00:00
|
|
|
|
{props.topic.stat?.followers +
|
2022-09-20 08:26:12 +00:00
|
|
|
|
' ' +
|
|
|
|
|
t('follower') +
|
|
|
|
|
plural(
|
2022-09-30 14:22:33 +00:00
|
|
|
|
props.topic.stat?.followers || 0,
|
2022-09-20 08:26:12 +00:00
|
|
|
|
locale() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's']
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{/*FIXME*/}
|
|
|
|
|
{/*<Show when={false && !props.subscribeButtonBottom}>*/}
|
|
|
|
|
{/* <span class='topic-details__item'>*/}
|
|
|
|
|
{/* {topic().stat?.viewed +*/}
|
|
|
|
|
{/* ' ' +*/}
|
|
|
|
|
{/* t('view') +*/}
|
|
|
|
|
{/* plural(*/}
|
|
|
|
|
{/* topic().stat?.viewed || 0,*/}
|
|
|
|
|
{/* locale() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's']*/}
|
|
|
|
|
{/* )}*/}
|
|
|
|
|
{/* </span>*/}
|
|
|
|
|
{/*</Show>*/}
|
|
|
|
|
</Show>
|
|
|
|
|
|
|
|
|
|
{/*
|
|
|
|
|
<span class='topic-details__item'>
|
|
|
|
|
{subscribers().toString() + ' ' + t('follower') + plural(
|
|
|
|
|
subscribers(),
|
|
|
|
|
locale() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's']
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
*/}
|
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
</div>
|
|
|
|
|
<div classList={{ 'col-md-3': !props.compact && !props.subscribeButtonBottom }}>
|
2022-09-13 09:59:04 +00:00
|
|
|
|
<Show
|
|
|
|
|
when={subscribed()}
|
|
|
|
|
fallback={
|
|
|
|
|
<button onClick={() => subscribe(true)} class="button--light">
|
|
|
|
|
+ {t('Follow')}
|
|
|
|
|
</button>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<button onClick={() => subscribe(false)} class="button--light">
|
|
|
|
|
- {t('Unfollow')}
|
|
|
|
|
</button>
|
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|