diff options
author | Anton Tananaev <anton@traccar.org> | 2022-05-22 15:55:45 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-05-22 15:55:45 -0700 |
commit | dd18f6264b1a5eb006b4b57951176f7da9cf4fe1 (patch) | |
tree | 19fc46d444890680eeff40dd1059a9f92c723ebe /modern/src/main | |
parent | 729c219369e288a60432f0e7722dae36088c0bda (diff) | |
download | trackermap-web-dd18f6264b1a5eb006b4b57951176f7da9cf4fe1.tar.gz trackermap-web-dd18f6264b1a5eb006b4b57951176f7da9cf4fe1.tar.bz2 trackermap-web-dd18f6264b1a5eb006b4b57951176f7da9cf4fe1.zip |
Reorganize collections
Diffstat (limited to 'modern/src/main')
-rw-r--r-- | modern/src/main/DevicesList.js | 11 | ||||
-rw-r--r-- | modern/src/main/StatusCard.js | 25 |
2 files changed, 23 insertions, 13 deletions
diff --git a/modern/src/main/DevicesList.js b/modern/src/main/DevicesList.js index 6ff08c6a..b80eaf8b 100644 --- a/modern/src/main/DevicesList.js +++ b/modern/src/main/DevicesList.js @@ -21,7 +21,6 @@ import FlashOffIcon from '@material-ui/icons/FlashOff'; import ErrorIcon from '@material-ui/icons/Error'; import { devicesActions } from '../store'; -import EditCollectionView from '../settings/components/EditCollectionView'; import { useEffectAsync } from '../reactHelper'; import { formatAlarm, formatBoolean, formatPercentage, formatStatus, getStatusColor, @@ -139,7 +138,7 @@ const DeviceRow = ({ data, index, style }) => { ); }; -const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { +const DevicesList = ({ filter }) => { const classes = useStyles(); const dispatch = useDispatch(); const listInnerEl = useRef(null); @@ -167,7 +166,7 @@ const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { } else { throw Error(await response.text()); } - }, [updateTimestamp]); + }, []); return ( <AutoSizer className={classes.list}> @@ -177,7 +176,7 @@ const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { width={width} height={height} itemCount={filteredItems.length} - itemData={{ items: filteredItems, onMenuClick }} + itemData={{ items: filteredItems }} itemSize={72} overscanCount={10} innerRef={listInnerEl} @@ -190,8 +189,4 @@ const DeviceView = ({ updateTimestamp, onMenuClick, filter }) => { ); }; -const DevicesList = ({ filter }) => ( - <EditCollectionView content={DeviceView} editPath="/settings/device" endpoint="devices" disableAdd filter={filter} /> -); - export default DevicesList; diff --git a/modern/src/main/StatusCard.js b/modern/src/main/StatusCard.js index b470890e..d23bc8c3 100644 --- a/modern/src/main/StatusCard.js +++ b/modern/src/main/StatusCard.js @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { useSelector } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { makeStyles, Card, CardContent, Typography, CardActions, CardHeader, IconButton, Avatar, Table, TableBody, TableRow, TableCell, TableContainer, @@ -19,6 +19,8 @@ import dimensions from '../common/theme/dimensions'; import { useDeviceReadonly, useReadonly } from '../common/util/permissions'; import usePersistedState from '../common/util/usePersistedState'; import usePositionAttributes from '../common/attributes/usePositionAttributes'; +import { devicesActions } from '../store'; +import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ card: { @@ -64,6 +66,7 @@ const StatusRow = ({ name, content }) => { const StatusCard = ({ deviceId, onClose }) => { const classes = useStyles(); const history = useHistory(); + const dispatch = useDispatch(); const t = useTranslation(); const readonly = useReadonly(); @@ -75,7 +78,19 @@ const StatusCard = ({ deviceId, onClose }) => { const positionAttributes = usePositionAttributes(t); const [positionItems] = usePersistedState('positionItems', ['speed', 'address', 'totalDistance', 'course']); - const [removeDialogShown, setRemoveDialogShown] = useState(false); + const [removing, setRemoving] = useState(false); + + const handleRemove = useCatch(async (removed) => { + if (removed) { + const response = await fetch('/api/devices'); + if (response.ok) { + dispatch(devicesActions.refresh(await response.json())); + } else { + throw Error(await response.text()); + } + } + setRemoving(false); + }); return ( <> @@ -131,17 +146,17 @@ const StatusCard = ({ deviceId, onClose }) => { <IconButton onClick={() => history.push(`/settings/device/${deviceId}`)} disabled={deviceReadonly}> <EditIcon /> </IconButton> - <IconButton onClick={() => setRemoveDialogShown(true)} disabled={deviceReadonly} className={classes.negative}> + <IconButton onClick={() => setRemoving(true)} disabled={deviceReadonly} className={classes.negative}> <DeleteIcon /> </IconButton> </CardActions> </Card> )} <RemoveDialog - open={removeDialogShown} + open={removing} endpoint="devices" itemId={deviceId} - onResult={() => setRemoveDialogShown(false)} + onResult={(removed) => handleRemove(removed)} /> </> ); |