import { useEffect, useState } from 'react'; import { Backdrop, Box, CircularProgress, LinearProgress, Paper, Typography } from '@mui/material'; import { useActivity } from '@/api/activity'; import { useUi } from '@/i18n/useUi'; /** True only after `active` has been continuously true for `delay` ms (so quick calls never flash). */ export function useDelayed(active: boolean, delay: number): boolean { const [on, setOn] = useState(false); useEffect(() => { if (!active) { setOn(false); return; } const id = window.setTimeout(() => setOn(true), delay); return () => window.clearTimeout(id); }, [active, delay]); return on; } /** Slim global progress bar for any fetch, shown after a 250 ms delay. */ export function GlobalProgress() { const { reads, writes } = useActivity(); const show = useDelayed(reads + writes > 0, 250); if (!show) return null; return ( t.zIndex.tooltip + 20 }} /> ); } /** Blocking "Saving..." card for writes; also prevents double submits. */ export function SavingOverlay() { const { writes } = useActivity(); const { t } = useUi(); return ( 0} sx={{ zIndex: (th) => th.zIndex.modal + 20, color: 'text.primary', backgroundColor: 'rgba(0,0,0,0.35)' }}> {t('busy.saving')} {t('busy.savingHint')} ); }