Corrigindo Estúdio de Poesia: PDF, Inteligência de Idade e Botão Lixeira

This commit is contained in:
2026-06-05 14:08:55 +00:00
parent b7b6c6c42b
commit 945a87b998
2 changed files with 60 additions and 17 deletions
+49 -16
View File
@@ -5294,19 +5294,34 @@ const initApp = () => {
if (btnDownloadPoesiaPdf) {
btnDownloadPoesiaPdf.addEventListener('click', () => {
if (!currentPoesia) return;
const element = document.createElement('div');
element.innerHTML = window.marked ? marked.parse(currentPoesia) : currentPoesia;
element.style.padding = '20px';
element.style.fontFamily = 'Arial, sans-serif';
element.style.color = '#333';
html2pdf().set({
margin: 15,
filename: 'poesia_pedagogica.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
}).from(element).save();
const printWindow = window.open('', '_blank');
printWindow.document.write(`
<html>
<head>
<title>Poesia - Assistente PedaGog</title>
<style>
body { font-family: 'Outfit', 'Inter', sans-serif; padding: 40px; color: #333; line-height: 1.6; }
h1, h2, h3 { color: #10b981; margin-top: 24px; margin-bottom: 12px; }
@media print {
body { padding: 0; }
button { display: none; }
}
</style>
</head>
<body>
<div style="max-width: 800px; margin: 0 auto;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 20px;">
<h1 style="margin: 0; border: none; padding: 0;">📜 Poesia Pedagógica</h1>
<button onclick="window.print()" style="background: #10b981; color: white; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: bold;">Imprimir / Salvar PDF</button>
</div>
<div>
${window.marked ? marked.parse(currentPoesia) : currentPoesia}
</div>
</div>
</body>
</html>
`);
printWindow.document.close();
});
}
@@ -5327,16 +5342,34 @@ const initApp = () => {
const date = new Date(item.created_at).toLocaleString('pt-BR');
const div = document.createElement('div');
div.className = 'history-item-card';
div.style.cssText = 'background: rgba(255,255,255,0.02); padding: 14px; border-radius: 8px; border: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 8px; cursor: pointer;';
div.style.cssText = 'background: rgba(255,255,255,0.02); padding: 14px; border-radius: 8px; border: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 8px; cursor: pointer; position: relative;';
div.innerHTML = `
<div style="display: flex; justify-content: space-between; align-items: flex-start;">
<div style="display: flex; justify-content: space-between; align-items: flex-start; padding-right: 30px;">
<strong style="color: var(--brand-green); font-size: 0.95rem;">${item.faixa_etaria} (${item.estrofes} Estrofes)</strong>
<span style="font-size: 0.75rem; color: var(--text-secondary);">${date}</span>
</div>
<p style="margin: 0; font-size: 0.85rem; color: var(--text-primary); opacity: 0.9;">Tema: ${item.tema}</p>
<button class="btn-delete-poesia" data-id="${item.id}" style="position: absolute; top: 12px; right: 12px; background: transparent; border: none; color: #ef4444; cursor: pointer; font-size: 1.1rem; padding: 4px; border-radius: 4px;" title="Excluir Poesia">🗑️</button>
`;
div.addEventListener('click', async () => {
div.addEventListener('click', async (e) => {
if (e.target.closest('.btn-delete-poesia')) {
e.stopPropagation();
if (confirm('Tem certeza que deseja excluir esta poesia?')) {
try {
const delRes = await fetch(`/api/poesias/${item.id}`, { method: 'DELETE' });
if (delRes.ok) {
showToast('Poesia excluída.', 'success');
loadPoesiaHistory();
} else {
showToast('Erro ao excluir.', 'error');
}
} catch (err) {
showToast('Erro de conexão.', 'error');
}
}
return;
}
try {
const res = await fetch(`/api/poesias/${item.id}`);
const detail = await res.json();
+11 -1
View File
@@ -1157,12 +1157,22 @@ app.post('/api/poesias/generate', requireAuth, async (req, res) => {
try {
let poesiaText = '';
let idadeInstrucao = '';
if (faixaEtaria.includes('Bebês') || faixaEtaria.includes('bem pequenas')) {
idadeInstrucao = '- NÍVEL FÁCIL: Use palavras EXTREMAMENTE simples, do cotidiano infantil. As estrofes devem ser MUITO curtas, contendo poucas palavras por verso, pois são crianças de colo ou maternal. Elas precisam conseguir memorizar e repetir facilmente.';
} else if (faixaEtaria.includes('pequenas')) {
idadeInstrucao = '- NÍVEL MÉDIO: Use palavras fáceis e lúdicas, focando em sonoridade. As estrofes podem ter tamanho normal de versos infantis (4 a 5 palavras por verso).';
} else {
idadeInstrucao = '- NÍVEL AVANÇADO: Use vocabulário um pouco mais rico, com metáforas leves. Para crianças do Fundamental I, os versos podem ser mais elaborados e trazer reflexões sobre o tema.';
}
const systemInstruction = `Você é um poeta pedagógico infantil especializado em criar poesias ritmadas, sonoras e adequadas para o desenvolvimento infantil no Brasil.
REGRAS RÍGIDAS:
- Escreva a poesia para a faixa etária: ${faixaEtaria}
${idadeInstrucao}
- A poesia DEVE ter EXATAMENTE ${estrofes} estrofes.
- O tema da poesia é: "${tema}"
- Use rimas claras e vocabulário apropriado para a idade.
- Use rimas claras, ritmo marcante (musicalidade) e seja criativo.
- Sua resposta deve conter APENAS a poesia formatada em Markdown, sem NENHUM comentário adicional, explicação, ou blocos de pensamento.
- Responda EXCLUSIVAMENTE em Português do Brasil.`;