2023-10-18 05:14:58 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { LostConnectionAlert } from './lost-connection-alert'
|
|
|
|
import { useConnectionContext } from '@/features/ide-react/context/connection-context'
|
|
|
|
import { debugging } from '@/utils/debugging'
|
|
|
|
import { Alert } from 'react-bootstrap'
|
2023-10-26 04:57:00 -04:00
|
|
|
import useScopeValue from '@/shared/hooks/use-scope-value'
|
2024-01-03 06:12:50 -05:00
|
|
|
import { createPortal } from 'react-dom'
|
|
|
|
import { useGlobalAlertsContainer } from '@/features/ide-react/context/global-alerts-context'
|
2023-10-18 05:14:58 -04:00
|
|
|
|
|
|
|
export function Alerts() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const {
|
|
|
|
connectionState,
|
|
|
|
isConnected,
|
|
|
|
isStillReconnecting,
|
|
|
|
tryReconnectNow,
|
|
|
|
secondsUntilReconnect,
|
|
|
|
} = useConnectionContext()
|
2024-01-03 06:12:50 -05:00
|
|
|
const globalAlertsContainer = useGlobalAlertsContainer()
|
2023-10-18 05:14:58 -04:00
|
|
|
|
2023-10-26 04:57:00 -04:00
|
|
|
const [synctexError] = useScopeValue('sync_tex_error')
|
2023-10-18 05:14:58 -04:00
|
|
|
|
2024-01-03 06:12:50 -05:00
|
|
|
if (!globalAlertsContainer) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return createPortal(
|
|
|
|
<>
|
2023-10-18 05:14:58 -04:00
|
|
|
{connectionState.forceDisconnected ? (
|
2023-11-06 08:11:06 -05:00
|
|
|
<Alert bsStyle="danger" className="small">
|
2023-10-18 05:14:58 -04:00
|
|
|
<strong>{t('disconnected')}</strong>
|
|
|
|
</Alert>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{connectionState.reconnectAt ? (
|
|
|
|
<LostConnectionAlert
|
|
|
|
reconnectAt={connectionState.reconnectAt}
|
|
|
|
tryReconnectNow={tryReconnectNow}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{isStillReconnecting ? (
|
|
|
|
<Alert bsStyle="warning" className="small">
|
|
|
|
<strong>{t('reconnecting')}…</strong>
|
|
|
|
</Alert>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{synctexError ? (
|
|
|
|
<Alert bsStyle="warning" className="small">
|
|
|
|
<strong>{t('synctex_failed')}</strong>
|
|
|
|
<a
|
|
|
|
href="/learn/how-to/SyncTeX_Errors"
|
|
|
|
target="_blank"
|
|
|
|
id="synctex-more-info-button"
|
|
|
|
className="alert-link-as-btn pull-right"
|
|
|
|
>
|
|
|
|
{t('more_info')}
|
|
|
|
</a>
|
|
|
|
</Alert>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{connectionState.inactiveDisconnect ||
|
|
|
|
(connectionState.readyState === WebSocket.CLOSED &&
|
|
|
|
(connectionState.error === 'rate-limited' ||
|
|
|
|
connectionState.error === 'unable-to-connect') &&
|
|
|
|
!secondsUntilReconnect()) ? (
|
|
|
|
<Alert bsStyle="warning" className="small">
|
|
|
|
<strong>{t('editor_disconected_click_to_reconnect')}</strong>
|
|
|
|
</Alert>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{debugging ? (
|
|
|
|
<Alert bsStyle="warning" className="small">
|
|
|
|
<strong>Connected: {isConnected.toString()}</strong>
|
|
|
|
</Alert>
|
|
|
|
) : null}
|
2024-01-03 06:12:50 -05:00
|
|
|
</>,
|
|
|
|
globalAlertsContainer
|
2023-10-18 05:14:58 -04:00
|
|
|
)
|
|
|
|
}
|