2023-05-01 18:32:32 +00:00
|
|
|
import type { Author } from '../../graphql/types.gen'
|
2023-08-11 16:42:41 +00:00
|
|
|
import { Userpic } from './Userpic'
|
2022-11-14 17:41:05 +00:00
|
|
|
import { Icon } from '../_shared/Icon'
|
2023-05-01 18:32:32 +00:00
|
|
|
import styles from './AuthorCard.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 { 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 { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient'
|
2022-12-17 03:27:00 +00:00
|
|
|
import { FollowingEntity } from '../../graphql/types.gen'
|
|
|
|
import { router, useRouter } from '../../stores/router'
|
|
|
|
import { openPage } from '@nanostores/router'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useLocalize } from '../../context/localize'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
interface AuthorCardProps {
|
2022-11-19 05:00:54 +00:00
|
|
|
caption?: string
|
2023-03-23 21:39:13 +00:00
|
|
|
hideWriteButton?: boolean
|
2022-09-09 11:53:35 +00:00
|
|
|
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
|
2023-05-17 20:27:24 +00:00
|
|
|
isTextButton?: boolean
|
2022-11-26 21:27:54 +00:00
|
|
|
isComments?: boolean
|
2023-01-26 21:42:47 +00:00
|
|
|
isFeedMode?: boolean
|
2023-02-13 13:48:05 +00:00
|
|
|
isNowrap?: boolean
|
2023-06-02 22:01:34 +00:00
|
|
|
class?: string
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const AuthorCard = (props: AuthorCardProps) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t, lang } = useLocalize()
|
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
const {
|
|
|
|
session,
|
2022-12-06 16:03:55 +00:00
|
|
|
isSessionLoaded,
|
2023-06-14 17:19:30 +00:00
|
|
|
actions: { loadSession, requireAuthentication }
|
2022-12-01 18:45:35 +00:00
|
|
|
} = useSession()
|
|
|
|
|
|
|
|
const [isSubscribing, setIsSubscribing] = createSignal(false)
|
2022-09-30 14:22:33 +00:00
|
|
|
|
2023-01-20 04:40:55 +00:00
|
|
|
const subscribed = createMemo<boolean>(() => {
|
|
|
|
return session()?.news?.authors?.some((u) => u === props.author.slug) || false
|
|
|
|
})
|
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-12-07 20:11:32 +00:00
|
|
|
const name = createMemo(() => {
|
2023-02-17 09:21:02 +00:00
|
|
|
if (lang() !== 'ru') {
|
2022-12-07 20:11:32 +00:00
|
|
|
if (props.author.name === 'Дискурс') {
|
|
|
|
return 'Discours'
|
|
|
|
}
|
|
|
|
|
|
|
|
return translit(props.author.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return props.author.name
|
|
|
|
})
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
// TODO: reimplement AuthorCard
|
2022-12-17 03:27:00 +00:00
|
|
|
const { changeSearchParam } = useRouter()
|
|
|
|
const initChat = () => {
|
2023-06-14 17:19:30 +00:00
|
|
|
requireAuthentication(() => {
|
|
|
|
openPage(router, `inbox`)
|
|
|
|
changeSearchParam('initChat', `${props.author.id}`)
|
|
|
|
}, 'discussions')
|
2022-12-17 03:27:00 +00:00
|
|
|
}
|
2023-06-14 17:19:30 +00:00
|
|
|
|
|
|
|
const handleSubscribe = () => {
|
|
|
|
requireAuthentication(() => {
|
|
|
|
subscribe(true)
|
|
|
|
}, 'subscribe')
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
return (
|
2022-11-11 08:58:22 +00:00
|
|
|
<div
|
2023-06-02 22:01:34 +00:00
|
|
|
class={clsx(styles.author, props.class)}
|
2022-11-11 08:58:22 +00:00
|
|
|
classList={{
|
|
|
|
[styles.authorPage]: props.isAuthorPage,
|
2022-11-26 21:27:54 +00:00
|
|
|
[styles.authorComments]: props.isComments,
|
2023-01-26 21:42:47 +00:00
|
|
|
[styles.authorsListItem]: props.isAuthorsList,
|
2023-02-13 13:48:05 +00:00
|
|
|
[styles.feedMode]: props.isFeedMode,
|
|
|
|
[styles.nowrapView]: props.isNowrap
|
2022-11-11 08:58:22 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Userpic
|
2023-08-11 16:42:41 +00:00
|
|
|
name={props.author.name}
|
|
|
|
userpic={props.author.userpic}
|
2022-11-11 08:58:22 +00:00
|
|
|
hasLink={props.hasLink}
|
|
|
|
isBig={props.isAuthorPage}
|
|
|
|
isAuthorsList={props.isAuthorsList}
|
2023-06-21 20:32:16 +00:00
|
|
|
isFeedMode={props.isFeedMode}
|
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}>
|
2023-06-02 22:01:34 +00:00
|
|
|
<div class={styles.authorNameContainer}>
|
|
|
|
<a class={styles.authorName} href={`/author/${props.author.slug}`}>
|
|
|
|
{name()}
|
|
|
|
</a>
|
|
|
|
</div>
|
2022-10-04 12:42:11 +00:00
|
|
|
</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>
|
2022-12-06 16:03:55 +00:00
|
|
|
<Show when={isSessionLoaded()}>
|
2022-12-01 18:45:35 +00:00
|
|
|
<Show when={canFollow()}>
|
|
|
|
<div class={styles.authorSubscribe}>
|
|
|
|
<Show
|
|
|
|
when={subscribed()}
|
|
|
|
fallback={
|
|
|
|
<button
|
2023-06-14 17:19:30 +00:00
|
|
|
onClick={handleSubscribe}
|
2022-12-01 18:45:35 +00:00
|
|
|
class={clsx('button', styles.button)}
|
|
|
|
classList={{
|
2023-05-17 20:27:24 +00:00
|
|
|
[styles.buttonSubscribe]: !props.isAuthorsList && !props.isTextButton,
|
2022-12-01 18:45:35 +00:00
|
|
|
'button--subscribe': !props.isAuthorsList,
|
2023-05-17 20:27:24 +00:00
|
|
|
'button--subscribe-topic': props.isAuthorsList || props.isTextButton,
|
|
|
|
[styles.buttonWrite]: props.isAuthorsList || props.isTextButton,
|
2022-12-01 18:45:35 +00:00
|
|
|
[styles.isSubscribing]: isSubscribing()
|
|
|
|
}}
|
|
|
|
disabled={isSubscribing()}
|
|
|
|
>
|
2023-05-17 20:27:24 +00:00
|
|
|
<Show when={!props.isAuthorsList && !props.isTextButton}>
|
2022-12-04 15:10:27 +00:00
|
|
|
<Icon name="author-subscribe" class={styles.icon} />
|
2022-12-01 18:45:35 +00:00
|
|
|
</Show>
|
2023-05-17 20:27:24 +00:00
|
|
|
<Show when={props.isTextButton}>
|
|
|
|
<span class={clsx(styles.buttonLabel, styles.buttonLabelVisible)}>
|
|
|
|
{t('Follow')}
|
|
|
|
</span>
|
|
|
|
</Show>
|
2022-12-01 18:45:35 +00:00
|
|
|
</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={{
|
2023-05-17 20:27:24 +00:00
|
|
|
[styles.buttonSubscribe]: !props.isAuthorsList && !props.isTextButton,
|
2022-12-01 18:45:35 +00:00
|
|
|
'button--subscribe': !props.isAuthorsList,
|
2023-05-17 20:27:24 +00:00
|
|
|
'button--subscribe-topic': props.isAuthorsList || props.isTextButton,
|
|
|
|
[styles.buttonWrite]: props.isAuthorsList || props.isTextButton,
|
2022-12-01 18:45:35 +00:00
|
|
|
[styles.isSubscribing]: isSubscribing()
|
|
|
|
}}
|
|
|
|
disabled={isSubscribing()}
|
|
|
|
>
|
2023-05-17 20:27:24 +00:00
|
|
|
<Show when={!props.isAuthorsList && !props.isTextButton}>
|
2022-12-01 18:45:35 +00:00
|
|
|
<Icon name="author-unsubscribe" class={styles.icon} />
|
|
|
|
</Show>
|
2023-05-17 20:27:24 +00:00
|
|
|
<Show when={props.isTextButton}>
|
2023-06-15 20:44:49 +00:00
|
|
|
<span
|
|
|
|
class={clsx(
|
|
|
|
styles.buttonLabel,
|
|
|
|
styles.buttonLabelVisible,
|
|
|
|
styles.buttonUnfollowLabel
|
|
|
|
)}
|
|
|
|
>
|
2023-05-17 20:27:24 +00:00
|
|
|
{t('Unfollow')}
|
|
|
|
</span>
|
2023-06-15 20:44:49 +00:00
|
|
|
<span
|
|
|
|
class={clsx(
|
|
|
|
styles.buttonLabel,
|
|
|
|
styles.buttonLabelVisible,
|
|
|
|
styles.buttonSubscribedLabel
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{t('You are subscribed')}
|
|
|
|
</span>
|
2023-05-17 20:27:24 +00:00
|
|
|
</Show>
|
2022-12-01 18:45:35 +00:00
|
|
|
</button>
|
2022-11-11 08:58:22 +00:00
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-03-23 21:39:13 +00:00
|
|
|
<Show when={!props.hideWriteButton}>
|
2022-12-01 18:45:35 +00:00
|
|
|
<button
|
|
|
|
class={styles.button}
|
|
|
|
classList={{
|
|
|
|
[styles.buttonSubscribe]: !props.isAuthorsList,
|
|
|
|
'button--subscribe': !props.isAuthorsList,
|
|
|
|
'button--subscribe-topic': props.isAuthorsList,
|
|
|
|
[styles.buttonWrite]: props.liteButtons && props.isAuthorsList
|
|
|
|
}}
|
2022-12-17 03:27:00 +00:00
|
|
|
onClick={initChat}
|
2022-12-01 18:45:35 +00:00
|
|
|
>
|
2023-05-17 20:27:24 +00:00
|
|
|
<Show when={!props.isTextButton}>
|
|
|
|
<Icon name="comment" class={styles.icon} />
|
|
|
|
</Show>
|
|
|
|
<Show when={!props.liteButtons || props.isTextButton}>{t('Write')}</Show>
|
2022-12-01 18:45:35 +00:00
|
|
|
</button>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
<Show when={!props.noSocialButtons}>
|
2023-01-20 04:40:55 +00:00
|
|
|
<div class={styles.authorSubscribeSocial}>
|
|
|
|
<For each={props.author.links}>{(link) => <a href={link} />}</For>
|
|
|
|
</div>
|
2022-12-01 18:45:35 +00:00
|
|
|
</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
|
|
|
)
|
|
|
|
}
|