From de60d08d8eab359634da51456016eaddf2ee9a74 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 9 Apr 2022 23:17:57 +0200 Subject: [PATCH] Created the test area component --- client/src/components/TestAreaComponent.js | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 client/src/components/TestAreaComponent.js diff --git a/client/src/components/TestAreaComponent.js b/client/src/components/TestAreaComponent.js new file mode 100644 index 00000000..9ecbb758 --- /dev/null +++ b/client/src/components/TestAreaComponent.js @@ -0,0 +1,38 @@ +import {useContext, useEffect, useState} from "react"; +import Speedtest from "./SpeedtestComponent"; +import {getIconBySpeed} from "../HelperFunctions"; +import {ConfigContext} from "../context/ConfigContext"; + +function TestArea() { + const config = useContext(ConfigContext); + const [tests, setTests] = useState([]); + + useEffect(() => { + let passwordHeaders = localStorage.getItem("password") ? {password: localStorage.getItem("password")} : {} + fetch("/api/speedtests", {headers: passwordHeaders}) + .then(res => res.json()) + .then(tests => setTests(tests)); + }, [setTests]); + + if (Object.entries(config).length === 0) return (<>) + + return ( +
+
+ {tests.map ? tests.map(test => { + let date = new Date(Date.parse(test.created)); + let timeString = String(date.getHours()).padStart(2, '0') + ":" + String(date.getMinutes()).padStart(2, '0'); + return + }) : ""} +
+
+ ); +} + +export default TestArea; \ No newline at end of file