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

68 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-05-25 16:35:02 +00:00
import { For, Show } 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
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) => {
2024-05-25 16:35:02 +00:00
const { t } = useLocalize()
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}>
<Show when={props.followers && props.followers.length > 0}>
2024-05-25 16:27:15 +00:00
<div class={styles.subscribersList}>
<For each={props.followers.slice(0, 3)}>
2024-05-25 16:35:02 +00:00
{(f) => <Userpic size={'XS'} name={f.name} userpic={f.pic} class={styles.subscribersItem} />}
2024-05-25 16:27:15 +00:00
</For>
</div>
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-25 16:27:15 +00:00
<div class={styles.subscribersList}>
<For each={props.following.slice(0, 3)}>
{(f) => {
if ('name' in f) {
2024-05-25 16:35:02 +00:00
return (
<Userpic size={'XS'} name={f.name} userpic={f.pic} class={styles.subscribersItem} />
)
2024-05-25 16:27:15 +00:00
}
if ('title' in f) {
2024-05-25 16:35:02 +00:00
return (
<Userpic size={'XS'} name={f.title} userpic={f.pic} class={styles.subscribersItem} />
)
2024-05-25 16:27:15 +00:00
}
return null
}}
</For>
</div>
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-25 16:27:15 +00:00
</>
2024-05-10 14:14:06 +00:00
)
}