2021-10-12 04:47:46 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
2024-10-08 10:22:13 -04:00
|
|
|
import { useProjectContext } from '@/shared/context/project-context'
|
|
|
|
import { sendMB, isSmallDevice } from '@/infrastructure/event-tracking'
|
|
|
|
import Icon from '@/shared/components/icon'
|
|
|
|
import OLTooltip from '@/features/ui/components/ol/ol-tooltip'
|
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
|
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
function PdfHybridDownloadButton() {
|
2021-10-15 05:39:56 -04:00
|
|
|
const { pdfDownloadUrl } = useCompileContext()
|
2021-10-12 04:47:46 -04:00
|
|
|
|
2023-03-13 10:11:43 -04:00
|
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
const { t } = useTranslation()
|
2022-05-18 09:46:10 -04:00
|
|
|
const description = pdfDownloadUrl
|
|
|
|
? t('download_pdf')
|
|
|
|
: t('please_compile_pdf_before_download')
|
2021-10-12 04:47:46 -04:00
|
|
|
|
2024-10-08 10:22:13 -04:00
|
|
|
function handleOnClick(e: React.MouseEvent) {
|
|
|
|
const event = e as React.MouseEvent<HTMLAnchorElement>
|
|
|
|
if (event.currentTarget.dataset.disabled === 'true') {
|
|
|
|
event.preventDefault()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMB('download-pdf-button-click', {
|
2023-08-22 09:33:19 -04:00
|
|
|
projectId,
|
|
|
|
location: 'pdf-preview',
|
2023-11-24 07:12:32 -05:00
|
|
|
isSmallDevice,
|
2023-08-22 09:33:19 -04:00
|
|
|
})
|
2023-03-13 10:11:43 -04:00
|
|
|
}
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
return (
|
2024-10-08 10:22:13 -04:00
|
|
|
<OLTooltip
|
2023-05-16 08:16:28 -04:00
|
|
|
id="download-pdf"
|
2022-05-19 08:45:20 -04:00
|
|
|
description={description}
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
|
|
|
>
|
2024-10-08 10:22:13 -04:00
|
|
|
<OLButton
|
2023-03-13 10:11:43 -04:00
|
|
|
onClick={handleOnClick}
|
2024-10-08 10:22:13 -04:00
|
|
|
variant="link"
|
2024-05-31 04:51:27 -04:00
|
|
|
className="pdf-toolbar-btn"
|
2024-10-08 10:22:13 -04:00
|
|
|
draggable={false}
|
|
|
|
data-disabled={!pdfDownloadUrl}
|
2021-10-12 04:47:46 -04:00
|
|
|
disabled={!pdfDownloadUrl}
|
|
|
|
download
|
|
|
|
href={pdfDownloadUrl || '#'}
|
|
|
|
target="_blank"
|
2021-12-07 05:06:38 -05:00
|
|
|
style={{ pointerEvents: 'auto' }}
|
2023-09-15 03:14:01 -04:00
|
|
|
aria-label={t('download_pdf')}
|
2021-10-12 04:47:46 -04:00
|
|
|
>
|
2024-10-08 10:22:13 -04:00
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<Icon type="download" fw />}
|
|
|
|
bs5={<MaterialIcon type="download" />}
|
|
|
|
/>
|
|
|
|
</OLButton>
|
|
|
|
</OLTooltip>
|
2021-10-12 04:47:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-18 09:46:10 -04:00
|
|
|
export default PdfHybridDownloadButton
|