From d9bd2a941c4a11c660e52db504587ba735a29add Mon Sep 17 00:00:00 2001 From: Desmond Kyeremeh Date: Fri, 23 Jul 2021 13:52:48 +0000 Subject: Fixed homepage issues --- modern/src/DevicesList.js | 76 ++++++++++++++++++++++++++--------------------- modern/src/MainPage.js | 22 ++++++++------ 2 files changed, 55 insertions(+), 43 deletions(-) (limited to 'modern/src') diff --git a/modern/src/DevicesList.js b/modern/src/DevicesList.js index 294a9fff..79b62982 100644 --- a/modern/src/DevicesList.js +++ b/modern/src/DevicesList.js @@ -1,8 +1,7 @@ -import React, { Fragment } from 'react'; +import React, { useRef } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { makeStyles } from '@material-ui/core/styles'; import Avatar from '@material-ui/core/Avatar'; -import Divider from '@material-ui/core/Divider'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemAvatar from '@material-ui/core/ListItemAvatar'; @@ -19,11 +18,16 @@ import { devicesActions } from './store'; import EditCollectionView from './EditCollectionView'; import { useEffectAsync } from './reactHelper'; import { formatPosition } from './common/formatter'; +import { getDevices, getItemPosition } from './common/selectors'; const useStyles = makeStyles((theme) => ({ list: { maxHeight: '100%', }, + listInner: { + position: 'relative', + margin: theme.spacing(1.5, 0), + }, icon: { width: '25px', height: '25px', @@ -82,43 +86,40 @@ const DeviceRow = ({ data, index, style }) => { const { items } = data; const item = items[index]; - const position = useSelector((state) => state.positions.items[item.id]); + const position = useSelector(getItemPosition(item.id)); const showIgnition = position?.attributes.hasOwnProperty('ignition') && position.attributes.ignition; return (
- - dispatch(devicesActions.select(item))}> - - - - - - - - {position && ( - - {showIgnition && ( - - - - )} - {position.attributes.hasOwnProperty('batteryLevel') && ( - - - {formatPosition(position.attributes.batteryLevel, 'batteryLevel')} - - - - - - )} + dispatch(devicesActions.select(item))}> + + + + + + + + {position && ( + + {showIgnition && ( + + + + )} + {position.attributes.hasOwnProperty('batteryLevel') && ( + + + {formatPosition(position.attributes.batteryLevel, 'batteryLevel')} + + + + )} - - - {index < items.length - 1 ? : null} - + + )} + +
); }; @@ -126,8 +127,13 @@ const DeviceRow = ({ data, index, style }) => { const DeviceView = ({ updateTimestamp, onMenuClick }) => { const classes = useStyles(); const dispatch = useDispatch(); + const listInnerEl = useRef(null); - const items = useSelector((state) => Object.values(state.devices.items)); + const items = useSelector(getDevices); + + if (listInnerEl.current) { + listInnerEl.current.className = classes.listInner; + } useEffectAsync(async () => { const response = await fetch('/api/devices'); @@ -146,6 +152,8 @@ const DeviceView = ({ updateTimestamp, onMenuClick }) => { itemCount={items.length} itemData={{ items, onMenuClick }} itemSize={72 + 1} + overscanCount={10} + innerRef={listInnerEl} > {DeviceRow} diff --git a/modern/src/MainPage.js b/modern/src/MainPage.js index 417cdb03..e0707404 100644 --- a/modern/src/MainPage.js +++ b/modern/src/MainPage.js @@ -36,10 +36,10 @@ const useStyles = makeStyles((theme) => ({ bottom: theme.spacing(8), zIndex: 1301, transition: 'transform .5s ease', + backgroundColor: 'white', [theme.breakpoints.down('md')]: { width: '100%', margin: 0, - backgroundColor: 'white', }, }, sidebarCollapsed: { @@ -50,7 +50,7 @@ const useStyles = makeStyles((theme) => ({ }, }, paper: { - borderRadius: '0px', + zIndex: 1, }, toolbar: { display: 'flex', @@ -61,8 +61,6 @@ const useStyles = makeStyles((theme) => ({ }, deviceList: { flex: 1, - overflow: 'auto', - padding: theme.spacing(1.5, 0), }, sidebarToggle: { position: 'absolute', @@ -71,7 +69,13 @@ const useStyles = makeStyles((theme) => ({ borderRadius: '0px', minWidth: 0, [theme.breakpoints.down('md')]: { - left: theme.spacing(0), + left: 0, + }, + }, + sidebarToggleText: { + marginLeft: theme.spacing(1), + [theme.breakpoints.only('xs')]: { + display: 'none', }, }, sidebarToggleBg: { @@ -121,10 +125,10 @@ const MainPage = () => { disableElevation > - {!isPhone ? t('deviceTitle') : ''} +
{t('deviceTitle')}
-
- + + {isTablet && ( @@ -154,7 +158,7 @@ const MainPage = () => {
-
+ -- cgit v1.2.3