From 37dd8129f8e07d00eb93262210bf1ecd4ce95532 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 20 Sep 2020 22:39:04 -0700 Subject: Refactor collection editing --- modern/src/DeviceList.js | 111 +++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 80 deletions(-) (limited to 'modern/src/DeviceList.js') diff --git a/modern/src/DeviceList.js b/modern/src/DeviceList.js index 66b94063..b7c15dc4 100644 --- a/modern/src/DeviceList.js +++ b/modern/src/DeviceList.js @@ -1,109 +1,60 @@ -import React, { Fragment, useState } from 'react'; +import React, { Fragment } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { makeStyles } from '@material-ui/core/styles'; -import { useHistory } from 'react-router-dom'; import Avatar from '@material-ui/core/Avatar'; import Divider from '@material-ui/core/Divider'; import IconButton from '@material-ui/core/IconButton'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemAvatar from '@material-ui/core/ListItemAvatar'; -import Menu from '@material-ui/core/Menu'; -import MenuItem from '@material-ui/core/MenuItem'; import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import ListItemText from '@material-ui/core/ListItemText'; import LocationOnIcon from '@material-ui/icons/LocationOn'; import MoreVertIcon from '@material-ui/icons/MoreVert'; -import Fab from '@material-ui/core/Fab'; -import AddIcon from '@material-ui/icons/Add'; import { devicesActions } from './store'; -import t from './common/localization'; -import RemoveDialog from './RemoveDialog'; +import EditCollectionView from './EditCollectionView'; -const useStyles = makeStyles(theme => ({ +const useStyles = makeStyles(() => ({ list: { maxHeight: '100%', overflow: 'auto', }, - fab: { - position: 'absolute', - bottom: theme.spacing(2), - right: theme.spacing(2), - }, })); -const DeviceList = () => { - const [menuDeviceId, setMenuDeviceId] = useState(null); - const [menuAnchorEl, setMenuAnchorEl] = useState(null); - const [removeDialogOpen, setRemoveDialogOpen] = useState(false); - const devices = useSelector(state => Object.values(state.devices.items)); - const dispatch = useDispatch(); +const DeviceView = ({ onMenuClick }) => { const classes = useStyles(); - const history = useHistory(); - - const handleMenuClick = (event, deviceId) => { - setMenuDeviceId(deviceId); - setMenuAnchorEl(event.currentTarget); - } - - const handleMenuClose = () => { - setMenuAnchorEl(null); - } - - const handleMenuEdit = () => { - history.push(`/device/${menuDeviceId}`); - handleMenuClose(); - } - - const handleMenuRemove = () => { - setRemoveDialogOpen(true); - handleMenuClose(); - } + const dispatch = useDispatch(); - const handleAdd = () => { - history.push('/device'); - handleMenuClose(); - } + const items = useSelector(state => Object.values(state.devices.items)); - const handleRemoveResult = (removed) => { - setRemoveDialogOpen(false); - if (removed) { - dispatch(devicesActions.remove(menuDeviceId)); - } - } + return ( + + {items.map((item, index, list) => ( + + dispatch(devicesActions.select(item))}> + + + + + + + + onMenuClick(event.currentTarget, item.id)}> + + + + + {index < list.length - 1 ? : null} + + ))} + + ); +} +const DeviceList = () => { return ( - <> - - {devices.map((device, index, list) => ( - - dispatch(devicesActions.select(device))}> - - - - - - - - handleMenuClick(event, device.id)}> - - - - - {index < list.length - 1 ? : null} - - ))} - - - - - - {t('sharedEdit')} - {t('sharedRemove')} - - - + ); } -- cgit v1.2.3