fix(web): fix system status card stuck in loading state

fetchStatus(showLoading=false) never called setLoading(false), so the
initial loading=true was never cleared. Simplify to always setLoading
in the finally block — the spinner only shows on the very first load
since subsequent fetches complete near-instantly.
This commit is contained in:
Junyan Qin
2026-04-19 14:33:12 +08:00
committed by WangCham
parent e0510bca6b
commit dfd4ab791e

View File

@@ -43,8 +43,7 @@ export default function SystemStatusCard({
const [boxStatus, setBoxStatus] = useState<ApiRespBoxStatus | null>(null);
const [loading, setLoading] = useState(true);
const fetchStatus = useCallback(async (showLoading = false) => {
if (showLoading) setLoading(true);
const fetchStatus = useCallback(async () => {
try {
const [plugin, box] = await Promise.all([
httpClient.getPluginSystemStatus().catch(() => null),
@@ -53,14 +52,13 @@ export default function SystemStatusCard({
setPluginStatus(plugin);
setBoxStatus(box);
} finally {
if (showLoading) setLoading(false);
setLoading(false);
}
}, []);
useEffect(() => {
// refreshKey changes when the user clicks "Refresh Data"
fetchStatus(refreshKey === undefined);
const interval = setInterval(() => fetchStatus(false), 30_000);
fetchStatus();
const interval = setInterval(fetchStatus, 30_000);
return () => clearInterval(interval);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchStatus, refreshKey]);
@@ -90,7 +88,7 @@ export default function SystemStatusCard({
return (
<Popover
onOpenChange={(open) => {
if (open) fetchStatus(false);
if (open) fetchStatus();
}}
>
<PopoverTrigger asChild>