actions-word-count.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { useState, useCallback } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import Tooltip from '../../../shared/components/tooltip'
  4. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  5. import WordCountModal from '../../word-count-modal/components/word-count-modal'
  6. import LeftMenuButton from './left-menu-button'
  7. import * as eventTracking from '../../../infrastructure/event-tracking'
  8. export default function ActionsWordCount() {
  9. const [showModal, setShowModal] = useState(false)
  10. const { pdfUrl } = useCompileContext()
  11. const { t } = useTranslation()
  12. const handleShowModal = useCallback(() => {
  13. eventTracking.sendMB('left-menu-count')
  14. setShowModal(true)
  15. }, [])
  16. return (
  17. <>
  18. {pdfUrl ? (
  19. <LeftMenuButton
  20. onClick={handleShowModal}
  21. icon={{
  22. type: 'eye',
  23. fw: true,
  24. }}
  25. >
  26. {t('word_count')}
  27. </LeftMenuButton>
  28. ) : (
  29. <Tooltip
  30. id="disabled-word-count"
  31. description={t('please_compile_pdf_before_word_count')}
  32. overlayProps={{
  33. placement: 'top',
  34. }}
  35. >
  36. {/* OverlayTrigger won't fire unless the child is a non-react html element (e.g div, span) */}
  37. <div>
  38. <LeftMenuButton
  39. icon={{
  40. type: 'eye',
  41. fw: true,
  42. }}
  43. disabled
  44. disabledAccesibilityText={t(
  45. 'please_compile_pdf_before_word_count'
  46. )}
  47. >
  48. {t('word_count')}
  49. </LeftMenuButton>
  50. </div>
  51. </Tooltip>
  52. )}
  53. <WordCountModal show={showModal} handleHide={() => setShowModal(false)} />
  54. </>
  55. )
  56. }