2022-09-09 11:53:35 +00:00
|
|
|
import { For, Show } from 'solid-js/web'
|
|
|
|
import type { Author } from '../../graphql/types.gen'
|
|
|
|
import Userpic from './Userpic'
|
2022-09-22 09:37:49 +00:00
|
|
|
import { Icon } from '../Nav/Icon'
|
2022-10-14 18:33:06 +00:00
|
|
|
import style from './Card.module.scss'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { createMemo } from 'solid-js'
|
|
|
|
import { translit } from '../../utils/ru2en'
|
|
|
|
import { t } from '../../utils/intl'
|
2022-09-30 14:22:33 +00:00
|
|
|
import { useAuthStore } from '../../stores/auth'
|
2022-09-23 23:42:19 +00:00
|
|
|
import { locale } from '../../stores/ui'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { follow, unfollow } from '../../stores/zine/common'
|
2022-10-14 18:33:06 +00:00
|
|
|
import { clsx } from 'clsx'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
interface AuthorCardProps {
|
|
|
|
compact?: boolean
|
|
|
|
hideDescription?: boolean
|
|
|
|
hideFollow?: boolean
|
|
|
|
hasLink?: boolean
|
|
|
|
subscribed?: boolean
|
|
|
|
author: Author
|
2022-10-14 18:33:06 +00:00
|
|
|
isAuthorPage?: boolean
|
2022-10-19 21:40:50 +00:00
|
|
|
noSocialButtons?: boolean
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const AuthorCard = (props: AuthorCardProps) => {
|
2022-09-30 14:22:33 +00:00
|
|
|
const { session } = useAuthStore()
|
|
|
|
|
2022-10-04 12:42:11 +00:00
|
|
|
const subscribed = createMemo<boolean>(
|
|
|
|
() => session()?.news?.authors?.some((u) => u === props.author.slug) || false
|
2022-09-09 11:53:35 +00:00
|
|
|
)
|
2022-09-30 14:22:33 +00:00
|
|
|
const canFollow = createMemo(() => !props.hideFollow && session()?.user?.slug !== props.author.slug)
|
2022-09-23 23:42:19 +00:00
|
|
|
const bio = () => props.author.bio || t('Our regular contributor')
|
|
|
|
const name = () => {
|
2022-09-09 11:53:35 +00:00
|
|
|
return props.author.name === 'Дискурс' && locale() !== 'ru'
|
|
|
|
? 'Discours'
|
|
|
|
: translit(props.author.name || '', locale() || 'ru')
|
2022-09-23 23:42:19 +00:00
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
// TODO: reimplement AuthorCard
|
|
|
|
return (
|
2022-10-14 18:33:06 +00:00
|
|
|
<div class={style.author} classList={{ [style.authorPage]: props.isAuthorPage }}>
|
|
|
|
<Userpic user={props.author} hasLink={props.hasLink} isBig={props.isAuthorPage} />
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-10-14 18:33:06 +00:00
|
|
|
<div class={style.authorDetails}>
|
|
|
|
<div class={style.authorDetailsWrapper}>
|
2022-10-04 12:42:11 +00:00
|
|
|
<Show when={props.hasLink}>
|
2022-10-14 18:33:06 +00:00
|
|
|
<a class={style.authorName} href={`/author/${props.author.slug}`}>
|
2022-10-04 12:42:11 +00:00
|
|
|
{name()}
|
|
|
|
</a>
|
|
|
|
</Show>
|
|
|
|
<Show when={!props.hasLink}>
|
2022-10-14 18:33:06 +00:00
|
|
|
<div class={style.authorName}>{name()}</div>
|
2022-10-04 12:42:11 +00:00
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-10-04 12:42:11 +00:00
|
|
|
<Show when={!props.hideDescription}>
|
2022-10-14 18:33:06 +00:00
|
|
|
<div class={style.authorAbout}>{bio()}</div>
|
2022-10-04 12:42:11 +00:00
|
|
|
</Show>
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-10-04 12:42:11 +00:00
|
|
|
<Show when={canFollow()}>
|
2022-10-14 18:33:06 +00:00
|
|
|
<div class={style.authorSubscribe}>
|
2022-10-04 12:42:11 +00:00
|
|
|
<Show
|
|
|
|
when={subscribed()}
|
|
|
|
fallback={
|
2022-10-14 18:33:06 +00:00
|
|
|
<button
|
|
|
|
onClick={() => follow}
|
|
|
|
class={clsx('button button--subscribe', style.button, style.buttonSubscribe)}
|
|
|
|
>
|
|
|
|
<Icon name="author-subscribe" class={style.icon} />
|
|
|
|
<span class={style.buttonLabel}> {t('Follow')}</span>
|
2022-10-04 12:42:11 +00:00
|
|
|
</button>
|
|
|
|
}
|
|
|
|
>
|
2022-10-14 18:33:06 +00:00
|
|
|
<button
|
|
|
|
onClick={() => unfollow}
|
|
|
|
class={clsx('button button--subscribe', style.button, style.buttonSubscribe)}
|
|
|
|
>
|
|
|
|
<Icon name="author-unsubscribe" class={style.icon} />
|
|
|
|
<span class={style.buttonLabel}>- {t('Unfollow')}</span>
|
2022-10-04 12:42:11 +00:00
|
|
|
</button>
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-10-04 12:42:11 +00:00
|
|
|
<Show when={!props.compact}>
|
2022-10-14 18:33:06 +00:00
|
|
|
<button class={clsx(style.buttonWrite, style.button, 'button')}>
|
|
|
|
<Icon name="edit" class={style.icon} />
|
2022-10-04 12:42:11 +00:00
|
|
|
{t('Write')}
|
|
|
|
</button>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-10-19 21:40:50 +00:00
|
|
|
<Show when={!props.noSocialButtons}>
|
|
|
|
<For each={props.author.links}>{(link) => <a href={link} />}</For>
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
</Show>
|
|
|
|
</div>
|
2022-10-04 12:42:11 +00:00
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
)
|
|
|
|
}
|