actions-word-count.tsx 1.9 KB

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