1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 10:52:47 +00:00

handling sensors with redux

This commit is contained in:
2016-09-05 18:27:52 +00:00
parent be5e95b6cf
commit 0e8d2e5b2b
15 changed files with 200 additions and 69 deletions

View File

@@ -21,13 +21,13 @@ export default class Post extends React.Component {
componentDidMount() {
const params = this.props.params;
this.props.actions.fetchPost(params.category, params.post);
this.props.appActions.fetchPost(params.category, params.post);
}
render() {
const post = this.props.redux.post;
const fetched = this.props.redux.fetched;
const fetching = this.props.redux.fetching;
const post = this.props.app.post;
const fetched = this.props.app.fetched;
const fetching = this.props.app.fetching;
return (
<div class="Content">

View File

@@ -9,12 +9,12 @@ import '../../assets/scss/Content.scss';
export default class Preview extends React.Component {
componentDidMount() {
this.props.actions.fetchPreview();
this.props.appActions.fetchPreview();
}
insertPosts(posts) {
let elements = [];
for (let i = 0; i < this.props.redux.postLimit && i < posts.length; i++) {
for (let i = 0; i < this.props.app.postLimit && i < posts.length; i++) {
elements.push(
<div class="post" key={i}>
<div class="date">
@@ -34,10 +34,10 @@ export default class Preview extends React.Component {
}
render() {
const posts = this.props.redux.preview.posts;
const postLimit = this.props.redux.postLimit;
const increasePostLimit = this.props.actions.increasePostLimit;
const fetched = this.props.redux.fetched;
const posts = this.props.app.preview.posts;
const postLimit = this.props.app.postLimit;
const fetched = this.props.app.fetched;
const increasePostLimit = this.props.appActions.increasePostLimit;
return (
<div class="Content">

View File

@@ -63,7 +63,7 @@ export default class Sidebar extends React.Component {
<h2>Sensors</h2>
<hr/>
<SensorList/>
{this.props.sensor.fetchedList ? <SensorList list={this.props.sensor.list}/> : null}
</div>
);
}

View File

@@ -2,10 +2,13 @@ import React from 'react';
export default class SensorInfo extends React.Component{
componentDidMount(){
this.props.sensorActions.fetchSensorInfoYear('Grand Meadow', '2016');
this.props.sensorActions.fetchSensorInfoMonth('Grand Meadow', '2016', 'May');
}
render(){
return(
<div>Test123</div>
<div class="Content">Test123</div>
);
}
}

View File

@@ -3,41 +3,6 @@ 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);
@@ -50,9 +15,11 @@ export default class SensorList extends React.Component {
);
}
render() {
const list = this.props.list;
return (
<div>
{this.state.fetched ? this.state.sensors.map(this.insertSensorData) : null}
{list.map(this.insertSensorData)}
</div>
)
}