ConceptPortal-public/rsconcept/frontend/src/app/GlobalLoader.tsx

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-15 17:39:09 +03:00
import { useNavigation } from 'react-router';
2025-02-15 17:11:36 +03:00
import clsx from 'clsx';
2025-02-15 17:39:09 +03:00
import { useDebounce } from 'use-debounce';
2025-02-15 17:11:36 +03:00
import { Loader } from '@/components/Loader';
2025-02-15 17:39:09 +03:00
import { PARAMETER } from '@/utils/constants';
2025-02-15 17:11:36 +03:00
2025-02-17 15:12:15 +03:00
// TODO: add animation
2025-02-15 17:11:36 +03:00
export function GlobalLoader() {
2025-02-15 17:39:09 +03:00
const navigation = useNavigation();
const isLoading = navigation.state === 'loading';
const [loadingDebounced] = useDebounce(isLoading, PARAMETER.navigationPopupDelay);
2025-02-17 15:12:15 +03:00
if (!loadingDebounced) {
2025-02-15 17:39:09 +03:00
return null;
}
2025-02-15 17:11:36 +03:00
return (
<div className='fixed top-0 left-0 w-full h-full z-modal cursor-default'>
<div className={clsx('z-navigation', 'fixed top-0 left-0', 'w-full h-full', 'backdrop-blur-[3px] opacity-50')} />
<div className={clsx('z-navigation', 'fixed top-0 left-0', 'w-full h-full', 'bg-prim-0 opacity-25')} />
<div
className={clsx(
'px-10 mb-10',
'z-modal absolute bottom-1/2 left-1/2 -translate-x-1/2 translate-y-1/2',
'border rounded-xl bg-prim-100'
)}
>
<Loader scale={6} />
</div>
</div>
);
}