The latest test timer is now updated every second

This commit is contained in:
Mathias Wagner
2022-05-08 01:09:14 +02:00
parent 150596b9e1
commit 6da7328c59

View File

@@ -8,6 +8,7 @@ import {DialogContext} from "../context/DialogContext";
function LatestTestComponent() {
const [latest, setLatest] = useState({});
const [latestTestTime, setLatestTestTime] = useState("");
const [setDialog] = useContext(DialogContext);
const config = useContext(ConfigContext);
@@ -15,10 +16,16 @@ function LatestTestComponent() {
let passwordHeaders = localStorage.getItem("password") ? {password: localStorage.getItem("password")} : {}
fetch("/api/speedtests/latest", {headers: passwordHeaders})
.then(res => res.json())
.then(latest => setLatest(latest));
.then(latest => {
setLatest(latest);
setLatestTestTime(generateRelativeTime(latest.created));
});
}, [setLatest]);
setTimeout(() => {
setLatestTestTime(generateRelativeTime(latest.created));
}, 1000);
if (Object.entries(config).length === 0) return (<></>)
return (
@@ -77,7 +84,7 @@ function LatestTestComponent() {
<h2 className="container-text">Letzter Test<span className="container-subtext">vor</span></h2>
</div>
<div className="container-main">
<h2>{generateRelativeTime(latest.created)}</h2>
<h2>{latestTestTime}</h2>
</div>
</div>
</div>