preview-pane.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. onClearCache,
  9. onRecompile,
  10. onRunSyntaxCheckNow,
  11. onSetAutoCompile,
  12. onSetDraftMode,
  13. onSetSyntaxCheck,
  14. onToggleLogs,
  15. outputFiles,
  16. pdfDownloadUrl,
  17. onLogEntryLinkClick,
  18. showLogs
  19. }) {
  20. const { t } = useTranslation()
  21. const nErrors =
  22. compilerState.logEntries && compilerState.logEntries.errors
  23. ? compilerState.logEntries.errors.length
  24. : 0
  25. const nWarnings =
  26. compilerState.logEntries && compilerState.logEntries.warnings
  27. ? compilerState.logEntries.warnings.length
  28. : 0
  29. const nLogEntries =
  30. compilerState.logEntries && compilerState.logEntries.all
  31. ? compilerState.logEntries.all.length
  32. : 0
  33. return (
  34. <>
  35. <PreviewToolbar
  36. compilerState={compilerState}
  37. logsState={{ nErrors, nWarnings, nLogEntries }}
  38. showLogs={showLogs}
  39. onClearCache={onClearCache}
  40. onRecompile={onRecompile}
  41. onRunSyntaxCheckNow={onRunSyntaxCheckNow}
  42. onSetAutoCompile={onSetAutoCompile}
  43. onSetDraftMode={onSetDraftMode}
  44. onSetSyntaxCheck={onSetSyntaxCheck}
  45. onToggleLogs={onToggleLogs}
  46. outputFiles={outputFiles}
  47. pdfDownloadUrl={pdfDownloadUrl}
  48. />
  49. <span aria-live="polite" className="sr-only">
  50. {nErrors && !compilerState.isCompiling
  51. ? t('n_errors', { count: nErrors })
  52. : ''}
  53. </span>
  54. <span aria-live="polite" className="sr-only">
  55. {nWarnings && !compilerState.isCompiling
  56. ? t('n_warnings', { count: nWarnings })
  57. : ''}
  58. </span>
  59. {showLogs ? (
  60. <PreviewLogsPane
  61. logEntries={compilerState.logEntries.all}
  62. onLogEntryLinkClick={onLogEntryLinkClick}
  63. />
  64. ) : null}
  65. </>
  66. )
  67. }
  68. PreviewPane.propTypes = {
  69. compilerState: PropTypes.shape({
  70. isAutoCompileOn: PropTypes.bool.isRequired,
  71. isCompiling: PropTypes.bool.isRequired,
  72. isDraftModeOn: PropTypes.bool.isRequired,
  73. isSyntaxCheckOn: PropTypes.bool.isRequired,
  74. logEntries: PropTypes.object.isRequired
  75. }),
  76. onClearCache: PropTypes.func.isRequired,
  77. onLogEntryLinkClick: PropTypes.func.isRequired,
  78. onRecompile: PropTypes.func.isRequired,
  79. onRunSyntaxCheckNow: PropTypes.func.isRequired,
  80. onSetAutoCompile: PropTypes.func.isRequired,
  81. onSetDraftMode: PropTypes.func.isRequired,
  82. onSetSyntaxCheck: PropTypes.func.isRequired,
  83. onToggleLogs: PropTypes.func.isRequired,
  84. outputFiles: PropTypes.array,
  85. pdfDownloadUrl: PropTypes.string,
  86. showLogs: PropTypes.bool.isRequired
  87. }
  88. export default PreviewPane