From b188ea1d09ad42998a363ddfcb6ded4b4f3cfbf8 Mon Sep 17 00:00:00 2001 From: Jojo Ortiz Date: Thu, 5 Oct 2023 15:06:22 -0700 Subject: [PATCH] add OVERWRITE download state for checking if file overwrite ok --- .../Chatbots/Components/DownloadModal.svelte | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/pykoi/frontend/src/lib/Chatbots/Components/DownloadModal.svelte b/pykoi/frontend/src/lib/Chatbots/Components/DownloadModal.svelte index 1230cef..959f17e 100644 --- a/pykoi/frontend/src/lib/Chatbots/Components/DownloadModal.svelte +++ b/pykoi/frontend/src/lib/Chatbots/Components/DownloadModal.svelte @@ -8,11 +8,11 @@ FILE_INPUT: 0, DOWNLOADED: 1, FAILED_DOWNLOAD: 2, + OVERWRITE: 3, }; let downloadState = DOWNLOAD_STATE.FILE_INPUT; - const handleSubmit = async (e) => { - e.preventDefault(); + const saveToCSV = async (file_name) => { const request_body = { file_name, }; @@ -34,6 +34,19 @@ } }; + const handleSubmit = async (e) => { + e.preventDefault(); + const response = await fetch( + `/file_exists/?file_name=${file_name}.csv` + ); + const file_exists_response = await response.json(); + if (file_exists_response.file_exists === true) { + downloadState = DOWNLOAD_STATE.OVERWRITE; + } else { + saveToCSV(file_name); + } + }; + function handleClose() { showModal = false; downloadState = DOWNLOAD_STATE.FILE_INPUT; @@ -62,7 +75,7 @@ {/if} {#if downloadState === DOWNLOAD_STATE.DOWNLOADED}
- ✅ Data downloaded to ~/pykoi/{file_name}.csv + ✅ Data downloaded to /pykoi/{file_name}.csv
@@ -71,10 +84,19 @@ {#if downloadState === DOWNLOAD_STATE.FAILED_DOWNLOAD}
⚠️ Download failed. Please try again.
- +
{/if} + {#if downloadState === DOWNLOAD_STATE.OVERWRITE} +
+ ⚠️ {file_name}.csv already exists. Do you wish to overwrite it? +
+
+ + +
+ {/if}