webapp/src/components/Author/Userpic.tsx

63 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-10-31 16:40:55 +00:00
import { Show } from 'solid-js'
2022-09-09 11:53:35 +00:00
import type { Author } from '../../graphql/types.gen'
2022-11-11 08:58:22 +00:00
import styles from './Userpic.module.scss'
2022-10-25 19:43:24 +00:00
import { clsx } from 'clsx'
2022-09-09 11:53:35 +00:00
interface UserpicProps {
user: Author
hasLink?: boolean
isBig?: boolean
2022-10-25 19:43:24 +00:00
class?: string
2022-11-11 08:58:22 +00:00
isAuthorsList?: boolean
2022-09-09 11:53:35 +00:00
}
export default (props: UserpicProps) => {
const letters = () => {
const names = props.user && props.user.name ? props.user.name.split(' ') : []
return names[0][0] + (names.length > 1 ? names[1][0] : '')
}
return (
2022-11-11 08:58:22 +00:00
<div
class={clsx(styles.circlewrap, props.class)}
classList={{
[styles.big]: props.isBig,
[styles.authorsList]: props.isAuthorsList
}}
>
2022-09-09 11:53:35 +00:00
<Show when={props.hasLink}>
<a href={`/author/${props.user.slug}`}>
<Show
when={props.user && props.user.userpic === ''}
fallback={
<img
2022-11-26 16:51:08 +00:00
src={props.user.userpic || '/icons/user-default.svg'}
2022-09-09 11:53:35 +00:00
alt={props.user.name || ''}
classList={{ anonymous: !props.user.userpic }}
/>
}
>
2022-11-11 08:58:22 +00:00
<div class={styles.userpic}>{letters()}</div>
2022-09-09 11:53:35 +00:00
</Show>
</a>
</Show>
<Show when={!props.hasLink}>
<Show
when={props.user && props.user.userpic === ''}
fallback={
<img
2022-11-26 16:51:08 +00:00
src={props.user.userpic || '/icons/user-default.svg'}
2022-09-09 11:53:35 +00:00
alt={props.user.name || ''}
classList={{ anonymous: !props.user.userpic }}
/>
}
>
2022-11-11 08:58:22 +00:00
<div class={styles.userpic}>{letters()}</div>
2022-09-09 11:53:35 +00:00
</Show>
</Show>
</div>
)
}