2021-10-06 04:33:24 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2022-01-11 04:17:56 -05:00
|
|
|
import { useEffect, useState } from 'react'
|
2024-10-14 04:00:41 -04:00
|
|
|
import OLSpinner, {
|
|
|
|
OLSpinnerSize,
|
|
|
|
} from '@/features/ui/components/ol/ol-spinner'
|
|
|
|
import { isBootstrap5 } from '@/features/utils/bootstrap-5'
|
2024-10-11 05:51:02 -04:00
|
|
|
import { setTimeout } from '@/utils/window'
|
2024-10-11 05:22:38 -04:00
|
|
|
import classNames from 'classnames'
|
2021-10-06 04:33:24 -04:00
|
|
|
|
2024-02-06 10:19:37 -05:00
|
|
|
function LoadingSpinner({
|
2024-10-11 05:22:38 -04:00
|
|
|
align,
|
2024-02-06 10:19:37 -05:00
|
|
|
delay = 0,
|
|
|
|
loadingText,
|
2024-10-14 04:00:41 -04:00
|
|
|
size = 'sm',
|
|
|
|
className,
|
2024-02-06 10:19:37 -05:00
|
|
|
}: {
|
2024-10-11 05:22:38 -04:00
|
|
|
align?: 'left' | 'center'
|
2024-02-06 10:19:37 -05:00
|
|
|
delay?: 0 | 500 // 500 is our standard delay
|
|
|
|
loadingText?: string
|
2024-10-14 04:00:41 -04:00
|
|
|
size?: OLSpinnerSize
|
|
|
|
className?: string
|
2024-02-06 10:19:37 -05:00
|
|
|
}) {
|
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(() => {
|
2024-10-11 05:51:02 -04:00
|
|
|
const timer = setTimeout(() => {
|
2022-01-11 04:17:56 -05:00
|
|
|
setShow(true)
|
|
|
|
}, delay)
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.clearTimeout(timer)
|
|
|
|
}
|
|
|
|
}, [delay])
|
|
|
|
|
|
|
|
if (!show) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2024-10-14 04:00:41 -04:00
|
|
|
const extraClasses = isBootstrap5()
|
2024-10-23 09:21:00 -04:00
|
|
|
? [align === 'left' ? 'align-items-start' : 'align-items-center']
|
2024-10-14 04:00:41 -04:00
|
|
|
: null
|
2024-10-11 05:22:38 -04:00
|
|
|
|
2021-10-06 04:33:24 -04:00
|
|
|
return (
|
2024-10-14 04:00:41 -04:00
|
|
|
<div className={classNames('loading', className, extraClasses)}>
|
|
|
|
<OLSpinner size={size} />
|
|
|
|
|
|
|
|
{loadingText || t('loading')}…
|
|
|
|
</div>
|
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,
|
2024-02-06 10:19:37 -05:00
|
|
|
loadingText,
|
2024-10-14 04:00:41 -04:00
|
|
|
size = 'sm',
|
2023-10-17 04:41:40 -04:00
|
|
|
}: {
|
2024-02-06 10:19:37 -05:00
|
|
|
delay?: 0 | 500
|
2023-10-17 04:41:40 -04:00
|
|
|
minHeight?: string
|
2024-02-06 10:19:37 -05:00
|
|
|
loadingText?: string
|
2024-10-14 04:00:41 -04:00
|
|
|
size?: OLSpinnerSize
|
2023-10-17 04:41:40 -04:00
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div className="full-size-loading-spinner-container" style={{ minHeight }}>
|
2024-10-14 04:00:41 -04:00
|
|
|
<LoadingSpinner size={size} loadingText={loadingText} delay={delay} />
|
2023-10-17 04:41:40 -04:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|