Show messages when imports succeed.

This commit is contained in:
jude 2023-09-24 14:14:21 +01:00
parent 541633270c
commit 8ddff698e5
3 changed files with 36 additions and 12 deletions

View File

@ -136,6 +136,7 @@ pub(crate) async fn import_reminders(
match base64::decode(&body.body) { match base64::decode(&body.body) {
Ok(body) => { Ok(body) => {
let mut reader = csv::Reader::from_reader(body.as_slice()); let mut reader = csv::Reader::from_reader(body.as_slice());
let mut count = 0;
for result in reader.deserialize::<ReminderCsv>() { for result in reader.deserialize::<ReminderCsv>() {
match result { match result {
@ -184,6 +185,8 @@ pub(crate) async fn import_reminders(
reminder, reminder,
) )
.await?; .await?;
count += 1;
} }
Err(_) => { Err(_) => {
@ -204,7 +207,9 @@ pub(crate) async fn import_reminders(
} }
match transaction.commit().await { match transaction.commit().await {
Ok(_) => Ok(json!({})), Ok(_) => Ok(json!({
"message": format!("Imported {} reminders", count)
})),
Err(e) => { Err(e) => {
warn!("Failed to commit transaction: {:?}", e); warn!("Failed to commit transaction: {:?}", e);

View File

@ -603,6 +603,16 @@ function show_error(error) {
}, 5000); }, 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.value = colorPicker.color.hexString;
$colorPickerInput.addEventListener("input", () => { $colorPickerInput.addEventListener("input", () => {
@ -753,12 +763,25 @@ $uploader.addEventListener("change", (ev) => {
fileReader.onload = (e) => resolve(fileReader.result); fileReader.onload = (e) => resolve(fileReader.result);
fileReader.readAsDataURL($uploader.files[0]); fileReader.readAsDataURL($uploader.files[0]);
}).then((dataUrl) => { }).then((dataUrl) => {
$importBtn.setAttribute("disabled", true);
fetch(`/dashboard/api/guild/${guildId()}/export/${urlTail}`, { fetch(`/dashboard/api/guild/${guildId()}/export/${urlTail}`, {
method: "PUT", method: "PUT",
body: JSON.stringify({ body: dataUrl.split(",")[1] }), 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];
});
}); });
}); });

View File

@ -76,6 +76,10 @@
<span class="icon"><i class="far fa-exclamation-circle"></i></span> <span class="error-message"></span> <span class="icon"><i class="far fa-exclamation-circle"></i></span> <span class="error-message"></span>
</div> </div>
<div class="notification is-success flash-message" id="success">
<span class="icon"><i class="far fa-check"></i></span> <span class="success-message"></span>
</div>
<div class="modal" id="addImageModal"> <div class="modal" id="addImageModal">
<div class="modal-background"></div> <div class="modal-background"></div>
<div class="modal-card"> <div class="modal-card">
@ -185,14 +189,6 @@
</label> </label>
</div> </div>
</div> </div>
<div class="control">
<div class="field">
<label>
<input type="radio" class="default-width" name="exportSelect" value="todos">
Todo Lists
</label>
</div>
</div>
<br> <br>
<div class="has-text-centered"> <div class="has-text-centered">
<div style="color: red"> <div style="color: red">