From 5a5bfd6c42539f72d03ec0b1670636ce9fb4b590 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 28 Jun 2021 22:46:39 -0700 Subject: Virtualize device list --- modern/src/DevicesList.js | 70 +++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 23 deletions(-) (limited to 'modern/src/DevicesList.js') diff --git a/modern/src/DevicesList.js b/modern/src/DevicesList.js index 976fd84..f66d717 100644 --- a/modern/src/DevicesList.js +++ b/modern/src/DevicesList.js @@ -10,6 +10,8 @@ import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import ListItemText from '@material-ui/core/ListItemText'; import MoreVertIcon from '@material-ui/icons/MoreVert'; +import { FixedSizeList } from 'react-window'; +import AutoSizer from 'react-virtualized-auto-sizer'; import { devicesActions } from './store'; import EditCollectionView from './EditCollectionView'; @@ -18,7 +20,6 @@ import { useEffectAsync } from './reactHelper'; const useStyles = makeStyles(() => ({ list: { maxHeight: '100%', - overflow: 'auto', }, icon: { width: '25px', @@ -27,6 +28,35 @@ const useStyles = makeStyles(() => ({ }, })); +const DeviceRow = ({ data, index, style }) => { + const classes = useStyles(); + const dispatch = useDispatch(); + + const { items, onMenuClick } = data; + const item = items[index]; + + return ( +
+ + dispatch(devicesActions.select(item))}> + + + + + + + + onMenuClick(event.currentTarget, item.id)}> + + + + + {index < items.length - 1 ? : null} + +
+ ); +}; + const DeviceView = ({ updateTimestamp, onMenuClick }) => { const classes = useStyles(); const dispatch = useDispatch(); @@ -41,33 +71,27 @@ const DeviceView = ({ updateTimestamp, onMenuClick }) => { }, [updateTimestamp]); return ( - - {items.map((item, index, list) => ( - - dispatch(devicesActions.select(item))}> - - - - - - - - onMenuClick(event.currentTarget, item.id)}> - - - - - {index < list.length - 1 ? : null} - - ))} - + + {({ height, width }) => ( + + + {DeviceRow} + + + )} + ); -} +}; const DevicesList = () => { return ( ); -} +}; export default DevicesList; -- cgit v1.2.3