github.com/stampzilla/stampzilla-go@v2.0.0-rc9+incompatible/nodes/stampzilla-magicmirror/web/src/routes/home/DeviceList.js (about)

     1  import React from 'react'
     2  import moment from 'moment'
     3  import { connect } from 'react-redux'
     4  
     5  class DeviceList extends React.PureComponent {
     6    render() {
     7      const { devices, state } = this.props
     8  
     9      return (
    10        <div class="device-list">
    11          {devices.map(device => {
    12            let value = JSON.stringify(
    13              state.getIn([device.get('device'), 'state', device.get('state')])
    14            )
    15  
    16            if (value && device.get('decimals')) {
    17              value *= Math.pow(10, device.get('decimals'))
    18              value = Math.round(value)
    19              value /= Math.pow(10, device.get('decimals'))
    20              console.log(value)
    21            }
    22  
    23            if (value && device.get('states')) {
    24              value = device.getIn(['states', value])
    25            }
    26  
    27            if (device.get('unit')) {
    28              value = `${value} ${device.get('unit')}`
    29            }
    30  
    31            return (
    32              <div className="device-list-item">
    33                <strong>{value}</strong>
    34                <small>{device.get('title')}</small>
    35              </div>
    36            )
    37          })}
    38        </div>
    39      )
    40    }
    41  }
    42  
    43  const mapStateToProps = state => ({
    44    state: state.getIn(['devices', 'list'])
    45  })
    46  
    47  export default connect(mapStateToProps)(DeviceList)