mirror of
https://github.com/MAKS-IT-COM/maksit-certs-ui.git
synced 2025-12-31 04:00:03 +01:00
41 lines
908 B
TypeScript
41 lines
908 B
TypeScript
// components/Loader.tsx
|
|
import React, { useEffect } from 'react'
|
|
import { useSelector, useDispatch } from 'react-redux'
|
|
import { RootState } from '@/redux/store'
|
|
import { reset } from '@/redux/slices/loaderSlice'
|
|
import './loader.css'
|
|
|
|
const Loader: React.FC = () => {
|
|
const dispatch = useDispatch()
|
|
const activeRequests = useSelector(
|
|
(state: RootState) => state.loader.activeRequests
|
|
)
|
|
|
|
useEffect(() => {
|
|
let timeout: NodeJS.Timeout | null = null
|
|
if (activeRequests > 0) {
|
|
timeout = setTimeout(() => {
|
|
dispatch(reset())
|
|
}, 120000) // Adjust the timeout as necessary
|
|
}
|
|
|
|
return () => {
|
|
if (timeout) {
|
|
clearTimeout(timeout)
|
|
}
|
|
}
|
|
}, [activeRequests, dispatch])
|
|
|
|
if (activeRequests === 0) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div className="loader-overlay">
|
|
<span className="loader"></span>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export { Loader }
|