mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
87199c80fe
Add connection and SyncTex alerts GitOrigin-RevId: 5004a0d356d0a0355d125516a18db1f57e617a7f
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { useTranslation } from 'react-i18next'
|
|
import { useEffect, useState } from 'react'
|
|
import { secondsUntil } from '@/features/ide-react/connection/utils'
|
|
import { Alert } from 'react-bootstrap'
|
|
|
|
type LostConnectionAlertProps = {
|
|
reconnectAt: number
|
|
tryReconnectNow: () => void
|
|
}
|
|
|
|
export function LostConnectionAlert({
|
|
reconnectAt,
|
|
tryReconnectNow,
|
|
}: LostConnectionAlertProps) {
|
|
const { t } = useTranslation()
|
|
const [secondsUntilReconnect, setSecondsUntilReconnect] = useState(
|
|
secondsUntil(reconnectAt)
|
|
)
|
|
|
|
useEffect(() => {
|
|
const timer = window.setInterval(() => {
|
|
setSecondsUntilReconnect(secondsUntil(reconnectAt))
|
|
}, 1000)
|
|
return () => window.clearInterval(timer)
|
|
}, [reconnectAt])
|
|
|
|
return (
|
|
<Alert bsStyle="warning" className="small">
|
|
<strong>{t('lost_connection')}</strong>{' '}
|
|
{t('reconnecting_in_x_secs', { seconds: secondsUntilReconnect })}.
|
|
<button
|
|
id="try-reconnect-now-button"
|
|
className="pull-right"
|
|
onClick={() => tryReconnectNow()}
|
|
>
|
|
{t('try_now')}
|
|
</button>
|
|
</Alert>
|
|
)
|
|
}
|