pdf-hybrid-code-check-button.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { memo, useCallback } from 'react'
  2. import { sendMBOnce } from '../../../infrastructure/event-tracking'
  3. import { Button } from 'react-bootstrap'
  4. import Icon from '../../../shared/components/icon'
  5. import { useTranslation } from 'react-i18next'
  6. import { useCompileContext } from '../../../shared/context/compile-context'
  7. function PdfHybridCodeCheckButton() {
  8. const { codeCheckFailed, error, setShowLogs } = useCompileContext()
  9. const { t } = useTranslation()
  10. const handleClick = useCallback(() => {
  11. setShowLogs(value => {
  12. if (!value) {
  13. sendMBOnce('ide-open-logs-once')
  14. }
  15. return !value
  16. })
  17. }, [setShowLogs])
  18. if (!codeCheckFailed) {
  19. return null
  20. }
  21. return (
  22. <Button
  23. bsSize="xsmall"
  24. bsStyle="danger"
  25. disabled={Boolean(error)}
  26. className="btn-toggle-logs toolbar-item"
  27. onClick={handleClick}
  28. >
  29. <Icon type="exclamation-triangle" />
  30. <span className="toolbar-text toolbar-hide-small">
  31. {t('code_check_failed')}
  32. </span>
  33. </Button>
  34. )
  35. }
  36. export default memo(PdfHybridCodeCheckButton)