mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-11 02:12:53 +00:00
Starting on sensor stuff
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
//assest
|
//components
|
||||||
|
import SensorList from './sensors/SensorList';
|
||||||
|
|
||||||
|
//assets
|
||||||
import me from '../../assets/images/me.jpg';
|
import me from '../../assets/images/me.jpg';
|
||||||
import '../../assets/scss/Sidebar.scss';
|
import '../../assets/scss/Sidebar.scss';
|
||||||
|
|
||||||
@@ -60,7 +63,7 @@ export default class Sidebar extends React.Component{
|
|||||||
|
|
||||||
<h2>Sensors</h2>
|
<h2>Sensors</h2>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
<SensorList/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
60
client/js/components/sensors/SensorList.js
Normal file
60
client/js/components/sensors/SensorList.js
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as types from "./constants";
|
import * as types from "./constants";
|
||||||
import marked from 'marked';
|
import marked from 'marked';
|
||||||
|
import 'whatwg-fetch';
|
||||||
|
|
||||||
function initPreview(posts) {
|
function initPreview(posts) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user