mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
b902bd9265
GitOrigin-RevId: 96b8bb527fa3d60a5fb84eee2b8f4fabc1726875
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
import { memo, useCallback, useMemo } from 'react'
|
|
import { Button } from 'react-bootstrap'
|
|
import { usePdfPreviewContext } from '../contexts/pdf-preview-context'
|
|
import { PdfLogsButtonContent } from './pdf-logs-button-content'
|
|
import { sendMBOnce } from '../../../infrastructure/event-tracking'
|
|
|
|
function PdfLogsButton() {
|
|
const {
|
|
codeCheckFailed,
|
|
error,
|
|
logEntries,
|
|
showLogs,
|
|
setShowLogs,
|
|
} = usePdfPreviewContext()
|
|
|
|
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)
|