overleaf/services/web/frontend/js/shared/components/loading-spinner.js
June Kelly dc6f480843 Merge pull request #7275 from overleaf/ds-shared-loading-spinner-2
Changed LoadingSpinner default delay

GitOrigin-RevId: 2bf499585e3394e5c6b8ed9583add7ef6f678fc1
2022-04-07 09:56:57 +00:00

38 lines
702 B
JavaScript

import { useTranslation } from 'react-i18next'
import Icon from './icon'
import { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
function LoadingSpinner({ delay = 0 }) {
const { t } = useTranslation()
const [show, setShow] = useState(false)
useEffect(() => {
const timer = window.setTimeout(() => {
setShow(true)
}, delay)
return () => {
window.clearTimeout(timer)
}
}, [delay])
if (!show) {
return null
}
return (
<div className="loading">
<Icon type="refresh" fw spin />
&nbsp;
{t('loading')}
</div>
)
}
LoadingSpinner.propTypes = {
delay: PropTypes.number,
}
export default LoadingSpinner