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 { createPortal } from 'react-dom' import { useGlobalAlertsContainer } from '@/features/ide-react/context/global-alerts-context' import OLNotification from '@/features/ui/components/ol/ol-notification' export function Alerts() { const { t } = useTranslation() const { connectionState, isConnected, isStillReconnecting, tryReconnectNow, secondsUntilReconnect, } = useConnectionContext() const globalAlertsContainer = useGlobalAlertsContainer() if (!globalAlertsContainer) { return null } return createPortal( <> {connectionState.forceDisconnected && // hide "disconnected" banner when displaying out of sync modal connectionState.error !== 'out-of-sync' ? ( {t('disconnected')}} /> ) : null} {connectionState.reconnectAt ? ( ) : null} {isStillReconnecting ? ( {t('reconnecting')}…} /> ) : null} {connectionState.inactiveDisconnect || (connectionState.readyState === WebSocket.CLOSED && (connectionState.error === 'rate-limited' || connectionState.error === 'unable-to-connect') && !secondsUntilReconnect()) ? ( {t('editor_disconected_click_to_reconnect')} } /> ) : null} {debugging ? ( Connected: {isConnected.toString()}} /> ) : null} , globalAlertsContainer ) }