feat(ui): add transient loading indicator
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled

This commit is contained in:
Tom Boullay
2026-05-31 22:43:48 +02:00
parent d26c676edf
commit 51569af7b8
7 changed files with 165 additions and 39 deletions
@@ -0,0 +1,36 @@
import { useCallback, useEffect, useRef, useState } from "react";
const DEFAULT_LOADING_DURATION_MS = 900;
export function useTransientLoadingIndicator(): {
showLoading: (durationMs?: number) => void;
visible: boolean;
} {
const [visible, setVisible] = useState(false);
const timeoutRef = useRef<number | null>(null);
const showLoading = useCallback(
(durationMs = DEFAULT_LOADING_DURATION_MS) => {
if (timeoutRef.current !== null) {
window.clearTimeout(timeoutRef.current);
}
setVisible(true);
timeoutRef.current = window.setTimeout(() => {
setVisible(false);
timeoutRef.current = null;
}, durationMs);
},
[],
);
useEffect(() => {
return () => {
if (timeoutRef.current !== null) {
window.clearTimeout(timeoutRef.current);
}
};
}, []);
return { showLoading, visible };
}