alerts.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // TODO SavingNotificationController, SystemMessagesController, out-of-sync modal
  7. export function Alerts() {
  8. const { t } = useTranslation()
  9. const {
  10. connectionState,
  11. isConnected,
  12. isStillReconnecting,
  13. tryReconnectNow,
  14. secondsUntilReconnect,
  15. } = useConnectionContext()
  16. // TODO: Get this from a context
  17. const synctexError = false
  18. return (
  19. <div className="global-alerts">
  20. {connectionState.forceDisconnected ? (
  21. <Alert bsStyle="warning" className="small">
  22. <strong>{t('disconnected')}</strong>
  23. </Alert>
  24. ) : null}
  25. {connectionState.reconnectAt ? (
  26. <LostConnectionAlert
  27. reconnectAt={connectionState.reconnectAt}
  28. tryReconnectNow={tryReconnectNow}
  29. />
  30. ) : null}
  31. {isStillReconnecting ? (
  32. <Alert bsStyle="warning" className="small">
  33. <strong>{t('reconnecting')}…</strong>
  34. </Alert>
  35. ) : null}
  36. {synctexError ? (
  37. <Alert bsStyle="warning" className="small">
  38. <strong>{t('synctex_failed')}</strong>
  39. <a
  40. href="/learn/how-to/SyncTeX_Errors"
  41. target="_blank"
  42. id="synctex-more-info-button"
  43. className="alert-link-as-btn pull-right"
  44. >
  45. {t('more_info')}
  46. </a>
  47. </Alert>
  48. ) : null}
  49. {connectionState.inactiveDisconnect ||
  50. (connectionState.readyState === WebSocket.CLOSED &&
  51. (connectionState.error === 'rate-limited' ||
  52. connectionState.error === 'unable-to-connect') &&
  53. !secondsUntilReconnect()) ? (
  54. <Alert bsStyle="warning" className="small">
  55. <strong>{t('editor_disconected_click_to_reconnect')}</strong>
  56. </Alert>
  57. ) : null}
  58. {debugging ? (
  59. <Alert bsStyle="warning" className="small">
  60. <strong>Connected: {isConnected.toString()}</strong>
  61. </Alert>
  62. ) : null}
  63. </div>
  64. )
  65. }