diff --git a/frontend/src/pages/ViewPlan.tsx b/frontend/src/pages/ViewPlan.tsx index fe49bf9..d28b196 100644 --- a/frontend/src/pages/ViewPlan.tsx +++ b/frontend/src/pages/ViewPlan.tsx @@ -6,6 +6,7 @@ import DrillService from '../service/drillService'; import { toast, ToastContainer } from 'react-toastify'; import { Icon } from '@iconify/react/dist/iconify.js'; import DrillElementService from '../service/drillElementService'; +import html2pdf from 'html2pdf.js'; const ViewPlan = () => { const stringSelectedClassPlan = localStorage.getItem('selectedClassPlan'); @@ -233,6 +234,70 @@ const ViewPlan = () => { } catch (error) {} }; + const downloadPlan = async () => { + try { + // Carregar todos os drills relacionados ao plano de aula + const drillResponses = await Promise.all( + drills.map((drl) => drill.getById((drl as { id: string }).id)) + ); + + // Criar um elemento HTML para representar o plano de aula e os drills + const container = document.createElement('div'); + + // Adicionar os dados do plano de aula ao HTML + const planDiv = document.createElement('div'); + planDiv.style.margin = '50px' + planDiv.innerHTML = ` +

${planUpdated.title}

+

+

Objetivos

+

${planUpdated.goals}

+

+

Observações

+

${planUpdated.observations}

+

+

Drills

+ `; + container.appendChild(planDiv); + + // Adicionar os dados dos drills ao HTML + drillResponses.forEach((response) => { + const drillData = response.data; + const drillDiv = document.createElement('div'); + drillDiv.innerHTML = ` +

+

${drillData.title}

+

+

Descrição

+

${drillData.description}

+

+

Observações

+

${drillData.observations}

+

+ + + `; + container.appendChild(drillDiv); + }); + + // Configurar as opções do html2pdf + const options = { + + filename: 'plano_de_aula_com_drills.pdf', + image: { type: 'jpeg', quality: 0.98 }, + html2canvas: { scale: 2 }, + jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }, + }; + + // Converter o HTML para PDF usando html2pdf + html2pdf(container, options); + + } catch (error) { + console.error('Erro ao criar o arquivo PDF:', error); + // Lide com o erro conforme necessário + } + }; + return ( <> { onClick={startEditingTitle} className="clickableIcon" /> + ) : (