From af6b60f85ba09a9d1a258cf9d1b6b61d4b8e4fe5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 1 May 2022 15:26:08 -0700 Subject: Migrate to a card for popup --- modern/src/map/StatusCard.js | 136 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 modern/src/map/StatusCard.js (limited to 'modern/src/map/StatusCard.js') diff --git a/modern/src/map/StatusCard.js b/modern/src/map/StatusCard.js new file mode 100644 index 00000000..47f7724d --- /dev/null +++ b/modern/src/map/StatusCard.js @@ -0,0 +1,136 @@ +import React, { useState } from 'react'; +import { useSelector } from 'react-redux'; +import { useHistory } from 'react-router-dom'; +import { + makeStyles, Button, Card, CardContent, Typography, CardActions, CardHeader, IconButton, Avatar, Table, TableBody, TableRow, TableCell, TableContainer, +} from '@material-ui/core'; +import CloseIcon from '@material-ui/icons/Close'; +import ReplayIcon from '@material-ui/icons/Replay'; +import ExitToAppIcon from '@material-ui/icons/ExitToApp'; +import EditIcon from '@material-ui/icons/Edit'; +import DeleteIcon from '@material-ui/icons/Delete'; + +import { useTranslation } from '../LocalizationProvider'; +import { formatDistance, formatPosition, formatSpeed, formatStatus } from '../common/formatter'; +import RemoveDialog from '../RemoveDialog'; +import { useAttributePreference } from '../common/preferences'; + +const useStyles = makeStyles((theme) => ({ + paper: { + width: '300px', + }, + negative: { + color: theme.palette.colors.negative, + }, + listItemContainer: { + maxWidth: '240px', + }, + icon: { + width: '25px', + height: '25px', + filter: 'brightness(0) invert(1)', + }, + table: { + '& .MuiTableCell-sizeSmall': { + paddingLeft: theme.spacing(0.5), + paddingRight: theme.spacing(0.5), + }, + }, + cell: { + borderBottom: 'none', + }, +})); + +const StatusRow = ({ name, value }) => { + const classes = useStyles(); + + return ( + + + {name} + + + {value} + + + ); +} + +const StatusCard = ({ deviceId, onClose }) => { + const classes = useStyles(); + const history = useHistory(); + const t = useTranslation(); + + const device = useSelector((state) => state.devices.items[deviceId]); + const position = useSelector((state) => state.positions.items[deviceId]); + + const distanceUnit = useAttributePreference('distanceUnit'); + const speedUnit = useAttributePreference('speedUnit'); + + const [removeDialogShown, setRemoveDialogShown] = useState(false); + + return ( + <> + {device && + + + + + } + action={ + + + + } + title={device.name} + subheader={formatStatus(device.status, t)} + /> + {position && + + + + + + + {position.attributes.odometer + ? + : + } + + +
+
+
+ } + + + history.push('/replay')} disabled={!position}> + + + + + + history.push(`/device/${deviceId}`)}> + + + setRemoveDialogShown(true)} className={classes.negative}> + + + +
+ } + setRemoveDialogShown(false)} + /> + + ); +}; + +export default StatusCard; -- cgit v1.2.3