mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-02-05 04:58:34 -06:00
The latest test timer is now updated every second
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user