diff options
Diffstat (limited to 'src/components/Avatar')
-rw-r--r-- | src/components/Avatar/Avatar.tsx | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/components/Avatar/Avatar.tsx b/src/components/Avatar/Avatar.tsx index e445891..29754c9 100644 --- a/src/components/Avatar/Avatar.tsx +++ b/src/components/Avatar/Avatar.tsx @@ -1,35 +1,27 @@ 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; + user?: User; className?: string; } const Avatar: React.FC<PropTypes> = ({ user, className }) => { const history = useHistory(); - const { username, avatarUrl } = user; const handleClick = () => { - history.push(`/profile/${username}`); + if (user) history.push(`/profile/${user.username}`); }; - return avatarUrl ? ( + return ( <AvatarBase - src={avatarUrl} - alt={username[0].toUpperCase()} + src={user?.avatarUrl} onClick={handleClick} className={className} style={{ cursor: 'pointer' }} /> - ) : ( - <AccountCircle - className={className} - onClick={handleClick} - /> ); }; |