Commit 2890f86a by OuiAtichat

update

parent 485f63e0
...@@ -69,6 +69,9 @@ const Data = [ ...@@ -69,6 +69,9 @@ const Data = [
class Home extends Component { class Home extends Component {
state = { state = {
allDevicesId: null,
allDeviceInfo: null,
currentUid: null,
userToken: null, userToken: null,
kairosUrl: null, kairosUrl: null,
currentUser: null, currentUser: null,
...@@ -104,12 +107,13 @@ class Home extends Component { ...@@ -104,12 +107,13 @@ class Home extends Component {
}; };
async componentDidMount() { async componentDidMount() {
await this.getFireStoreData(); await this.getConfig();
this.getCurrentUser(); await this.getCurrentUser();
this.getAllDevicesInfo();
// await this.getFeedData(); // await this.getFeedData();
} }
getFireStoreData = async () => { getConfig = async () => {
const configData = await db.collection('config').get(); const configData = await db.collection('config').get();
//get all data from collection 'config' //get all data from collection 'config'
configData.forEach(doc => { configData.forEach(doc => {
...@@ -121,8 +125,33 @@ class Home extends Component { ...@@ -121,8 +125,33 @@ class Home extends Component {
}; };
getCurrentUser = async () => { getCurrentUser = async () => {
const { displayName, email } = await app.auth().currentUser; const { displayName, email, uid } = await app.auth().currentUser;
this.setState({ currentUser: displayName || email }); this.setState({
currentUser: displayName || email,
currentUid: uid,
});
};
getAllDevicesInfo = async () => {
const { currentUid } = this.state;
const DevicesId = await db
.collection('membership')
.doc(currentUid)
.get();
// console.log(Object.keys(DevicesId.data()));
// const allDevicesId = Object.keys(DevicesId.data());
// console.log(allDevicesId);
// let allDeviceInfo = [];
// allDevicesId.map(async (deviceId, index) => {
// const deviceInfo = await db
// .collection('device')
// .doc(deviceId)
// .get();
// allDeviceInfo.push(deviceInfo.data());
// });
this.setState({ allDevicesId: Object.keys(DevicesId.data()) });
}; };
getFeedData = async (deviceId, selectedRange, breakdown) => { getFeedData = async (deviceId, selectedRange, breakdown) => {
...@@ -199,7 +228,7 @@ class Home extends Component { ...@@ -199,7 +228,7 @@ class Home extends Component {
getSelectedFeed = selectedFeed => { getSelectedFeed = selectedFeed => {
const { device, range, breakdown } = selectedFeed; const { device, range, breakdown } = selectedFeed;
this.getFeedData(device, range, breakdown); this.getFeedData(device || this.state.allDevicesId[0], range, breakdown);
}; };
getMax = (data) => { getMax = (data) => {
...@@ -256,6 +285,8 @@ class Home extends Component { ...@@ -256,6 +285,8 @@ class Home extends Component {
render() { render() {
const { const {
allDevicesId,
allDeviceInfo,
currentUser, currentUser,
currentFeed, currentFeed,
revenueFeed, revenueFeed,
...@@ -270,7 +301,11 @@ class Home extends Component { ...@@ -270,7 +301,11 @@ class Home extends Component {
<NavBar user={currentUser} /> <NavBar user={currentUser} />
<Container style={{ padding: '30px', maxWidth: '990px' }}> <Container style={{ padding: '30px', maxWidth: '990px' }}>
<Row> <Row>
<GetDataSelection onConfirm={this.getSelectedFeed} /> <GetDataSelection
allDevicesId={allDevicesId}
// allDeviceInfo={allDeviceInfo}
onConfirm={this.getSelectedFeed}
/>
</Row> </Row>
<Row> <Row>
<Mapbox /> <Mapbox />
......
...@@ -4,11 +4,15 @@ import { withRouter } from 'react-router'; ...@@ -4,11 +4,15 @@ import { withRouter } from 'react-router';
import app from '../../firebase'; import app from '../../firebase';
class LogInContainer extends Component { class LogInContainer extends Component {
state = {
membership: null,
};
handleSignUp = async event => { handleSignUp = async event => {
event.preventDefault(); event.preventDefault();
const { email, password } = event.target.elements; const { email, password } = event.target.elements;
try { try {
await app.auth().signInWithEmailAndPassword(email.value, password.value); await app.auth().signInWithEmailAndPassword(email.value, password.value);
this.props.history.push('/'); this.props.history.push('/');
} catch (error) { } catch (error) {
alert(error); alert(error);
......
...@@ -2,10 +2,11 @@ import React, { Component } from 'react'; ...@@ -2,10 +2,11 @@ import React, { Component } from 'react';
import { Col, Form, Button } from 'react-bootstrap'; import { Col, Form, Button } from 'react-bootstrap';
import DateRangeSeletion from './DateRangeSeletion'; import DateRangeSeletion from './DateRangeSeletion';
import moment from 'moment'; import moment from 'moment';
import { db } from '../../firebase';
class GetDataSelection extends Component { class GetDataSelection extends Component {
state = { state = {
device: '3d2951a5-fa10-4d56-abae-bc471f3d2e1f', device: null,
range: { range: {
startDate: moment() startDate: moment()
.subtract(1, 'days') .subtract(1, 'days')
...@@ -13,6 +14,7 @@ class GetDataSelection extends Component { ...@@ -13,6 +14,7 @@ class GetDataSelection extends Component {
endDate: moment().valueOf(), endDate: moment().valueOf(),
}, },
breakdown: 'minutes', breakdown: 'minutes',
allDeviceInfo: null,
}; };
handleClickGo = e => { handleClickGo = e => {
...@@ -23,7 +25,31 @@ class GetDataSelection extends Component { ...@@ -23,7 +25,31 @@ class GetDataSelection extends Component {
this.setState({ range: selectedRange }); this.setState({ range: selectedRange });
}; };
getAllDevicesInfo = () => {
if (this.props.allDevicesId) {
const allDevicesId = this.props.allDevicesId;
let allDeviceInfo = [];
allDevicesId.map(async (deviceId, index) => {
const deviceInfo = await db
.collection('device')
.doc(deviceId)
.get();
allDeviceInfo.push(deviceInfo.data());
});
console.log('allDeviceInfo', allDeviceInfo);
this.setState({ allDeviceInfo });
}
};
componentDidMount = () => {
this.getAllDevicesInfo();
};
render() { render() {
let { allDevicesId } = this.props;
console.log('allDevicesId', allDevicesId);
return ( return (
<Col> <Col>
<Form.Label>Get data from</Form.Label> <Form.Label>Get data from</Form.Label>
...@@ -37,9 +63,14 @@ class GetDataSelection extends Component { ...@@ -37,9 +63,14 @@ class GetDataSelection extends Component {
this.setState({ device: e.target.value }); this.setState({ device: e.target.value });
}} }}
> >
<option value="">Choose...</option> {allDevicesId &&
<option>3d2951a5-fa10-4d56-abae-bc471f3d2e1f</option> allDevicesId.map((deviceId, index) => {
<option>3d2951a5-fa10-4d56-abae-bc471f3d2e12</option> return (
<option key={`option${index}`} value={deviceId}>
{index}
</option>
);
})}
</Form.Control> </Form.Control>
</Col> </Col>
<Col md> <Col md>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment