aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/Avatar.js
blob: 6ea0d5d530b41d40d4f1dbf4dc1debd2cbbd16c9 (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
45
46
47
48
49
50
51
52
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';

import { UserType } from './Types';

import Icon from './Icon';

import './Avatar.css';

const Avatar = React.memo(props => {
    return (
        <div className="Avatar" style={props.style}>
            <div className="msg-avatar">
                {
                    props.user.uname ?
                        <Link to={{ pathname: props.link || `/${props.user.uname}/` }}>
                            { props.user.avatar ?
                             <img src={props.user.avatar} alt={`${props.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: `/${props.user.uname}/` }}>
                        <span>{props.user.uname}</span>
                    </Link>
                </span>
                {props.children}
            </div>
        </div>
    );
});

export default Avatar;

export const AvatarLink = React.memo(props => {
    return (
        <Link to={{ pathname: props.link || `/${props.user.uname}/` }}>
            <img src={props.user.avatar} alt={`${props.user.uname}`} />
            {props.user.uname}
        </Link>
    );
});

Avatar.propTypes = {
    user: UserType,
    link: PropTypes.string,
    children: PropTypes.node
};