From f9c054c62b7418b126d79ac40d7ceb18610f64d6 Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Thu, 3 Aug 2023 00:27:26 +0530 Subject: [PATCH] calibration --- src/components/Calibrations.css | 0 src/components/Calibrations.js | 81 +++++++++++++++++++++++++++++++++ src/index.js | 5 ++ 3 files changed, 86 insertions(+) create mode 100644 src/components/Calibrations.css create mode 100644 src/components/Calibrations.js diff --git a/src/components/Calibrations.css b/src/components/Calibrations.css new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Calibrations.js b/src/components/Calibrations.js new file mode 100644 index 0000000..37a1c41 --- /dev/null +++ b/src/components/Calibrations.js @@ -0,0 +1,81 @@ +import React, { useEffect, useState } from 'react'; +import { query, collection, onSnapshot } from 'firebase/firestore'; +import Dropdown from 'react-dropdown'; +import 'react-dropdown/style.css'; +import moment from 'moment'; + +import db from '../firebase'; +import './Calibrations.css'; + +const Calibrations = () => { + const [device, setDevice] = useState("Select a device"); + const [devices, setDevices] = useState([]); + const [curDeviceData, setCurDeviceData] = useState(null); + + const changeDevice = ({ value }) => { + setDevice(value); + } + + const toggleShowDevice = () => { + console.log(devices.filter(x => x.deviceId === device)) + setCurDeviceData(devices.find(x => x.deviceId === device)); + // if (!device) { + // setCurDeviceData(devices.filter(x => x.deviceId === device)); + // } else { + // setDevice(null); + // } + } + + useEffect(() => { + if (!devices?.length) { + const q = query(collection(db, "devices")); + + const unsub = onSnapshot(q, (querySnapshot) => { + const testDevices = []; + querySnapshot.forEach((document) => { + const deviceData = document.data(); + testDevices.push(deviceData); + }); + setDevices(testDevices); + }); + + return () => unsub; + } + }, [device, curDeviceData]); + + return ( +
+
Calibrations
+
+ x.deviceId)} onChange={changeDevice} value={device} placeholder="Select an device" /> + {/* { return { value: x, label: x }; })} menuPlacement='auto' maxMenuHeight={250} menuShouldScrollIntoView={true} onChange={changeTestDate} /> +