From d3a027a92958371acaf35d300770a4c864df7231 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 21 Jun 2020 17:42:00 -0700 Subject: Implement device removal --- modern/src/DeviceList.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'modern/src/DeviceList.js') diff --git a/modern/src/DeviceList.js b/modern/src/DeviceList.js index b047826..5e09041 100644 --- a/modern/src/DeviceList.js +++ b/modern/src/DeviceList.js @@ -34,6 +34,7 @@ const useStyles = makeStyles(theme => ({ })); 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)); @@ -41,7 +42,8 @@ const DeviceList = () => { const classes = useStyles(); const history = useHistory(); - const handleMenuClick = (event) => { + const handleMenuClick = (event, deviceId) => { + setMenuDeviceId(deviceId); setMenuAnchorEl(event.currentTarget); } @@ -50,7 +52,7 @@ const DeviceList = () => { } const handleMenuEdit = () => { - history.push('/device'); + history.push(`/device/${menuDeviceId}`); handleMenuClose(); } @@ -59,6 +61,18 @@ const DeviceList = () => { handleMenuClose(); } + const handleAdd = () => { + history.push('/device'); + handleMenuClose(); + } + + const handleRemoveResult = (removed) => { + setRemoveDialogOpen(false); + if (removed) { + dispatch(devicesActions.remove(menuDeviceId)); + } + } + return ( <> @@ -72,27 +86,25 @@ const DeviceList = () => { - + handleMenuClick(event, device.id)}> {index < list.length - 1 ? : null} - )) - } + ))} - + {t('sharedEdit')} {t('sharedRemove')} - { setRemoveDialogOpen(false) }} /> + ); } export default DeviceList; - -- cgit v1.2.3