aboutsummaryrefslogtreecommitdiff
path: root/src/components/Avatar/Avatar.tsx
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-08-11 23:17:28 +0300
committerGitHub <noreply@github.com>2020-08-11 23:17:28 +0300
commit94067ef2a0d9ac5c2aa5f45eca5366a2251ac04a (patch)
tree51e502c7d1be7c8ad2179daf2f5c9bfd27911636 /src/components/Avatar/Avatar.tsx
parentc6723fa8a2a303f356b1756b45b2190203c96582 (diff)
parentb5ce9be31993f5b4bee9abbe57d775b7ea407507 (diff)
downloadwhich-ui-94067ef2a0d9ac5c2aa5f45eca5366a2251ac04a.tar.gz
Merge pull request #76 from which-ecosystem/redesign
Initial header redesign
Diffstat (limited to 'src/components/Avatar/Avatar.tsx')
-rw-r--r--src/components/Avatar/Avatar.tsx36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/components/Avatar/Avatar.tsx b/src/components/Avatar/Avatar.tsx
new file mode 100644
index 0000000..e445891
--- /dev/null
+++ b/src/components/Avatar/Avatar.tsx
@@ -0,0 +1,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;