From 3cd9081939d2f22221065018cb501441528257fc Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 3 Jul 2020 22:09:22 +0300 Subject: feat: adapt header for mobile devices --- package-lock.json | 13 +++++++ package.json | 1 + src/components/Header/Header.tsx | 78 ++++++++++++++++++++++++++++------------ 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 = ( + + + + ); + + const NotificationsButton = ( + + + + ); + + const ProfileButton = ( + + { user?.avatarUrl + ? + : + } + + ); + + const BrowserVersion = ( - + Which
- - - - - - - - { - user?.avatarUrl - ? - : - } - + {FeedButton} + {NotificationsButton} + {ProfileButton}
); + + const MobileVersion = ( + + + + W + + {FeedButton} + {NotificationsButton} + {ProfileButton} + + + ); + + return isMobile ? MobileVersion : BrowserVersion; }; export default Header; -- cgit v1.2.3