handel interval onlyShowAvaliable

This commit is contained in:
2022-05-22 18:55:49 +08:00
parent 25c556ea44
commit 6aee86182e

View File

@@ -141,8 +141,6 @@ export default function Time(props) {
}; };
const refreshRanges = () => { const refreshRanges = () => {
getLimit();
getStats();
fetch(`${prefix}/api/time/ranges`) fetch(`${prefix}/api/time/ranges`)
.then((res) => res.json()) .then((res) => res.json())
.then((res) => { .then((res) => {
@@ -224,11 +222,17 @@ export default function Time(props) {
useEffect(() => { useEffect(() => {
refreshRanges(); refreshRanges();
getLimit();
getStats();
const interval = setInterval(() => { const interval = setInterval(() => {
getLimit();
getStats();
if (!onlyShowAvaliable) {
refreshRanges(); refreshRanges();
}
}, 1000); }, 1000);
return () => clearInterval(interval); return () => clearInterval(interval);
}, []); }, [onlyShowAvaliable]);
/* /*
useEffect(() => { useEffect(() => {
@@ -357,7 +361,7 @@ export default function Time(props) {
</TableHead> </TableHead>
<TableBody> <TableBody>
{ranges.map((range) => { {ranges.map((range) => {
if (onlyShowAvaliable && range.name === "") { if (onlyShowAvaliable && range.username !== "") {
return; return;
} }
return ( return (