download-pdf.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { useTranslation } from 'react-i18next'
  2. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  3. import { useProjectContext } from '../../../shared/context/project-context'
  4. import { isSmallDevice } from '../../../infrastructure/event-tracking'
  5. import MaterialIcon from '@/shared/components/material-icon'
  6. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  7. import { useEditorAnalytics } from '@/shared/hooks/use-editor-analytics'
  8. export default function DownloadPDF() {
  9. const { t } = useTranslation()
  10. const { pdfDownloadUrl, pdfUrl } = useCompileContext()
  11. const { projectId } = useProjectContext()
  12. const { sendEvent } = useEditorAnalytics()
  13. function sendDownloadEvent() {
  14. sendEvent('download-pdf-button-click', {
  15. projectId,
  16. location: 'left-menu',
  17. isSmallDevice,
  18. })
  19. }
  20. if (pdfUrl) {
  21. return (
  22. <a
  23. href={pdfDownloadUrl || pdfUrl}
  24. target="_blank"
  25. rel="noreferrer"
  26. onClick={sendDownloadEvent}
  27. >
  28. <MaterialIcon type="picture_as_pdf" size="2x" />
  29. <br />
  30. PDF
  31. </a>
  32. )
  33. } else {
  34. return (
  35. <OLTooltip
  36. id="disabled-pdf-download"
  37. description={t('please_compile_pdf_before_download')}
  38. overlayProps={{ placement: 'bottom' }}
  39. >
  40. <div className="link-disabled">
  41. <MaterialIcon type="picture_as_pdf" size="2x" />
  42. <br />
  43. PDF
  44. </div>
  45. </OLTooltip>
  46. )
  47. }
  48. }