1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-10 18:02:51 +00:00

Starting on sensor stuff

This commit is contained in:
2016-08-28 23:34:18 -05:00
parent 93464d9a66
commit 678755b3ef
3 changed files with 66 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
import React from 'react';
//assest
//components
import SensorList from './sensors/SensorList';
//assets
import me from '../../assets/images/me.jpg';
import '../../assets/scss/Sidebar.scss';
@@ -60,7 +63,7 @@ export default class Sidebar extends React.Component{
<h2>Sensors</h2>
<hr/>
<SensorList/>
</div>
);
}

View File

@@ -0,0 +1,60 @@
import React from 'react';
import 'whatwg-fetch';
export default class SensorList extends React.Component {
constructor(){
super();
this.state = {
sensors : {},
fetching: false,
fetched: false
}
}
componentDidMount(){
this.loadSensorData();
}
loadSensorData(){
this.setState({
fetching: true
});
fetch('/api/allsensors')
.then((response) => {
return response.json()
})
.then((json) => {
this.setState({
sensors: json,
fetching: false,
fetched: true
});
})
.catch((e) => {
console.log('Loading sensors failed', e)
});
}
insertSensorData = (sensor, index) => {
const date = new Date(sensor.updated);
return (
<div key={index}>
<h3>{sensor.location}</h3>
<p>{sensor.temperature}</p>
<p>{date.toString()}</p>
</div>
);
}
render(){
console.log(this.state);
return (
<div>
{this.state.fetched ? this.state.sensors.map(this.insertSensorData) : null}
</div>
)
}
}

View File

@@ -1,5 +1,6 @@
import * as types from "./constants";
import marked from 'marked';
import 'whatwg-fetch';
function initPreview(posts) {
return {