webapp/src/components/Author/Userpic.tsx

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-09-09 11:53:35 +00:00
import { Show } from 'solid-js/web'
import type { Author } from '../../graphql/types.gen'
import style 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-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-10-25 19:43:24 +00:00
<div class={clsx(style.circlewrap, props.class)} classList={{ [style.big]: props.isBig }}>
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
src={props.user.userpic || '/icons/user-anonymous.svg'}
alt={props.user.name || ''}
classList={{ anonymous: !props.user.userpic }}
/>
}
>
<div class={style.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
src={props.user.userpic || '/icons/user-anonymous.svg'}
alt={props.user.name || ''}
classList={{ anonymous: !props.user.userpic }}
/>
}
>
<div class={style.userpic}>{letters()}</div>
2022-09-09 11:53:35 +00:00
</Show>
</Show>
</div>
)
}