2024-06-06 09:04:01 +00:00
|
|
|
import { For, Show, createMemo } from 'solid-js'
|
2024-05-10 14:14:06 +00:00
|
|
|
|
2024-05-25 16:35:02 +00:00
|
|
|
import { useLocalize } from '../../../context/localize'
|
2024-05-10 14:14:06 +00:00
|
|
|
|
2024-05-25 16:35:02 +00:00
|
|
|
import { Author, Topic } from '../../../graphql/schema/core.gen'
|
|
|
|
import { Userpic } from '../../Author/Userpic'
|
2024-05-10 14:14:06 +00:00
|
|
|
|
2024-06-06 05:44:59 +00:00
|
|
|
import styles from './FollowingCounters.module.scss'
|
2024-05-10 14:14:06 +00:00
|
|
|
|
|
|
|
type Props = {
|
2024-05-18 17:16:45 +00:00
|
|
|
followers?: Author[]
|
|
|
|
followersAmount?: number
|
2024-05-10 14:14:06 +00:00
|
|
|
following?: Array<Author | Topic>
|
2024-05-18 17:16:45 +00:00
|
|
|
followingAmount?: number
|
2024-06-06 09:04:01 +00:00
|
|
|
authors?: Author[]
|
|
|
|
authorsAmount?: number
|
|
|
|
topics?: Topic[]
|
|
|
|
topicsAmount?: number
|
2024-05-10 14:14:06 +00:00
|
|
|
}
|
|
|
|
|
2024-06-06 09:04:01 +00:00
|
|
|
const UserpicList = (props: { items: Array<Author | Topic> }) => (
|
|
|
|
<div class={styles.subscribersList}>
|
|
|
|
<For each={props.items.slice(0, 3)}>
|
|
|
|
{(item) => (
|
|
|
|
<Userpic
|
|
|
|
size="XS"
|
|
|
|
name={'name' in item ? item.name : 'title' in item ? item.title : ''}
|
|
|
|
userpic={item.pic}
|
|
|
|
class={styles.subscribersItem}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
const Counter = (props: { count: number; label: string }) => (
|
|
|
|
<div class={styles.subscribersCounter}>{props.label}</div>
|
|
|
|
)
|
|
|
|
|
2024-06-06 05:44:59 +00:00
|
|
|
export const FollowingCounters = (props: Props) => {
|
2024-05-25 16:35:02 +00:00
|
|
|
const { t } = useLocalize()
|
2024-05-10 14:14:06 +00:00
|
|
|
|
2024-06-06 09:04:01 +00:00
|
|
|
const getFollowersCount = createMemo(() => props.followersAmount || props.followers?.length || 0)
|
|
|
|
const getFollowingCount = createMemo(() => props.followingAmount || props.following?.length || 0)
|
|
|
|
const getAuthorsCount = createMemo(() => props.authorsAmount || props.authors?.length || 0)
|
|
|
|
const getTopicsCount = createMemo(() => props.topicsAmount || props.topics?.length || 0)
|
|
|
|
|
2024-05-10 14:14:06 +00:00
|
|
|
return (
|
2024-05-25 16:27:15 +00:00
|
|
|
<>
|
2024-05-18 17:16:45 +00:00
|
|
|
<a href="?m=followers" class={styles.subscribers}>
|
2024-06-06 09:04:01 +00:00
|
|
|
<Show when={getFollowersCount() > 0}>
|
|
|
|
<UserpicList items={props.followers || []} />
|
2024-05-18 17:16:45 +00:00
|
|
|
</Show>
|
2024-06-06 09:04:01 +00:00
|
|
|
<Counter count={getFollowersCount()} label={t('some followers', { count: getFollowersCount() })} />
|
2024-05-18 17:16:45 +00:00
|
|
|
</a>
|
|
|
|
|
|
|
|
<a href="?m=following" class={styles.subscribers}>
|
2024-06-06 09:04:01 +00:00
|
|
|
<Show when={getFollowingCount() > 0}>
|
|
|
|
<UserpicList items={props.following || []} />
|
|
|
|
</Show>
|
|
|
|
<Show
|
|
|
|
when={getFollowingCount() > 0}
|
|
|
|
fallback={
|
|
|
|
<>
|
|
|
|
<Show when={getAuthorsCount() > 0}>
|
|
|
|
<UserpicList items={props.authors || []} />
|
|
|
|
<Counter
|
|
|
|
count={getAuthorsCount()}
|
|
|
|
label={t('some authors', { count: getAuthorsCount() })}
|
|
|
|
/>
|
|
|
|
</Show>
|
|
|
|
<Show when={getTopicsCount() > 0}>
|
|
|
|
<Counter count={getTopicsCount()} label={t('some topics', { count: getTopicsCount() })} />
|
|
|
|
</Show>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Counter
|
|
|
|
count={getFollowingCount()}
|
|
|
|
label={t('some followings', { count: getFollowingCount() })}
|
|
|
|
/>
|
2024-05-18 17:16:45 +00:00
|
|
|
</Show>
|
|
|
|
</a>
|
2024-05-25 16:27:15 +00:00
|
|
|
</>
|
2024-05-10 14:14:06 +00:00
|
|
|
)
|
|
|
|
}
|