aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/Avatar.js
blob: 1a8db0c3074915e633dac67885a9c02a7571d87f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { memo } from 'react'
import { Link } from 'react-router-dom'

import Icon from './Icon'

/**
 * @typedef {object} AvatarProps
 * @property {import('../api').User} user
 * @property {import('react').CSSProperties=} style
 * @property {string=} link
 * @property {import('react').ReactNode=} children
 */

/**
 * Avatar component
 * @param {AvatarProps} props
 */
function Avatar({ user, style, link, children }) {
    return (
        <div className="Avatar" style={style}>
            <div className="msg-avatar">
                {
                    user.uname ?
                        <Link to={{ pathname: link || `/${user.uname}/` }}>
                            {user.avatar ?
                                <img src={user.avatar} alt={`${user.uname}`} />
                                : <Icon name="ei-spinner" size="m" />}
                        </Link>
                        : <Icon name="ei-spinner" size="m" />
                }
            </div>
            <div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
                <span>
                    <Link to={{ pathname: link || `/${user.uname}/` }}>
                        <span>{user.uname}</span>
                    </Link>
                </span>
                {children}
            </div>
        </div>
    )
}

export default memo(Avatar)