diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-22 23:07:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 23:07:16 -0700 |
commit | 48a726021f5d3c741749094891d529ccb3ba59b4 (patch) | |
tree | 8df80eca54f9dd39664f63365ffcc2ec248fb3df /modern/src/DeviceList.js | |
parent | f5165c8e897e8d9cf4219d943e2d34b61adb48b5 (diff) | |
parent | ba9cc86f667486a09edb323402c2d63ada5ea639 (diff) | |
download | trackermap-web-48a726021f5d3c741749094891d529ccb3ba59b4.tar.gz trackermap-web-48a726021f5d3c741749094891d529ccb3ba59b4.tar.bz2 trackermap-web-48a726021f5d3c741749094891d529ccb3ba59b4.zip |
Merge pull request #768 from traccar/modern
Create a new React web app
Diffstat (limited to 'modern/src/DeviceList.js')
-rw-r--r-- | modern/src/DeviceList.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/modern/src/DeviceList.js b/modern/src/DeviceList.js new file mode 100644 index 00000000..03c5126c --- /dev/null +++ b/modern/src/DeviceList.js @@ -0,0 +1,52 @@ +import React, { Component, Fragment } from 'react'; +import { connect } from 'react-redux'; +import List from '@material-ui/core/List'; +import ListItem from '@material-ui/core/ListItem'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; +import ListItemText from '@material-ui/core/ListItemText'; +import Avatar from '@material-ui/core/Avatar'; +import LocationOnIcon from '@material-ui/icons/LocationOn'; +import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; +import IconButton from '@material-ui/core/IconButton'; +import MoreVertIcon from '@material-ui/icons/MoreVert'; +import Divider from '@material-ui/core/Divider'; +import { selectDevice } from './actions'; + +const mapStateToProps = state => ({ + devices: Array.from(state.devices.values()) +}); + +class DeviceList extends Component { + handleClick(device) { + this.props.dispatch(selectDevice(device)); + } + + render() { + const devices = this.props.devices.map((device, index, list) => + <Fragment key={device.id.toString()}> + <ListItem button onClick={(e) => this.handleClick(device)}> + <ListItemAvatar> + <Avatar> + <LocationOnIcon /> + </Avatar> + </ListItemAvatar> + <ListItemText primary={device.name} secondary={device.uniqueId} /> + <ListItemSecondaryAction> + <IconButton> + <MoreVertIcon /> + </IconButton> + </ListItemSecondaryAction> + </ListItem> + {index < list.length - 1 ? <Divider /> : null} + </Fragment> + ); + + return ( + <List> + {devices} + </List> + ); + } +} + +export default connect(mapStateToProps)(DeviceList); |