alerts.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { useTranslation } from 'react-i18next'
  2. import { LostConnectionAlert } from './lost-connection-alert'
  3. import { useConnectionContext } from '@/features/ide-react/context/connection-context'
  4. import { debugging } from '@/utils/debugging'
  5. import { Alert } from 'react-bootstrap'
  6. import useScopeValue from '@/shared/hooks/use-scope-value'
  7. export function Alerts() {
  8. const { t } = useTranslation()
  9. const {
  10. connectionState,
  11. isConnected,
  12. isStillReconnecting,
  13. tryReconnectNow,
  14. secondsUntilReconnect,
  15. } = useConnectionContext()
  16. const [synctexError] = useScopeValue('sync_tex_error')
  17. return (
  18. <div className="global-alerts">
  19. {connectionState.forceDisconnected ? (
  20. <Alert bsStyle="danger" className="small">
  21. <strong>{t('disconnected')}</strong>
  22. </Alert>
  23. ) : null}
  24. {connectionState.reconnectAt ? (
  25. <LostConnectionAlert
  26. reconnectAt={connectionState.reconnectAt}
  27. tryReconnectNow={tryReconnectNow}
  28. />
  29. ) : null}
  30. {isStillReconnecting ? (
  31. <Alert bsStyle="warning" className="small">
  32. <strong>{t('reconnecting')}…</strong>
  33. </Alert>
  34. ) : null}
  35. {synctexError ? (
  36. <Alert bsStyle="warning" className="small">
  37. <strong>{t('synctex_failed')}</strong>
  38. <a
  39. href="/learn/how-to/SyncTeX_Errors"
  40. target="_blank"
  41. id="synctex-more-info-button"
  42. className="alert-link-as-btn pull-right"
  43. >
  44. {t('more_info')}
  45. </a>
  46. </Alert>
  47. ) : null}
  48. {connectionState.inactiveDisconnect ||
  49. (connectionState.readyState === WebSocket.CLOSED &&
  50. (connectionState.error === 'rate-limited' ||
  51. connectionState.error === 'unable-to-connect') &&
  52. !secondsUntilReconnect()) ? (
  53. <Alert bsStyle="warning" className="small">
  54. <strong>{t('editor_disconected_click_to_reconnect')}</strong>
  55. </Alert>
  56. ) : null}
  57. {debugging ? (
  58. <Alert bsStyle="warning" className="small">
  59. <strong>Connected: {isConnected.toString()}</strong>
  60. </Alert>
  61. ) : null}
  62. </div>
  63. )
  64. }