From 526ec305e8097717c0f6ddd021ba2da260972650 Mon Sep 17 00:00:00 2001 From: Kyle Belanger Date: Fri, 14 Feb 2025 09:02:33 -0500 Subject: [PATCH] update script.js add functions to download --- public/js/script.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/public/js/script.js b/public/js/script.js index 1617774..afeca25 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -39,4 +39,27 @@ document.getElementById('uploadForm').addEventListener('submit', async function generateBtn.textContent = 'Generate Cover Letter'; } +}); + +document.getElementById('downloadBtn').addEventListener('click', async function() { + const coverLetterText = document.getElementById('coverLetterOutput').value; + + try { + const response = await fetch('/generate/download', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ coverLetterText }) + }); + + const result = await response.json(); + if (result.downloadLink) { + window.location.href = result.downloadLink; + } else { + alert('Error downloading document.') + } + } catch (error) { + console.error('Error:', error); + alert('Failed to download document.') + } + }); \ No newline at end of file