preview-pane.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React from 'react'
  2. import PropTypes from 'prop-types'
  3. import PreviewToolbar from './preview-toolbar'
  4. import PreviewLogsPane from './preview-logs-pane'
  5. import { useTranslation } from 'react-i18next'
  6. function PreviewPane({
  7. compilerState,
  8. onRecompile,
  9. onRunSyntaxCheckNow,
  10. onSetAutoCompile,
  11. onSetDraftMode,
  12. onSetSyntaxCheck,
  13. onToggleLogs,
  14. showLogs
  15. }) {
  16. const { t } = useTranslation()
  17. const nErrors =
  18. compilerState.logEntries && compilerState.logEntries.errors
  19. ? compilerState.logEntries.errors.length
  20. : 0
  21. const nWarnings =
  22. compilerState.logEntries && compilerState.logEntries.warnings
  23. ? compilerState.logEntries.warnings.length
  24. : 0
  25. const nLogEntries =
  26. compilerState.logEntries && compilerState.logEntries.all
  27. ? compilerState.logEntries.all.length
  28. : 0
  29. return (
  30. <>
  31. <PreviewToolbar
  32. compilerState={compilerState}
  33. logsState={{ nErrors, nWarnings, nLogEntries }}
  34. showLogs={showLogs}
  35. onRecompile={onRecompile}
  36. onRunSyntaxCheckNow={onRunSyntaxCheckNow}
  37. onSetAutoCompile={onSetAutoCompile}
  38. onSetDraftMode={onSetDraftMode}
  39. onSetSyntaxCheck={onSetSyntaxCheck}
  40. onToggleLogs={onToggleLogs}
  41. />
  42. <span aria-live="polite" className="sr-only">
  43. {nErrors && !compilerState.isCompiling
  44. ? t('n_errors', { count: nErrors })
  45. : ''}
  46. </span>
  47. <span aria-live="polite" className="sr-only">
  48. {nWarnings && !compilerState.isCompiling
  49. ? t('n_warnings', { count: nWarnings })
  50. : ''}
  51. </span>
  52. {showLogs ? (
  53. <PreviewLogsPane logEntries={compilerState.logEntries.all} />
  54. ) : null}
  55. </>
  56. )
  57. }
  58. PreviewPane.propTypes = {
  59. compilerState: PropTypes.shape({
  60. isAutoCompileOn: PropTypes.bool.isRequired,
  61. isCompiling: PropTypes.bool.isRequired,
  62. isDraftModeOn: PropTypes.bool.isRequired,
  63. isSyntaxCheckOn: PropTypes.bool.isRequired,
  64. logEntries: PropTypes.object.isRequired
  65. }),
  66. onRecompile: PropTypes.func.isRequired,
  67. onRunSyntaxCheckNow: PropTypes.func.isRequired,
  68. onSetAutoCompile: PropTypes.func.isRequired,
  69. onSetDraftMode: PropTypes.func.isRequired,
  70. onSetSyntaxCheck: PropTypes.func.isRequired,
  71. onToggleLogs: PropTypes.func.isRequired,
  72. showLogs: PropTypes.bool.isRequired
  73. }
  74. export default PreviewPane