mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
50df230846
GitOrigin-RevId: 02f97af1b9704782eee77a0b7dfc477ada23e34d
60 lines
1.3 KiB
JavaScript
60 lines
1.3 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)
|