From 8b6623d0e5a7e528ce60bfabc2355a6499837530 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Tue, 13 Jul 2021 17:06:01 +0530 Subject: Minor Design and Code improvements --- modern/src/DevicesList.js | 82 +++++++++++++++++-------------------- modern/src/MainPage.js | 100 +++++++++++++++++++++++++++------------------- 2 files changed, 96 insertions(+), 86 deletions(-) (limited to 'modern') diff --git a/modern/src/DevicesList.js b/modern/src/DevicesList.js index c774cdfe..d80c0608 100644 --- a/modern/src/DevicesList.js +++ b/modern/src/DevicesList.js @@ -19,7 +19,7 @@ import EditCollectionView from './EditCollectionView'; import { useEffectAsync } from './reactHelper'; import { formatPosition } from './common/formatter'; -const useStyles = makeStyles(theme => ({ +const useStyles = makeStyles((theme) => ({ list: { maxHeight: '100%', }, @@ -31,7 +31,7 @@ const useStyles = makeStyles(theme => ({ batteryText: { fontSize: '0.75rem', fontWeight: 'normal', - lineHeight: '0.875rem' + lineHeight: '0.875rem', }, green: { color: theme.palette.common.green, @@ -40,58 +40,31 @@ const useStyles = makeStyles(theme => ({ color: theme.palette.common.red, }, gray: { - color: theme.palette.common.gray - } + color: theme.palette.common.gray, + }, })); -const OnlineStatus =({ status }) => { - - const classes = useStyles(); - +const getOnlineStatus = (status) => { switch (status) { case 'online': - return {status} + return 'green'; case 'offline': - return {status} + return 'red'; case 'unknown': default: - return {status} - } -} - -const DeviceStatus = ({ deviceId }) => { - const classes = useStyles(); - let batteryClass = ''; - - const position = useSelector(state => state.positions.items[deviceId]); - if (!position) { - return null; + return 'gray'; } - const batteryLevel = position.attributes.hasOwnProperty('batteryLevel') ? position.attributes.batteryLevel : 'undefined'; +}; +const getBatteryStatus = (batteryLevel) => { if (batteryLevel >= 70) { - batteryClass = classes.green; - } else if (batteryLevel > 30) { - batteryClass = classes.gray; - } else { - batteryClass = classes.red; + return 'green'; } - return ( - - {position.attributes.hasOwnProperty('ignition') && - - } - {batteryLevel !== 'undefined' && - - {formatPosition(batteryLevel, 'batteryLevel')} - - - - - } - - ); -} + if (batteryLevel > 30) { + return 'gray'; + } + return 'red'; +}; const DeviceRow = ({ data, index, style }) => { const classes = useStyles(); @@ -99,6 +72,7 @@ const DeviceRow = ({ data, index, style }) => { const { items, onMenuClick } = data; const item = items[index]; + const position = useSelector((state) => state.positions.items[item.id]); return (
@@ -109,9 +83,27 @@ const DeviceRow = ({ data, index, style }) => { - } /> + - + {position && ( + + {position.attributes.hasOwnProperty('ignition') && ( + + + + )} + {position.attributes.hasOwnProperty('batteryLevel') && ( + + + {formatPosition(position.attributes.batteryLevel, 'batteryLevel')} + + + + + + )} + + )} {index < items.length - 1 ? : null} diff --git a/modern/src/MainPage.js b/modern/src/MainPage.js index 9740227e..e41cc338 100644 --- a/modern/src/MainPage.js +++ b/modern/src/MainPage.js @@ -1,7 +1,8 @@ import React, { useState } from 'react'; import { useHistory } from 'react-router-dom'; -import classnames from 'classnames'; -import { makeStyles, withWidth, Paper, Toolbar, Grid, TextField, IconButton, Button } from '@material-ui/core'; +import { + makeStyles, Paper, Toolbar, Grid, TextField, IconButton, Button, +} from '@material-ui/core'; import { useTheme } from '@material-ui/core/styles'; import useMediaQuery from '@material-ui/core/useMediaQuery'; @@ -48,15 +49,15 @@ const useStyles = makeStyles((theme) => ({ zIndex: 1301, height: '100%', maxHeight: `calc(100vh - ${theme.spacing(20)}px)`, - [theme.breakpoints.down("md")]: { + [theme.breakpoints.down('md')]: { top: theme.spacing(7), left: '0px', width: '100%', maxHeight: `calc(100vh - ${theme.spacing(14)}px)`, - } + }, }, paper: { - borderRadius: '0px', + borderRadius: '0px', }, toolbar: { paddingLeft: theme.spacing(2), @@ -68,25 +69,33 @@ const useStyles = makeStyles((theme) => ({ collapsed: { transform: `translateX(-${360 + 16}px)`, transition: 'transform .5s ease', - [theme.breakpoints.down("md")]: { - transform: `translateX(-100vw)`, - } + [theme.breakpoints.down('md')]: { + transform: 'translateX(-100vw)', + }, }, uncollapsed: { transform: `translateX(${theme.spacing(1.5)})`, transition: 'transform .5s ease', - [theme.breakpoints.down("md")]: { - transform: `translateX(0)`, - } + [theme.breakpoints.down('md')]: { + transform: 'translateX(0)', + }, }, deviceButton: { position: 'absolute', left: theme.spacing(1), top: theme.spacing(10.5), borderRadius: '0px', - [theme.breakpoints.down("md")]: { + [theme.breakpoints.down('md')]: { + left: theme.spacing(0), top: theme.spacing(7), - } + }, + }, + deviceButtonBackground: { + backgroundColor: 'white', + color: '#777777', + '&:hover': { + backgroundColor: 'white', + }, }, bottomMenuContainer: { position: 'absolute', @@ -94,11 +103,11 @@ const useStyles = makeStyles((theme) => ({ bottom: theme.spacing(1.5), width: theme.dimensions.drawerWidthDesktop, zIndex: 1301, - [theme.breakpoints.down("md")]: { + [theme.breakpoints.down('md')]: { bottom: theme.spacing(0), left: '0px', - width: '100%' - } + width: '100%', + }, }, menuButton: { display: 'flex', @@ -108,10 +117,10 @@ const useStyles = makeStyles((theme) => ({ fontSize: '0.75rem', fontWeight: 'normal', color: '#222222', - } + }, })); -const MainPage = ({ width }) => { +const MainPage = () => { const classes = useStyles(); const history = useHistory(); const theme = useTheme(); @@ -123,7 +132,7 @@ const MainPage = ({ width }) => { const handleClose = () => { setCollapsed(!collapsed); - } + }; return (
@@ -135,48 +144,57 @@ const MainPage = ({ width }) => { - {collapsed && - - } + )}
- + - {matchesMD && + {matchesMD && ( + - - } + + + )} setDeviceName(event.target.value)} + onChange={(event) => setDeviceName(event.target.value)} placeholder="Search Devices" - variant='filled' /> + variant="filled" + /> history.push('/device')}> - {!matchesMD && + {!matchesMD && ( + - } + + )} @@ -196,25 +214,25 @@ const MainPage = ({ width }) => { {t('reportReplay')} - + {t('reportTitle')} - + Options - + {t('settingsUser')} - + @@ -224,4 +242,4 @@ const MainPage = ({ width }) => { ); }; -export default withWidth()(MainPage); +export default MainPage; -- cgit v1.2.3