fix(pdf): bundle the branding assets into the app (no fetch at export), export returns its warnings and the editor reports missing elements

This commit is contained in:
bchanot committed 2026-10-11 16:09:39 +02:00
1 parent 80e95ca61d
commit 293a6e0b36
22 files changed
+199 -185

No files matched your search

+16 -2
View File
@@ -28,11 +28,17 @@ import {
} from '@/services/zoneInteraction'
import type { ViewStates } from '@/anatomy/drawing'
import { exportReportToPdf } from '@/pdf/export'
import type { ExportWarning } from '@faunosteo/pdf'
import { useT } from '@/i18n/useT'
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
/** What the PDF lacks, named for the practitioner: logo slots and view ids. */
function missingItemsOf(warnings: readonly ExportWarning[]): string[] {
return warnings.map((w) => (w.kind === 'logo_failed' ? w.slot : w.viewId))
}
/** Editor on the reference sheet: wires the canvas, the pickers and the store. */
export default function EditorRoute() {
const navigate = useNavigate()
@@ -144,14 +150,22 @@ export default function EditorRoute() {
if (!report) return
setExporting(true)
try {
const bytes = await exportReportToPdf(report, index, { locale })
const blob = new Blob([bytes as BlobPart], { type: 'application/pdf' })
const { pdf, warnings } = await exportReportToPdf(report, index, {
locale,
})
const blob = new Blob([pdf as BlobPart], { type: 'application/pdf' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `bilan-${report.animal.name}-${report.date}.pdf`
a.click()
URL.revokeObjectURL(url)
const missing = missingItemsOf(warnings)
if (missing.length) {
window.alert(
t('editor.export_warnings').replace('{items}', missing.join(', ')),
)
}
} catch (err) {
console.error('PDF export failed', err)
window.alert(t('editor.export_failed'))