mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-19 19:06:07 +00:00
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:
@@ -43,8 +43,7 @@ export default function SystemStatusCard({
|
|||||||
const [boxStatus, setBoxStatus] = useState<ApiRespBoxStatus | null>(null);
|
const [boxStatus, setBoxStatus] = useState<ApiRespBoxStatus | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const fetchStatus = useCallback(async (showLoading = false) => {
|
const fetchStatus = useCallback(async () => {
|
||||||
if (showLoading) setLoading(true);
|
|
||||||
try {
|
try {
|
||||||
const [plugin, box] = await Promise.all([
|
const [plugin, box] = await Promise.all([
|
||||||
httpClient.getPluginSystemStatus().catch(() => null),
|
httpClient.getPluginSystemStatus().catch(() => null),
|
||||||
@@ -53,14 +52,13 @@ export default function SystemStatusCard({
|
|||||||
setPluginStatus(plugin);
|
setPluginStatus(plugin);
|
||||||
setBoxStatus(box);
|
setBoxStatus(box);
|
||||||
} finally {
|
} finally {
|
||||||
if (showLoading) setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// refreshKey changes when the user clicks "Refresh Data"
|
fetchStatus();
|
||||||
fetchStatus(refreshKey === undefined);
|
const interval = setInterval(fetchStatus, 30_000);
|
||||||
const interval = setInterval(() => fetchStatus(false), 30_000);
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [fetchStatus, refreshKey]);
|
}, [fetchStatus, refreshKey]);
|
||||||
@@ -90,7 +88,7 @@ export default function SystemStatusCard({
|
|||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (open) fetchStatus(false);
|
if (open) fetchStatus();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
|
|||||||
Reference in New Issue
Block a user