2021-10-06 04:33:24 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import Icon from './icon'
|
2022-01-11 04:17:56 -05:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2021-10-06 04:33:24 -04:00
|
|
|
|
2022-04-07 04:58:48 -04:00
|
|
|
function LoadingSpinner({ delay = 0 }) {
|
2021-10-06 04:33:24 -04:00
|
|
|
const { t } = useTranslation()
|
2022-01-11 04:17:56 -05:00
|
|
|
|
|
|
|
const [show, setShow] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const timer = window.setTimeout(() => {
|
|
|
|
setShow(true)
|
|
|
|
}, delay)
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.clearTimeout(timer)
|
|
|
|
}
|
|
|
|
}, [delay])
|
|
|
|
|
|
|
|
if (!show) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-10-06 04:33:24 -04:00
|
|
|
return (
|
|
|
|
<div className="loading">
|
2022-01-19 06:56:57 -05:00
|
|
|
<Icon type="refresh" fw spin />
|
2022-01-11 04:17:56 -05:00
|
|
|
|
|
|
|
{t('loading')}…
|
2021-10-06 04:33:24 -04:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-11 04:17:56 -05:00
|
|
|
LoadingSpinner.propTypes = {
|
|
|
|
delay: PropTypes.number,
|
|
|
|
}
|
|
|
|
|
2021-10-06 04:33:24 -04:00
|
|
|
export default LoadingSpinner
|
2023-10-17 04:41:40 -04:00
|
|
|
|
|
|
|
export function FullSizeLoadingSpinner({
|
|
|
|
delay = 0,
|
|
|
|
minHeight,
|
|
|
|
}: {
|
|
|
|
delay?: number
|
|
|
|
minHeight?: string
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div className="full-size-loading-spinner-container" style={{ minHeight }}>
|
|
|
|
<LoadingSpinner delay={delay} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FullSizeLoadingSpinner.propTypes = {
|
|
|
|
delay: PropTypes.number,
|
|
|
|
minHeight: PropTypes.string,
|
|
|
|
}
|