From 8b1c7bb055ceeb4d3e95d7ab3b8fbe7aa1f8dfa7 Mon Sep 17 00:00:00 2001 From: Desmond Kyeremeh Date: Thu, 1 Jul 2021 13:55:52 +0000 Subject: Moved some selectors into separate file --- modern/src/MainToolbar.js | 75 ++++++++++++++++++++++++++++------------------- modern/src/selectors.js | 3 ++ 2 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 modern/src/selectors.js (limited to 'modern/src') diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js index 064507fb..c11ca96b 100644 --- a/modern/src/MainToolbar.js +++ b/modern/src/MainToolbar.js @@ -28,21 +28,22 @@ import CreateIcon from '@material-ui/icons/Create'; import ReplayIcon from '@material-ui/icons/Replay'; import BuildIcon from '@material-ui/icons/Build'; import t from './common/localization'; +import * as selectors from './selectors' const useStyles = makeStyles(theme => ({ flex: { flexGrow: 1 }, appBar: { - zIndex: theme.zIndex.drawer + 1, + zIndex: theme.zIndex.drawer + 1 }, list: { width: 250 }, menuButton: { marginLeft: -12, - marginRight: 20, - }, + marginRight: 20 + } })); const MainToolbar = () => { @@ -50,11 +51,15 @@ const MainToolbar = () => { const [drawer, setDrawer] = useState(false); const classes = useStyles(); const history = useHistory(); - const adminEnabled = useSelector(state => state.session.user && state.session.user.administrator); - const userId = useSelector(state => state.session.user && state.session.user.id); + const adminEnabled = useSelector(selectors.getIsAdmin); + const userId = useSelector(selectors.getUserId); - const openDrawer = () => { setDrawer(true) } - const closeDrawer = () => { setDrawer(false) } + const openDrawer = () => { + setDrawer(true); + }; + const closeDrawer = () => { + setDrawer(false); + }; const handleLogout = async () => { const response = await fetch('/api/session', { method: 'DELETE' }); @@ -62,7 +67,7 @@ const MainToolbar = () => { dispatch(sessionActions.updateUser(null)); history.push('/login'); } - } + }; return ( <> @@ -71,13 +76,16 @@ const MainToolbar = () => { + onClick={openDrawer} + > Traccar - + @@ -86,7 +94,8 @@ const MainToolbar = () => { className={classes.list} role="button" onClick={closeDrawer} - onKeyDown={closeDrawer}> + onKeyDown={closeDrawer} + > history.push('/')}> @@ -105,16 +114,15 @@ const MainToolbar = () => { - + - - {t('settingsTitle')} - - }> - history.push(`/user/${userId}`)}> + {t('settingsTitle')}}> + history.push(`/user/${userId}`)} + > @@ -126,7 +134,10 @@ const MainToolbar = () => { - history.push('/settings/notifications')}> + history.push('/settings/notifications')} + > @@ -144,13 +155,19 @@ const MainToolbar = () => { - history.push('/settings/attributes')}> + history.push('/settings/attributes')} + > - history.push('/settings/maintenances')}> + history.push('/settings/maintenances')} + > @@ -160,12 +177,7 @@ const MainToolbar = () => { {adminEnabled && ( <> - - {t('userAdmin')} - - }> + {t('userAdmin')}}> history.push('/admin/server')}> @@ -178,7 +190,10 @@ const MainToolbar = () => { - history.push('/admin/statistics')}> + history.push('/admin/statistics')} + > @@ -191,6 +206,6 @@ const MainToolbar = () => { ); -} +}; export default MainToolbar; diff --git a/modern/src/selectors.js b/modern/src/selectors.js new file mode 100644 index 00000000..f0b08f5f --- /dev/null +++ b/modern/src/selectors.js @@ -0,0 +1,3 @@ +export const getIsAdmin = state => state.session.user?.administrator; + +export const getUserId = state => state.session.user?.id; -- cgit v1.2.3