diff options
author | Anton Tananaev <anton@traccar.org> | 2023-08-19 13:58:45 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-08-19 13:59:07 -0700 |
commit | d3c7705bedebd65c94f9eea691aaf2fe03b0cafe (patch) | |
tree | 5f98b3d9bbbd4fe8067b5a334e84aff008b8db22 /modern/src/other/NetworkPage.jsx | |
parent | 0161ae449d4a7bd0781c0665d663353663ab0faf (diff) | |
download | trackermap-web-d3c7705bedebd65c94f9eea691aaf2fe03b0cafe.tar.gz trackermap-web-d3c7705bedebd65c94f9eea691aaf2fe03b0cafe.tar.bz2 trackermap-web-d3c7705bedebd65c94f9eea691aaf2fe03b0cafe.zip |
Move to Vite
Diffstat (limited to 'modern/src/other/NetworkPage.jsx')
-rw-r--r-- | modern/src/other/NetworkPage.jsx | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/modern/src/other/NetworkPage.jsx b/modern/src/other/NetworkPage.jsx new file mode 100644 index 00000000..9dc00c61 --- /dev/null +++ b/modern/src/other/NetworkPage.jsx @@ -0,0 +1,122 @@ +import React, { useState } from 'react'; +import { useSelector } from 'react-redux'; + +import { + Typography, Container, Paper, AppBar, Toolbar, IconButton, Table, TableHead, TableRow, TableCell, TableBody, +} from '@mui/material'; +import makeStyles from '@mui/styles/makeStyles'; +import ArrowBackIcon from '@mui/icons-material/ArrowBack'; +import { useNavigate, useParams } from 'react-router-dom'; +import { useEffectAsync } from '../reactHelper'; + +const useStyles = makeStyles((theme) => ({ + root: { + height: '100%', + display: 'flex', + flexDirection: 'column', + }, + content: { + overflow: 'auto', + paddingTop: theme.spacing(2), + paddingBottom: theme.spacing(2), + display: 'flex', + flexDirection: 'column', + gap: theme.spacing(2), + }, +})); + +const NetworkPage = () => { + const classes = useStyles(); + const navigate = useNavigate(); + + const { positionId } = useParams(); + + const [item, setItem] = useState({}); + + useEffectAsync(async () => { + if (positionId) { + const response = await fetch(`/api/positions?id=${positionId}`); + if (response.ok) { + const positions = await response.json(); + if (positions.length > 0) { + setItem(positions[0]); + } + } else { + throw Error(await response.text()); + } + } + }, [positionId]); + + const deviceName = useSelector((state) => { + if (item) { + const device = state.devices.items[item.deviceId]; + if (device) { + return device.name; + } + } + return null; + }); + + return ( + <div className={classes.root}> + <AppBar position="sticky" color="inherit"> + <Toolbar> + <IconButton color="inherit" edge="start" sx={{ mr: 2 }} onClick={() => navigate(-1)}> + <ArrowBackIcon /> + </IconButton> + <Typography variant="h6"> + {deviceName} + </Typography> + </Toolbar> + </AppBar> + <div className={classes.content}> + <Container maxWidth="sm"> + <Paper> + <Table> + <TableHead> + <TableRow> + <TableCell>MCC</TableCell> + <TableCell>MNC</TableCell> + <TableCell>LAC</TableCell> + <TableCell>CID</TableCell> + </TableRow> + </TableHead> + <TableBody> + {(item.network?.cellTowers || []).map((cell) => ( + <TableRow key={cell.cellId}> + <TableCell>{cell.mobileCountryCode}</TableCell> + <TableCell>{cell.mobileNetworkCode}</TableCell> + <TableCell>{cell.locationAreaCode}</TableCell> + <TableCell>{cell.cellId}</TableCell> + </TableRow> + ))} + </TableBody> + </Table> + </Paper> + </Container> + <Container maxWidth="sm"> + <Paper> + <Table> + <TableHead> + <TableRow> + <TableCell>MAC</TableCell> + <TableCell>RSSI</TableCell> + </TableRow> + </TableHead> + <TableBody> + {(item.network?.wifiAccessPoints || []).map((wifi) => ( + <TableRow key={wifi.macAddress}> + <TableCell>{wifi.macAddress}</TableCell> + <TableCell>{wifi.signalStrength}</TableCell> + </TableRow> + ))} + </TableBody> + </Table> + </Paper> + </Container> + </div> + </div> + ); +}; + +export default NetworkPage; |