blob: e445891ac9f432fdb292bf3dde256a5362efbc20 (
plain)
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
|
import React from 'react';
import { useHistory } from 'react-router-dom';
import { Avatar as AvatarBase } from '@material-ui/core';
import AccountCircle from '@material-ui/icons/AccountCircle';
import { User } from 'which-types';
interface PropTypes {
user: User;
className?: string;
}
const Avatar: React.FC<PropTypes> = ({ user, className }) => {
const history = useHistory();
const { username, avatarUrl } = user;
const handleClick = () => {
history.push(`/profile/${username}`);
};
return avatarUrl ? (
<AvatarBase
src={avatarUrl}
alt={username[0].toUpperCase()}
onClick={handleClick}
className={className}
style={{ cursor: 'pointer' }}
/>
) : (
<AccountCircle
className={className}
onClick={handleClick}
/>
);
};
export default Avatar;
|