import React from 'react'
import {CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from 'recharts';
import SensorCardDeck from './SensorCardDeck'
import {SensorDataCollection, ActiveDeviceCollection} from "../../client/main";
import {useTracker} from 'meteor/react-meteor-data';
import { Col, Form, Row, Card, CardDeck } from "react-bootstrap";
import { getAllEspNames } from "../api/espNames";
import moment from 'moment'
export default function Home() {
const deviceId = useTracker(() => {
return ActiveDeviceCollection.find().fetch()[0];
});
const sensorData = useTracker(() => {
if (deviceId === null || deviceId === undefined) {
return [];
} else {
return SensorDataCollection.find({device_id: deviceId.deviceId}, {
sort: {timestamp: -1},
limit: 61
}).fetch().reverse();
}
});
const handleChange = (e) => {
if (e.target.value === "") {
console.log("No device selected!");
} else {
var doc = ActiveDeviceCollection.findOne({deviceId: deviceId.deviceId});
ActiveDeviceCollection.update({_id: doc._id}, {$set: {deviceId: e.target.value}});
}
}
const getLabelFromStamp = (x) => {
return moment(x.timestamp).format("HH:mm");
}
if ((sensorData.length <= 0)) {
return (
Loading!
Please wait...
)
} else {
return (
<>
Devices:
{getAllEspNames().map((espName, index) => {
return
})}
active device: {deviceId.deviceId}
el.temperature !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}>
el.humidity !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}>
el.brightness !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}>
el.moisture !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}>
>
)
}
}