overleaf/services/web/frontend/js/features/pdf-preview/components/pdf-compile-button-inner.js
Alf Eaton ff44afb74c Only show compile shortcut when editor is visible (#7773)
GitOrigin-RevId: 0b6d25d7012e82a676e3a782730fb6ca481cd1e8
2022-04-28 08:03:19 +00:00

56 lines
1.7 KiB
JavaScript

import { Button, OverlayTrigger, Tooltip } from 'react-bootstrap'
import PropTypes from 'prop-types'
import Icon from '../../../shared/components/icon'
import { useTranslation } from 'react-i18next'
import { memo } from 'react'
import { useLayoutContext } from '../../../shared/context/layout-context'
const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
function PdfCompileButtonInner({ startCompile, compiling }) {
const { detachRole, view, pdfLayout } = useLayoutContext()
const { t } = useTranslation()
const compileButtonLabel = compiling ? t('compiling') + '…' : t('recompile')
// show the compile shortcut when the editor is visible
const showCompileShortcut =
detachRole !== 'detached' &&
(view === 'editor' || pdfLayout === 'sideBySide')
return (
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={
<Tooltip id="tooltip-logs-toggle" className="keyboard-tooltip">
{t('recompile_pdf')}{' '}
{showCompileShortcut && (
<span className="keyboard-shortcut">({modifierKey} + Enter)</span>
)}
</Tooltip>
}
>
<Button
className="btn-recompile"
bsStyle="success"
onClick={() => startCompile()}
aria-label={compileButtonLabel}
disabled={compiling}
>
<Icon type="refresh" spin={compiling} />
<span className="toolbar-hide-medium toolbar-hide-small btn-recompile-label">
{compileButtonLabel}
</span>
</Button>
</OverlayTrigger>
)
}
PdfCompileButtonInner.propTypes = {
compiling: PropTypes.bool.isRequired,
startCompile: PropTypes.func.isRequired,
}
export default memo(PdfCompileButtonInner)