webapp/src/components/_shared/Subscribers/Subscribers.tsx

60 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-05-10 14:14:06 +00:00
import { For, Show } from 'solid-js'
import { useLocalize } from '../../../context/localize'
import { Author, Topic } from '../../../graphql/schema/core.gen'
import { Userpic } from '../../Author/Userpic'
import styles from './Subscribers.module.scss'
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-05-10 14:14:06 +00:00
}
export const Subscribers = (props: Props) => {
const { t } = useLocalize()
return (
<div class={styles.subscribersContainer}>
2024-05-18 17:16:45 +00:00
<a href="?m=followers" class={styles.subscribers}>
<Show when={props.followers && props.followers.length > 0}>
2024-05-10 14:14:06 +00:00
<For each={props.followers.slice(0, 3)}>
{(f) => <Userpic size={'XS'} name={f.name} userpic={f.pic} class={styles.subscribersItem} />}
</For>
2024-05-18 17:16:45 +00:00
</Show>
<div class={styles.subscribersCounter}>
{t('SubscriberWithCount', {
count: props.followersAmount || props.followers.length || 0,
})}
</div>
</a>
<a href="?m=following" class={styles.subscribers}>
<Show when={props.following && props.following.length > 0}>
2024-05-10 14:14:06 +00:00
<For each={props.following.slice(0, 3)}>
{(f) => {
if ('name' in f) {
return <Userpic size={'XS'} name={f.name} userpic={f.pic} class={styles.subscribersItem} />
}
if ('title' in f) {
return <Userpic size={'XS'} name={f.title} userpic={f.pic} class={styles.subscribersItem} />
}
return null
}}
</For>
2024-05-18 17:16:45 +00:00
</Show>
<div class={styles.subscribersCounter}>
{t('SubscriptionWithCount', {
count: props.followingAmount || props.following?.length || 0,
})}
</div>
</a>
2024-05-10 14:14:06 +00:00
</div>
)
}