2024-01-31 12:34:15 +00:00
|
|
|
import type { Author, Community } from '../../../graphql/schema/core.gen'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
|
|
|
import { openPage, redirectPage } from '@nanostores/router'
|
2022-10-14 18:33:06 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-02-05 15:04:23 +00:00
|
|
|
import { For, Show, createEffect, createMemo, createSignal, onMount } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
import { useFollowing } from '../../../context/following'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { useLocalize } from '../../../context/localize'
|
2023-09-01 14:28:50 +00:00
|
|
|
import { useSession } from '../../../context/session'
|
2023-11-28 13:18:25 +00:00
|
|
|
import { FollowingEntity, Topic } from '../../../graphql/schema/core.gen'
|
2023-09-18 16:33:22 +00:00
|
|
|
import { SubscriptionFilter } from '../../../pages/types'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { router, useRouter } from '../../../stores/router'
|
2023-09-18 16:33:22 +00:00
|
|
|
import { isAuthor } from '../../../utils/isAuthor'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { translit } from '../../../utils/ru2en'
|
2024-02-04 17:40:15 +00:00
|
|
|
import { isCyrillic } from '../../../utils/translate'
|
2024-02-04 11:25:21 +00:00
|
|
|
import { SharePopup, getShareUrl } from '../../Article/SharePopup'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { Modal } from '../../Nav/Modal'
|
|
|
|
import { TopicBadge } from '../../Topic/TopicBadge'
|
2024-02-04 11:25:21 +00:00
|
|
|
import { Button } from '../../_shared/Button'
|
|
|
|
import { ShowOnlyOnClient } from '../../_shared/ShowOnlyOnClient'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { AuthorBadge } from '../AuthorBadge'
|
|
|
|
import { Userpic } from '../Userpic'
|
|
|
|
|
2023-11-08 20:42:13 +00:00
|
|
|
import stylesButton from '../../_shared/Button/Button.module.scss'
|
2024-02-04 11:25:21 +00:00
|
|
|
import styles from './AuthorCard.module.scss'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-09-09 12:04:46 +00:00
|
|
|
type Props = {
|
2022-09-09 11:53:35 +00:00
|
|
|
author: Author
|
2023-09-01 14:28:50 +00:00
|
|
|
followers?: Author[]
|
2023-09-16 06:26:19 +00:00
|
|
|
following?: Array<Author | Topic>
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
2023-09-09 12:04:46 +00:00
|
|
|
export const AuthorCard = (props: Props) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t, lang } = useLocalize()
|
2024-02-04 17:40:15 +00:00
|
|
|
const { author, isSessionLoaded, requireAuthentication } = useSession()
|
2024-01-31 12:34:15 +00:00
|
|
|
const [authorSubs, setAuthorSubs] = createSignal<Array<Author | Topic | Community>>([])
|
2023-09-01 14:28:50 +00:00
|
|
|
const [subscriptionFilter, setSubscriptionFilter] = createSignal<SubscriptionFilter>('all')
|
2024-02-03 07:56:11 +00:00
|
|
|
const [isFollowed, setIsFollowed] = createSignal<boolean>()
|
2023-12-03 10:22:42 +00:00
|
|
|
const isProfileOwner = createMemo(() => author()?.slug === props.author.slug)
|
2024-02-05 12:34:47 +00:00
|
|
|
const { setFollowing, isOwnerSubscribed } = useFollowing()
|
2024-02-04 17:40:15 +00:00
|
|
|
|
2024-02-05 11:11:46 +00:00
|
|
|
onMount(() => {
|
|
|
|
setAuthorSubs(props.following)
|
|
|
|
})
|
|
|
|
|
|
|
|
createEffect(() => {
|
|
|
|
setIsFollowed(isOwnerSubscribed(props.author?.id))
|
|
|
|
})
|
2024-02-03 07:56:11 +00:00
|
|
|
|
2022-12-07 20:11:32 +00:00
|
|
|
const name = createMemo(() => {
|
2023-12-28 00:30:09 +00:00
|
|
|
if (lang() !== 'ru' && isCyrillic(props.author.name)) {
|
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
|
2023-12-20 08:07:57 +00:00
|
|
|
const { changeSearchParams } = useRouter()
|
2022-12-17 03:27:00 +00:00
|
|
|
const initChat = () => {
|
2024-01-31 12:34:15 +00:00
|
|
|
// eslint-disable-next-line solid/reactivity
|
2023-06-14 17:19:30 +00:00
|
|
|
requireAuthentication(() => {
|
2024-02-05 15:04:23 +00:00
|
|
|
openPage(router, 'inbox')
|
2023-12-20 08:07:57 +00:00
|
|
|
changeSearchParams({
|
2023-11-14 15:10:00 +00:00
|
|
|
initChat: props.author.id.toString(),
|
2023-09-29 12:48:58 +00:00
|
|
|
})
|
2023-06-14 17:19:30 +00:00
|
|
|
}, 'discussions')
|
2022-12-17 03:27:00 +00:00
|
|
|
}
|
2023-06-14 17:19:30 +00:00
|
|
|
|
2023-09-01 14:28:50 +00:00
|
|
|
createEffect(() => {
|
2023-09-16 06:26:19 +00:00
|
|
|
if (props.following) {
|
2024-01-31 12:34:15 +00:00
|
|
|
if (subscriptionFilter() === 'authors') {
|
|
|
|
setAuthorSubs(props.following.filter((s) => 'name' in s))
|
2023-09-01 14:28:50 +00:00
|
|
|
} else if (subscriptionFilter() === 'topics') {
|
2024-01-31 12:34:15 +00:00
|
|
|
setAuthorSubs(props.following.filter((s) => 'title' in s))
|
|
|
|
} else if (subscriptionFilter() === 'communities') {
|
|
|
|
setAuthorSubs(props.following.filter((s) => 'title' in s))
|
2023-09-01 14:28:50 +00:00
|
|
|
} else {
|
2024-01-31 12:34:15 +00:00
|
|
|
setAuthorSubs(props.following)
|
2023-09-01 14:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
const handleFollowClick = () => {
|
2024-02-03 07:56:11 +00:00
|
|
|
const value = !isFollowed()
|
2024-01-31 12:34:15 +00:00
|
|
|
requireAuthentication(() => {
|
2024-02-03 07:56:11 +00:00
|
|
|
setIsFollowed(value)
|
2024-01-31 12:34:15 +00:00
|
|
|
setFollowing(FollowingEntity.Author, props.author.slug, value)
|
|
|
|
}, 'subscribe')
|
|
|
|
}
|
2023-11-13 18:56:47 +00:00
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
const followButtonText = createMemo(() => {
|
2024-02-05 11:11:46 +00:00
|
|
|
if (isOwnerSubscribed(props.author?.id)) {
|
2023-11-06 19:50:55 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-11-08 20:42:13 +00:00
|
|
|
<span class={stylesButton.buttonSubscribeLabel}>{t('Following')}</span>
|
|
|
|
<span class={stylesButton.buttonSubscribeLabelHovered}>{t('Unfollow')}</span>
|
2023-11-06 19:50:55 +00:00
|
|
|
</>
|
|
|
|
)
|
2023-10-20 16:21:40 +00:00
|
|
|
}
|
2023-11-13 18:56:47 +00:00
|
|
|
return t('Follow')
|
|
|
|
})
|
2023-10-13 06:10:24 +00:00
|
|
|
|
2023-10-20 16:21:40 +00:00
|
|
|
return (
|
|
|
|
<div class={clsx(styles.author, 'row')}>
|
|
|
|
<div class="col-md-5">
|
|
|
|
<Userpic
|
|
|
|
size={'XL'}
|
|
|
|
name={props.author.name}
|
2023-12-03 10:22:42 +00:00
|
|
|
userpic={props.author.pic}
|
2023-10-20 16:21:40 +00:00
|
|
|
slug={props.author.slug}
|
|
|
|
class={styles.circlewrap}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class={clsx('col-md-15 col-xl-13', styles.authorDetails)}>
|
2023-10-13 06:10:24 +00:00
|
|
|
<div class={styles.authorDetailsWrapper}>
|
2023-10-20 16:21:40 +00:00
|
|
|
<div class={styles.authorName}>{name()}</div>
|
2023-11-28 17:06:13 +00:00
|
|
|
<Show when={props.author.bio}>
|
|
|
|
<div class={styles.authorAbout} innerHTML={props.author.bio} />
|
|
|
|
</Show>
|
2023-10-13 06:10:24 +00:00
|
|
|
<Show
|
|
|
|
when={
|
|
|
|
(props.followers && props.followers.length > 0) ||
|
|
|
|
(props.following && props.following.length > 0)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div class={styles.subscribersContainer}>
|
2023-10-16 22:14:43 +00:00
|
|
|
<Show when={props.followers && props.followers.length > 0}>
|
2024-01-27 06:21:48 +00:00
|
|
|
<a href="?m=followers" class={styles.subscribers}>
|
2023-10-16 22:14:43 +00:00
|
|
|
<For each={props.followers.slice(0, 3)}>
|
2023-10-20 16:21:40 +00:00
|
|
|
{(f) => (
|
2023-12-03 10:22:42 +00:00
|
|
|
<Userpic size={'XS'} name={f.name} userpic={f.pic} class={styles.subscribersItem} />
|
2023-10-20 16:21:40 +00:00
|
|
|
)}
|
2023-10-16 22:14:43 +00:00
|
|
|
</For>
|
|
|
|
<div class={styles.subscribersCounter}>
|
2023-10-20 16:21:40 +00:00
|
|
|
{t('SubscriberWithCount', { count: props.followers.length ?? 0 })}
|
2023-10-16 22:14:43 +00:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Show>
|
2023-10-13 21:29:11 +00:00
|
|
|
|
2023-10-16 22:14:43 +00:00
|
|
|
<Show when={props.following && props.following.length > 0}>
|
2024-01-27 06:21:48 +00:00
|
|
|
<a href="?m=following" class={styles.subscribers}>
|
2023-10-16 22:14:43 +00:00
|
|
|
<For each={props.following.slice(0, 3)}>
|
|
|
|
{(f) => {
|
|
|
|
if ('name' in f) {
|
2023-10-20 16:21:40 +00:00
|
|
|
return (
|
|
|
|
<Userpic
|
|
|
|
size={'XS'}
|
|
|
|
name={f.name}
|
2023-12-03 10:22:42 +00:00
|
|
|
userpic={f.pic}
|
2023-10-20 16:21:40 +00:00
|
|
|
class={styles.subscribersItem}
|
|
|
|
/>
|
|
|
|
)
|
2024-02-04 09:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ('title' in f) {
|
2023-10-20 16:21:40 +00:00
|
|
|
return (
|
|
|
|
<Userpic
|
|
|
|
size={'XS'}
|
|
|
|
name={f.title}
|
|
|
|
userpic={f.pic}
|
|
|
|
class={styles.subscribersItem}
|
|
|
|
/>
|
|
|
|
)
|
2023-10-16 22:14:43 +00:00
|
|
|
}
|
2024-02-04 09:23:20 +00:00
|
|
|
|
2023-10-16 22:14:43 +00:00
|
|
|
return null
|
|
|
|
}}
|
|
|
|
</For>
|
|
|
|
<div class={styles.subscribersCounter}>
|
|
|
|
{t('SubscriptionWithCount', { count: props?.following.length ?? 0 })}
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Show>
|
2023-09-01 14:28:50 +00:00
|
|
|
</div>
|
2023-10-13 06:10:24 +00:00
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
<ShowOnlyOnClient>
|
2023-10-16 22:14:43 +00:00
|
|
|
<Show when={isSessionLoaded()}>
|
2023-10-17 06:11:44 +00:00
|
|
|
<Show when={props.author.links && props.author.links.length > 0}>
|
2023-10-16 22:14:43 +00:00
|
|
|
<div class={styles.authorSubscribeSocial}>
|
|
|
|
<For each={props.author.links}>
|
|
|
|
{(link) => (
|
|
|
|
<a
|
|
|
|
class={styles.socialLink}
|
|
|
|
href={link.startsWith('http') ? link : `https://${link}`}
|
|
|
|
target="_blank"
|
2024-02-04 09:23:20 +00:00
|
|
|
rel="nofollow noopener noreferrer"
|
2023-10-16 22:14:43 +00:00
|
|
|
>
|
|
|
|
<span class={styles.authorSubscribeSocialLabel}>
|
|
|
|
{link.startsWith('http') ? link : `https://${link}`}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
</Show>
|
2023-10-20 16:21:40 +00:00
|
|
|
<Show
|
|
|
|
when={isProfileOwner()}
|
|
|
|
fallback={
|
|
|
|
<div class={styles.authorActions}>
|
2024-02-05 11:11:46 +00:00
|
|
|
<Show when={authorSubs().length}>
|
2024-02-03 07:56:11 +00:00
|
|
|
<Button
|
|
|
|
onClick={handleFollowClick}
|
|
|
|
value={followButtonText()}
|
|
|
|
isSubscribeButton={true}
|
|
|
|
class={clsx({
|
|
|
|
[stylesButton.subscribed]: isFollowed(),
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</Show>
|
2023-10-31 16:44:00 +00:00
|
|
|
<Button
|
|
|
|
variant={'secondary'}
|
|
|
|
value={t('Message')}
|
|
|
|
onClick={initChat}
|
2023-11-02 22:02:11 +00:00
|
|
|
class={styles.buttonWriteMessage}
|
2023-10-31 16:44:00 +00:00
|
|
|
/>
|
2023-10-20 16:21:40 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div class={styles.authorActions}>
|
2023-10-16 22:14:43 +00:00
|
|
|
<Button
|
|
|
|
variant="secondary"
|
|
|
|
onClick={() => redirectPage(router, 'profileSettings')}
|
2023-11-28 17:06:13 +00:00
|
|
|
value={
|
|
|
|
<>
|
|
|
|
<span class={styles.authorActionsLabel}>{t('Edit profile')}</span>
|
|
|
|
<span class={styles.authorActionsLabelMobile}>{t('Edit')}</span>
|
|
|
|
</>
|
|
|
|
}
|
2023-10-16 22:14:43 +00:00
|
|
|
/>
|
|
|
|
<SharePopup
|
|
|
|
title={props.author.name}
|
|
|
|
description={props.author.bio}
|
2023-12-03 10:22:42 +00:00
|
|
|
imageUrl={props.author.pic}
|
2023-10-16 22:14:43 +00:00
|
|
|
shareUrl={getShareUrl({ pathname: `/author/${props.author.slug}` })}
|
|
|
|
trigger={<Button variant="secondary" value={t('Share')} />}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Show>
|
2023-10-13 06:10:24 +00:00
|
|
|
</Show>
|
|
|
|
</ShowOnlyOnClient>
|
|
|
|
<Show when={props.followers}>
|
2023-12-29 06:39:16 +00:00
|
|
|
<Modal variant="medium" isResponsive={true} name="followers" maxHeight>
|
2023-10-13 06:10:24 +00:00
|
|
|
<>
|
|
|
|
<h2>{t('Followers')}</h2>
|
|
|
|
<div class={styles.listWrapper}>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-24">
|
|
|
|
<For each={props.followers}>
|
2024-02-05 11:11:46 +00:00
|
|
|
{(follower: Author) => (
|
|
|
|
<AuthorBadge
|
|
|
|
author={follower}
|
|
|
|
isFollowed={{
|
|
|
|
loaded: Boolean(authorSubs()),
|
|
|
|
value: isOwnerSubscribed(follower.id),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2023-10-13 06:10:24 +00:00
|
|
|
</For>
|
|
|
|
</div>
|
2023-09-02 22:14:34 +00:00
|
|
|
</div>
|
2023-09-01 14:28:50 +00:00
|
|
|
</div>
|
2023-10-13 06:10:24 +00:00
|
|
|
</>
|
|
|
|
</Modal>
|
|
|
|
</Show>
|
|
|
|
<Show when={props.following}>
|
2023-12-29 06:39:16 +00:00
|
|
|
<Modal variant="medium" isResponsive={true} name="following" maxHeight>
|
2023-10-13 06:10:24 +00:00
|
|
|
<>
|
|
|
|
<h2>{t('Subscriptions')}</h2>
|
|
|
|
<ul class="view-switcher">
|
|
|
|
<li class={clsx({ 'view-switcher__item--selected': subscriptionFilter() === 'all' })}>
|
|
|
|
<button type="button" onClick={() => setSubscriptionFilter('all')}>
|
|
|
|
{t('All')}
|
|
|
|
</button>
|
|
|
|
<span class="view-switcher__counter">{props.following.length}</span>
|
|
|
|
</li>
|
2024-01-31 12:34:15 +00:00
|
|
|
<li class={clsx({ 'view-switcher__item--selected': subscriptionFilter() === 'authors' })}>
|
|
|
|
<button type="button" onClick={() => setSubscriptionFilter('authors')}>
|
2023-12-27 23:35:43 +00:00
|
|
|
{t('Authors')}
|
2023-10-13 06:10:24 +00:00
|
|
|
</button>
|
|
|
|
<span class="view-switcher__counter">
|
|
|
|
{props.following.filter((s) => 'name' in s).length}
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
<li class={clsx({ 'view-switcher__item--selected': subscriptionFilter() === 'topics' })}>
|
|
|
|
<button type="button" onClick={() => setSubscriptionFilter('topics')}>
|
|
|
|
{t('Topics')}
|
|
|
|
</button>
|
|
|
|
<span class="view-switcher__counter">
|
|
|
|
{props.following.filter((s) => 'title' in s).length}
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<br />
|
|
|
|
<div class={styles.listWrapper}>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-24">
|
2024-01-31 12:34:15 +00:00
|
|
|
<For each={authorSubs()}>
|
2023-10-13 06:10:24 +00:00
|
|
|
{(subscription) =>
|
|
|
|
isAuthor(subscription) ? (
|
2024-02-05 11:11:46 +00:00
|
|
|
<AuthorBadge
|
|
|
|
isFollowed={{
|
|
|
|
loaded: Boolean(authorSubs()),
|
|
|
|
value: isOwnerSubscribed(subscription.id),
|
|
|
|
}}
|
|
|
|
author={subscription}
|
|
|
|
/>
|
2023-10-13 06:10:24 +00:00
|
|
|
) : (
|
2024-02-08 09:11:52 +00:00
|
|
|
<TopicBadge
|
|
|
|
isFollowed={{
|
|
|
|
loaded: Boolean(authorSubs()),
|
|
|
|
value: isOwnerSubscribed(subscription.id),
|
|
|
|
}}
|
|
|
|
topic={subscription}
|
|
|
|
/>
|
2023-10-13 06:10:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
</For>
|
|
|
|
</div>
|
2023-09-02 22:14:34 +00:00
|
|
|
</div>
|
2023-09-01 14:28:50 +00:00
|
|
|
</div>
|
2023-10-13 06:10:24 +00:00
|
|
|
</>
|
|
|
|
</Modal>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
)
|
|
|
|
}
|