aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-07-03 22:09:22 +0300
committereug-vs <eug-vs@keemail.me>2020-07-03 22:09:46 +0300
commit3cd9081939d2f22221065018cb501441528257fc (patch)
tree51e96e803984e6ed39c27f3fc88ed92dedbd884f
parentaf51f6c8a6fabdd8e578e13599b33f121f483a52 (diff)
downloadwhich-ui-3cd9081939d2f22221065018cb501441528257fc.tar.gz
feat: adapt header for mobile devices
-rw-r--r--package-lock.json13
-rw-r--r--package.json1
-rw-r--r--src/components/Header/Header.tsx78
3 files changed, 70 insertions, 22 deletions
diff --git a/package-lock.json b/package-lock.json
index 41430ec..080ae60 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10798,6 +10798,14 @@
}
}
},
+ "react-device-detect": {
+ "version": "1.13.1",
+ "resolved": "https://registry.npmjs.org/react-device-detect/-/react-device-detect-1.13.1.tgz",
+ "integrity": "sha512-XTPgAMsUVHC5lMNUGiAeO2UfAfhMfjq0CBUM67eHnc9XfO7iESh6h/cffKV8VGgrZBX+dyuqJl23bLLHoav5Ig==",
+ "requires": {
+ "ua-parser-js": "^0.7.21"
+ }
+ },
"react-dom": {
"version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.13.1.tgz",
@@ -13189,6 +13197,11 @@
"integrity": "sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==",
"dev": true
},
+ "ua-parser-js": {
+ "version": "0.7.21",
+ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.21.tgz",
+ "integrity": "sha512-+O8/qh/Qj8CgC6eYBVBykMrNtp5Gebn4dlGD/kKXVkJNDwyrAwSIqwz8CDf+tsAIWVycKcku6gIXJ0qwx/ZXaQ=="
+ },
"unicode-canonical-property-names-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
diff --git a/package.json b/package.json
index 40797fe..67164a7 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"lodash": "^4.17.15",
"notistack": "^0.9.17",
"react": "^16.13.1",
+ "react-device-detect": "^1.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.10.0",
"react-scripts": "3.4.1",
diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx
index 294c250..c6c1608 100644
--- a/src/components/Header/Header.tsx
+++ b/src/components/Header/Header.tsx
@@ -11,25 +11,33 @@ import NotificationsIcon from '@material-ui/icons/Notifications';
import HomeIcon from '@material-ui/icons/Home';
import { useAuth } from '../../hooks/useAuth';
import { useNavigate } from '../../hooks/useNavigate';
+import { isMobile } from 'react-device-detect';
import SearchBar from './SearchBar';
-const useStyles = makeStyles({
- root: {
+const useStyles = makeStyles(theme => ({
+ mobile: {
+ top: 'auto',
+ bottom: 0
+ },
+ toolbar: {
display: 'flex',
- justifyContent: 'space-around',
+ justifyContent: 'space-around'
+ },
+ browserToolbar: {
width: '60%',
margin: 'auto'
},
logo: {
fontWeight: 'bold',
- cursor: 'pointer'
+ cursor: 'pointer',
+ color: 'white'
},
avatar: {
- width: 24,
- height: 24
+ width: theme.spacing(3),
+ height: theme.spacing(3)
}
-});
+}));
const Header: React.FC = () => {
const classes = useStyles();
@@ -53,31 +61,57 @@ const Header: React.FC = () => {
navigate('notifications');
};
- return (
+ const FeedButton = (
+ <IconButton onClick={handleFeed}>
+ <HomeIcon />
+ </IconButton>
+ );
+
+ const NotificationsButton = (
+ <IconButton onClick={handleNotifications}>
+ <NotificationsIcon />
+ </IconButton>
+ );
+
+ const ProfileButton = (
+ <IconButton onClick={handleProfile}>
+ { user?.avatarUrl
+ ? <Avatar className={classes.avatar} src={user?.avatarUrl} />
+ : <AccountCircle />
+ }
+ </IconButton>
+ );
+
+ const BrowserVersion = (
<AppBar position="fixed">
- <Toolbar className={classes.root}>
+ <Toolbar className={`${classes.toolbar} ${classes.browserToolbar}`}>
<Typography variant="h5" className={classes.logo} onClick={handleHome}>
Which
</Typography>
<SearchBar />
<div>
- <IconButton onClick={handleFeed}>
- <HomeIcon />
- </IconButton>
- <IconButton onClick={handleNotifications}>
- <NotificationsIcon />
- </IconButton>
- <IconButton onClick={handleProfile}>
- {
- user?.avatarUrl
- ? <Avatar className={classes.avatar} src={user?.avatarUrl} />
- : <AccountCircle />
- }
- </IconButton>
+ {FeedButton}
+ {NotificationsButton}
+ {ProfileButton}
</div>
</Toolbar>
</AppBar>
);
+
+ const MobileVersion = (
+ <AppBar position="fixed" className={classes.mobile}>
+ <Toolbar className={classes.toolbar}>
+ <IconButton onClick={handleHome}>
+ <Typography className={classes.logo}>W</Typography>
+ </IconButton>
+ {FeedButton}
+ {NotificationsButton}
+ {ProfileButton}
+ </Toolbar>
+ </AppBar>
+ );
+
+ return isMobile ? MobileVersion : BrowserVersion;
};
export default Header;