aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/Avatar/Avatar.tsx36
-rw-r--r--src/components/Header/Header.tsx8
-rw-r--r--src/components/UserStrip/UserStrip.tsx26
3 files changed, 46 insertions, 24 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;
diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx
index 344b839..5621dbf 100644
--- a/src/components/Header/Header.tsx
+++ b/src/components/Header/Header.tsx
@@ -3,7 +3,6 @@ import { useHistory } from 'react-router-dom';
import {
IconButton,
Typography,
- Avatar,
useMediaQuery
} from '@material-ui/core';
import {
@@ -19,6 +18,7 @@ import { useAuth } from '../../hooks/useAuth';
import MobileHeader from './MobileHeader';
import BottomBar from './BottomBar';
import BrowserHeader from './BrowserHeader';
+import Avatar from '../Avatar/Avatar';
const useStyles = makeStyles(theme => ({
@@ -90,9 +90,9 @@ const Header: React.FC = React.memo(() => {
const profile = (
<IconButton onClick={handleProfile}>
{
- user?.avatarUrl
- ? <Avatar className={classes.avatar} src={user?.avatarUrl} />
- : <AccountCircle />
+ user
+ ? <Avatar className={classes.avatar} user={user} />
+ : <AccountCircle className={classes.avatar} />
}
</IconButton>
);
diff --git a/src/components/UserStrip/UserStrip.tsx b/src/components/UserStrip/UserStrip.tsx
index 73d9363..a837961 100644
--- a/src/components/UserStrip/UserStrip.tsx
+++ b/src/components/UserStrip/UserStrip.tsx
@@ -1,10 +1,11 @@
import React from 'react';
-import { useHistory } from 'react-router-dom';
import { makeStyles } from '@material-ui/core/styles';
import VerifiedIcon from '@material-ui/icons/CheckCircleOutline';
-import { Avatar, CardHeader } from '@material-ui/core/';
+import { CardHeader } from '@material-ui/core/';
import { User } from 'which-types';
+import Avatar from '../Avatar/Avatar';
+
interface PropTypes {
user: User;
@@ -21,30 +22,15 @@ const useStyles = makeStyles(theme => ({
marginLeft: theme.spacing(0.5),
width: theme.spacing(2),
height: theme.spacing(2)
- },
- avatar: {
- cursor: 'pointer'
}
}));
const UserStrip: React.FC<PropTypes> = ({ user, info }) => {
const classes = useStyles();
- const history = useHistory();
- const { username, avatarUrl, verified } = user;
-
- const handleNavigate = () => {
- history.push(`/profile/${username}`);
- };
-
- const avatar = (
- <Avatar
- src={avatarUrl}
- alt={username[0].toUpperCase()}
- onClick={handleNavigate}
- className={classes.avatar}
- />
- );
+ const { username, verified } = user;
+
+ const avatar = <Avatar user={user} />;
const title = (
<div className={classes.root}>