1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-10 09:52:51 +00:00
Files
mywebsite/client/js/components/sensors/SensorList.js
2016-09-18 18:15:30 +00:00

60 lines
1.3 KiB
JavaScript

import React from 'react';
import {browserHistory} from 'react-router';
import 'whatwg-fetch';
import './SensorList.scss';
const options = {
month: 'numeric',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: true
};
export default class SensorList extends React.Component {
constructor(){
super();
this.openLink = this.openLink.bind(this);
}
openLink(location){
browserHistory.push(`/sensor/${location}`);
this.props.toggleOff();
}
insertSensorData = (sensor, index) => {
const date = new Date(sensor.updated);
return (
<div key={index} class="row" onClick={() => {this.openLink(sensor.location)}}>
<div class="temperature">
<h1>{sensor.temperature}°f</h1>
</div>
<div class="info">
<h3>{sensor.location}</h3>
<span class="date">Updated: {date.toLocaleString('en-us', options)}
{Date.now() - date < 420000
? <span class="connected"> Connected</span>
: <span class="disconnected"> Disconnected</span>
}
</span>
</div>
</div>
);
}
render() {
const list = this.props.list;
return (
<div class="SensorList">
<h2>Sensors</h2>
{list.map(this.insertSensorData)}
</div>
)
}
}