detach-compile-button.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { memo } from 'react'
  2. import PropTypes from 'prop-types'
  3. import classnames from 'classnames'
  4. import { useLayoutContext } from '../../../shared/context/layout-context'
  5. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  6. import PdfCompileButtonInner from './pdf-compile-button-inner'
  7. export function DetachCompileButton() {
  8. const { compiling, hasChanges, startCompile } = useCompileContext()
  9. return (
  10. <div
  11. className={classnames({
  12. 'btn-recompile-group': true,
  13. 'btn-recompile-group-has-changes': hasChanges,
  14. })}
  15. >
  16. <PdfCompileButtonInner
  17. startCompile={startCompile}
  18. compiling={compiling}
  19. />
  20. </div>
  21. )
  22. }
  23. export function DetachCompileButtonWrapper() {
  24. const { detachRole, detachIsLinked } = useLayoutContext(
  25. layoutContextPropTypes
  26. )
  27. if (detachRole !== 'detacher' || !detachIsLinked) {
  28. return null
  29. }
  30. return <DetachCompileButton />
  31. }
  32. const layoutContextPropTypes = {
  33. detachRole: PropTypes.string,
  34. detachIsLinked: PropTypes.bool,
  35. }
  36. export default memo(DetachCompileButtonWrapper)