webapp/src/components/Author/Card.tsx

98 lines
3.3 KiB
TypeScript
Raw Normal View History

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'
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'
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
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 (
<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
<div class={style.authorDetails}>
<div class={style.authorDetailsWrapper}>
2022-10-04 12:42:11 +00:00
<Show when={props.hasLink}>
<a class={style.authorName} href={`/author/${props.author.slug}`}>
2022-10-04 12:42:11 +00:00
{name()}
</a>
</Show>
<Show when={!props.hasLink}>
<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}>
<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()}>
<div class={style.authorSubscribe}>
2022-10-04 12:42:11 +00:00
<Show
when={subscribed()}
fallback={
<button
onClick={() => follow}
class={clsx('button button--subscribe', style.button, style.buttonSubscribe)}
>
<Icon name="author-subscribe" class={style.icon} />
<span class={style.buttonLabel}>&nbsp;{t('Follow')}</span>
2022-10-04 12:42:11 +00:00
</button>
}
>
<button
onClick={() => unfollow}
class={clsx('button button--subscribe', style.button, style.buttonSubscribe)}
>
<Icon name="author-unsubscribe" class={style.icon} />
<span class={style.buttonLabel}>-&nbsp;{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}>
<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
)
}