diff --git a/web/src/routes/dashboard/export.rs b/web/src/routes/dashboard/export.rs index b0b0a17..44a4cd3 100644 --- a/web/src/routes/dashboard/export.rs +++ b/web/src/routes/dashboard/export.rs @@ -136,6 +136,7 @@ pub(crate) async fn import_reminders( match base64::decode(&body.body) { Ok(body) => { let mut reader = csv::Reader::from_reader(body.as_slice()); + let mut count = 0; for result in reader.deserialize::() { match result { @@ -184,6 +185,8 @@ pub(crate) async fn import_reminders( reminder, ) .await?; + + count += 1; } Err(_) => { @@ -204,7 +207,9 @@ pub(crate) async fn import_reminders( } match transaction.commit().await { - Ok(_) => Ok(json!({})), + Ok(_) => Ok(json!({ + "message": format!("Imported {} reminders", count) + })), Err(e) => { warn!("Failed to commit transaction: {:?}", e); diff --git a/web/static/js/main.js b/web/static/js/main.js index cbd6f79..44cf8d6 100644 --- a/web/static/js/main.js +++ b/web/static/js/main.js @@ -603,6 +603,16 @@ function show_error(error) { }, 5000); } +function show_success(error) { + document.getElementById("success").querySelector("span.success-message").textContent = + error; + document.getElementById("success").classList.add("is-active"); + + window.setTimeout(() => { + document.getElementById("success").classList.remove("is-active"); + }, 5000); +} + $colorPickerInput.value = colorPicker.color.hexString; $colorPickerInput.addEventListener("input", () => { @@ -753,12 +763,25 @@ $uploader.addEventListener("change", (ev) => { fileReader.onload = (e) => resolve(fileReader.result); fileReader.readAsDataURL($uploader.files[0]); }).then((dataUrl) => { + $importBtn.setAttribute("disabled", true); + fetch(`/dashboard/api/guild/${guildId()}/export/${urlTail}`, { method: "PUT", body: JSON.stringify({ body: dataUrl.split(",")[1] }), - }).then(() => { - delete $uploader.files[0]; - }); + }) + .then((response) => response.json()) + .then((data) => { + $importBtn.removeAttribute("disabled"); + + if (data.error) { + show_error(data.error); + } else { + show_success(data.message); + } + }) + .then(() => { + delete $uploader.files[0]; + }); }); }); diff --git a/web/templates/dashboard.html.tera b/web/templates/dashboard.html.tera index eaae9af..ee35c0d 100644 --- a/web/templates/dashboard.html.tera +++ b/web/templates/dashboard.html.tera @@ -76,6 +76,10 @@ +
+ +
+ -
-
- -
-