2022-09-09 11:53:35 +00:00
|
|
|
import { Show } from 'solid-js/web'
|
|
|
|
import type { Author } from '../../graphql/types.gen'
|
2022-10-14 18:33:06 +00:00
|
|
|
import style from './Userpic.module.scss'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
interface UserpicProps {
|
|
|
|
user: Author
|
|
|
|
hasLink?: boolean
|
2022-10-14 18:33:06 +00:00
|
|
|
isBig?: 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-10-14 18:33:06 +00:00
|
|
|
<div class={style.circlewrap} 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 }}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2022-10-14 18:33:06 +00:00
|
|
|
<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 }}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2022-10-14 18:33:06 +00:00
|
|
|
<div class={style.userpic}>{letters()}</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
</Show>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|