2022-09-09 11:53:35 +00:00
|
|
|
import type { Author } from '../../graphql/types.gen'
|
|
|
|
import Userpic from './Userpic'
|
2022-11-14 17:41:05 +00:00
|
|
|
import { Icon } from '../_shared/Icon'
|
2022-11-11 08:58:22 +00:00
|
|
|
import styles from './Card.module.scss'
|
2022-12-01 18:45:35 +00:00
|
|
|
import { createMemo, createSignal, For, Show } from 'solid-js'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { translit } from '../../utils/ru2en'
|
|
|
|
import { t } from '../../utils/intl'
|
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-11-14 10:02:08 +00:00
|
|
|
import { useSession } from '../../context/session'
|
2022-11-30 21:50:33 +00:00
|
|
|
import { StatMetrics } from '../_shared/StatMetrics'
|
2022-12-01 18:45:35 +00:00
|
|
|
import { FollowingEntity } from '../../graphql/types.gen'
|
|
|
|
import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
interface AuthorCardProps {
|
2022-11-19 05:00:54 +00:00
|
|
|
caption?: string
|
2022-09-09 11:53:35 +00:00
|
|
|
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-11-11 08:58:22 +00:00
|
|
|
isAuthorsList?: boolean
|
2022-11-16 21:08:04 +00:00
|
|
|
truncateBio?: boolean
|
2022-11-23 19:14:59 +00:00
|
|
|
liteButtons?: boolean
|
2022-11-26 21:27:54 +00:00
|
|
|
isComments?: boolean
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const AuthorCard = (props: AuthorCardProps) => {
|
2022-12-01 18:45:35 +00:00
|
|
|
const {
|
|
|
|
session,
|
|
|
|
actions: { loadSession }
|
|
|
|
} = useSession()
|
|
|
|
|
|
|
|
const [isSubscribing, setIsSubscribing] = createSignal(false)
|
2022-09-30 14:22:33 +00:00
|
|
|
|
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-12-01 18:45:35 +00:00
|
|
|
|
|
|
|
const subscribe = async (really = true) => {
|
|
|
|
setIsSubscribing(true)
|
|
|
|
|
|
|
|
await (really
|
|
|
|
? follow({ what: FollowingEntity.Author, slug: props.author.slug })
|
|
|
|
: unfollow({ what: FollowingEntity.Author, slug: props.author.slug }))
|
|
|
|
|
|
|
|
await loadSession()
|
|
|
|
setIsSubscribing(false)
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:22:33 +00:00
|
|
|
const canFollow = createMemo(() => !props.hideFollow && session()?.user?.slug !== props.author.slug)
|
2022-11-21 00:12:20 +00:00
|
|
|
|
2022-09-23 23:42:19 +00:00
|
|
|
const name = () => {
|
2022-12-01 18:45:35 +00:00
|
|
|
return props.author.name === 'Дискурс' && locale() !== 'ru' ? 'Discours' : translit(props.author.name)
|
2022-09-23 23:42:19 +00:00
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
// TODO: reimplement AuthorCard
|
|
|
|
return (
|
2022-11-11 08:58:22 +00:00
|
|
|
<div
|
|
|
|
class={clsx(styles.author)}
|
|
|
|
classList={{
|
|
|
|
[styles.authorPage]: props.isAuthorPage,
|
2022-11-26 21:27:54 +00:00
|
|
|
[styles.authorComments]: props.isComments,
|
2022-11-11 08:58:22 +00:00
|
|
|
[styles.authorsListItem]: props.isAuthorsList
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Userpic
|
|
|
|
user={props.author}
|
|
|
|
hasLink={props.hasLink}
|
|
|
|
isBig={props.isAuthorPage}
|
|
|
|
isAuthorsList={props.isAuthorsList}
|
2022-11-26 21:27:54 +00:00
|
|
|
class={styles.circlewrap}
|
2022-11-11 08:58:22 +00:00
|
|
|
/>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-11-11 08:58:22 +00:00
|
|
|
<div class={styles.authorDetails}>
|
|
|
|
<div class={styles.authorDetailsWrapper}>
|
2022-10-04 12:42:11 +00:00
|
|
|
<Show when={props.hasLink}>
|
2022-11-11 08:58:22 +00:00
|
|
|
<a class={styles.authorName} href={`/author/${props.author.slug}`}>
|
2022-10-04 12:42:11 +00:00
|
|
|
{name()}
|
|
|
|
</a>
|
|
|
|
</Show>
|
|
|
|
<Show when={!props.hasLink}>
|
2022-11-11 08:58:22 +00:00
|
|
|
<div class={styles.authorName}>{name()}</div>
|
2022-10-04 12:42:11 +00:00
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-11-30 21:50:33 +00:00
|
|
|
<Show when={!props.hideDescription && props.author.bio}>
|
2022-11-16 21:08:04 +00:00
|
|
|
{props.isAuthorsList}
|
2022-11-22 09:27:01 +00:00
|
|
|
<div
|
|
|
|
class={styles.authorAbout}
|
|
|
|
classList={{ 'text-truncate': props.truncateBio }}
|
2022-11-27 17:02:04 +00:00
|
|
|
innerHTML={props.author.bio}
|
2022-12-01 18:45:35 +00:00
|
|
|
/>
|
2022-10-04 12:42:11 +00:00
|
|
|
</Show>
|
2022-11-30 21:50:33 +00:00
|
|
|
|
|
|
|
<Show when={props.author.stat}>
|
|
|
|
<StatMetrics fields={['shouts', 'followers', 'comments']} stat={props.author.stat} />
|
|
|
|
</Show>
|
2022-10-04 12:42:11 +00:00
|
|
|
</div>
|
2022-12-01 18:45:35 +00:00
|
|
|
<ShowOnlyOnClient>
|
|
|
|
<Show when={session.state !== 'pending'}>
|
|
|
|
<Show when={canFollow()}>
|
|
|
|
<div class={styles.authorSubscribe}>
|
|
|
|
<Show
|
|
|
|
when={subscribed()}
|
|
|
|
fallback={
|
|
|
|
<button
|
|
|
|
onClick={() => subscribe(true)}
|
|
|
|
class={clsx('button', styles.button)}
|
|
|
|
classList={{
|
|
|
|
[styles.buttonSubscribe]: !props.isAuthorsList,
|
|
|
|
'button--subscribe': !props.isAuthorsList,
|
|
|
|
'button--subscribe-topic': props.isAuthorsList,
|
|
|
|
[styles.buttonWrite]: props.isAuthorsList,
|
|
|
|
[styles.isSubscribing]: isSubscribing()
|
|
|
|
}}
|
|
|
|
disabled={isSubscribing()}
|
|
|
|
>
|
|
|
|
<Show when={!props.isAuthorsList}>
|
|
|
|
<Icon name="circle-plus" iconClassName={styles.s24} class={styles.icon} />
|
|
|
|
</Show>
|
|
|
|
<span class={styles.buttonLabel}>{t('Follow')}</span>
|
|
|
|
</button>
|
|
|
|
}
|
2022-10-14 18:33:06 +00:00
|
|
|
>
|
2022-12-01 18:45:35 +00:00
|
|
|
<button
|
|
|
|
onClick={() => subscribe(false)}
|
|
|
|
class={clsx('button', styles.button)}
|
|
|
|
classList={{
|
|
|
|
[styles.buttonSubscribe]: !props.isAuthorsList,
|
|
|
|
'button--subscribe': !props.isAuthorsList,
|
|
|
|
'button--subscribe-topic': props.isAuthorsList,
|
|
|
|
[styles.buttonWrite]: props.isAuthorsList,
|
|
|
|
[styles.isSubscribing]: isSubscribing()
|
|
|
|
}}
|
|
|
|
disabled={isSubscribing()}
|
|
|
|
>
|
|
|
|
<Show when={!props.isAuthorsList}>
|
|
|
|
<Icon name="author-unsubscribe" class={styles.icon} />
|
|
|
|
</Show>
|
|
|
|
<span class={styles.buttonLabel}>{t('Unfollow')}</span>
|
|
|
|
</button>
|
2022-11-11 08:58:22 +00:00
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
<Show when={!props.compact && !props.isAuthorsList}>
|
|
|
|
<button
|
|
|
|
class={styles.button}
|
|
|
|
classList={{
|
|
|
|
[styles.buttonSubscribe]: !props.isAuthorsList,
|
|
|
|
'button--subscribe': !props.isAuthorsList,
|
|
|
|
'button--subscribe-topic': props.isAuthorsList,
|
|
|
|
[styles.buttonWrite]: props.liteButtons && props.isAuthorsList
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon name="comment" class={styles.icon} />
|
|
|
|
<Show when={!props.liteButtons}>{t('Write')}</Show>
|
|
|
|
</button>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
<Show when={!props.noSocialButtons}>
|
|
|
|
<For each={props.author.links}>{(link) => <a href={link} />}</For>
|
|
|
|
</Show>
|
|
|
|
</Show>
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
</Show>
|
2022-12-01 18:45:35 +00:00
|
|
|
</Show>
|
|
|
|
</ShowOnlyOnClient>
|
2022-10-04 12:42:11 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
)
|
|
|
|
}
|