2020-09-28 06:51:15 -04:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import PreviewToolbar from './preview-toolbar'
|
|
|
|
import PreviewLogsPane from './preview-logs-pane'
|
2020-10-06 11:23:03 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2020-09-28 06:51:15 -04:00
|
|
|
|
|
|
|
function PreviewPane({
|
|
|
|
compilerState,
|
2020-10-20 08:44:19 -04:00
|
|
|
onClearCache,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRecompile,
|
|
|
|
onRunSyntaxCheckNow,
|
|
|
|
onSetAutoCompile,
|
|
|
|
onSetDraftMode,
|
|
|
|
onSetSyntaxCheck,
|
|
|
|
onToggleLogs,
|
2020-09-29 07:08:49 -04:00
|
|
|
showLogs
|
2020-09-28 06:51:15 -04:00
|
|
|
}) {
|
2020-10-06 11:23:03 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2020-09-29 07:08:49 -04:00
|
|
|
const nErrors =
|
|
|
|
compilerState.logEntries && compilerState.logEntries.errors
|
|
|
|
? compilerState.logEntries.errors.length
|
|
|
|
: 0
|
|
|
|
const nWarnings =
|
|
|
|
compilerState.logEntries && compilerState.logEntries.warnings
|
|
|
|
? compilerState.logEntries.warnings.length
|
|
|
|
: 0
|
|
|
|
const nLogEntries =
|
|
|
|
compilerState.logEntries && compilerState.logEntries.all
|
|
|
|
? compilerState.logEntries.all.length
|
|
|
|
: 0
|
|
|
|
|
2020-09-28 06:51:15 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PreviewToolbar
|
|
|
|
compilerState={compilerState}
|
2020-09-29 07:08:49 -04:00
|
|
|
logsState={{ nErrors, nWarnings, nLogEntries }}
|
|
|
|
showLogs={showLogs}
|
2020-10-20 08:44:19 -04:00
|
|
|
onClearCache={onClearCache}
|
2020-09-28 06:51:15 -04:00
|
|
|
onRecompile={onRecompile}
|
|
|
|
onRunSyntaxCheckNow={onRunSyntaxCheckNow}
|
|
|
|
onSetAutoCompile={onSetAutoCompile}
|
|
|
|
onSetDraftMode={onSetDraftMode}
|
|
|
|
onSetSyntaxCheck={onSetSyntaxCheck}
|
|
|
|
onToggleLogs={onToggleLogs}
|
|
|
|
/>
|
2020-10-06 11:23:03 -04:00
|
|
|
<span aria-live="polite" className="sr-only">
|
2020-10-07 06:43:54 -04:00
|
|
|
{nErrors && !compilerState.isCompiling
|
|
|
|
? t('n_errors', { count: nErrors })
|
|
|
|
: ''}
|
2020-10-06 11:23:03 -04:00
|
|
|
</span>
|
|
|
|
<span aria-live="polite" className="sr-only">
|
2020-10-07 06:43:54 -04:00
|
|
|
{nWarnings && !compilerState.isCompiling
|
|
|
|
? t('n_warnings', { count: nWarnings })
|
|
|
|
: ''}
|
2020-10-06 11:23:03 -04:00
|
|
|
</span>
|
2020-09-29 07:08:49 -04:00
|
|
|
{showLogs ? (
|
|
|
|
<PreviewLogsPane logEntries={compilerState.logEntries.all} />
|
|
|
|
) : null}
|
2020-09-28 06:51:15 -04:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewPane.propTypes = {
|
|
|
|
compilerState: PropTypes.shape({
|
|
|
|
isAutoCompileOn: PropTypes.bool.isRequired,
|
|
|
|
isCompiling: PropTypes.bool.isRequired,
|
|
|
|
isDraftModeOn: PropTypes.bool.isRequired,
|
2020-09-29 07:08:49 -04:00
|
|
|
isSyntaxCheckOn: PropTypes.bool.isRequired,
|
|
|
|
logEntries: PropTypes.object.isRequired
|
2020-09-28 06:51:15 -04:00
|
|
|
}),
|
2020-10-20 08:44:19 -04:00
|
|
|
onClearCache: PropTypes.func.isRequired,
|
2020-09-28 06:51:15 -04:00
|
|
|
onRecompile: PropTypes.func.isRequired,
|
|
|
|
onRunSyntaxCheckNow: PropTypes.func.isRequired,
|
|
|
|
onSetAutoCompile: PropTypes.func.isRequired,
|
|
|
|
onSetDraftMode: PropTypes.func.isRequired,
|
|
|
|
onSetSyntaxCheck: PropTypes.func.isRequired,
|
|
|
|
onToggleLogs: PropTypes.func.isRequired,
|
2020-09-29 07:08:49 -04:00
|
|
|
showLogs: PropTypes.bool.isRequired
|
2020-09-28 06:51:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewPane
|