overleaf/services/web/frontend/js/features/pdf-preview/components/pdf-logs-button.js
Alf Eaton f7ef2532e0 Handle PDF preview on toggle between split and full-width views (#5470)
* Only hide the compile logs pane when toggled off
* Handle PDF preview on toggle between split and full-width views

GitOrigin-RevId: 9ceca8a06a22abfa78f245e1ae5d24af98215906
2021-10-18 08:03:26 +00:00

65 lines
1.4 KiB
JavaScript

import { memo, useCallback, useMemo } from 'react'
import { Button } from 'react-bootstrap'
import { PdfLogsButtonContent } from './pdf-logs-button-content'
import { sendMBOnce } from '../../../infrastructure/event-tracking'
import { useCompileContext } from '../../../shared/context/compile-context'
function PdfLogsButton() {
const {
codeCheckFailed,
error,
logEntries,
showLogs,
setShowLogs,
} = useCompileContext()
const buttonStyle = useMemo(() => {
if (showLogs) {
return 'default'
}
if (codeCheckFailed) {
return 'danger'
}
if (logEntries) {
if (logEntries.errors?.length) {
return 'danger'
}
if (logEntries.warnings?.length) {
return 'warning'
}
}
return 'default'
}, [codeCheckFailed, logEntries, showLogs])
const handleClick = useCallback(() => {
setShowLogs(value => {
if (!value) {
sendMBOnce('ide-open-logs-once')
}
return !value
})
}, [setShowLogs])
return (
<Button
bsSize="xsmall"
bsStyle={buttonStyle}
disabled={Boolean(error)}
className="btn-toggle-logs toolbar-item"
onClick={handleClick}
>
<PdfLogsButtonContent
showLogs={showLogs}
logEntries={logEntries}
codeCheckFailed={codeCheckFailed}
/>
</Button>
)
}
export default memo(PdfLogsButton)