diff --git a/resources/js/pages/patients/NotesPanel.vue b/resources/js/pages/patients/NotesPanel.vue index b2c5ae8..69e30b2 100644 --- a/resources/js/pages/patients/NotesPanel.vue +++ b/resources/js/pages/patients/NotesPanel.vue @@ -16,7 +16,6 @@ const props = defineProps({ }) - const formatDateDate = (date) => { const messageDate = new Date(date); const options = { @@ -29,23 +28,25 @@ const formatDateDate = (date) => { return messageDate.toLocaleDateString('en-US', options).replace(/\//g, '-'); }; -const downloadFile = (fileUrl) => { - const link = document.createElement('a'); - link.href = fileUrl; - link.download = 'noteFile.png'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); -}; -const downloadImage = async (imageUrl) => { +const downloadFile = async (fileUrl, fileName = 'downloadedFile.png') => { try { - const response = await fetch(imageUrl) - const blob = await response.blob() - const fileName = imageUrl.split('/').pop() - saveAs(blob, fileName) + const response = await fetch(fileUrl); + if (!response.ok) throw new Error('Network response was not ok'); + const blob = await response.blob(); + const link = document.createElement('a'); + const url = window.URL.createObjectURL(blob); + link.href = url; + link.download = fileName; + document.body.appendChild(link); + link.click(); + window.URL.revokeObjectURL(url); + document.body.removeChild(link); } catch (error) { - console.error('Error downloading image:', error) } - } + console.error('Download failed', error); + } + }; + +