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) {
Ok(body) => {
let mut reader = csv::Reader::from_reader(body.as_slice());
let mut count = 0;
for result in reader.deserialize::<ReminderCsv>() {
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);

View File

@ -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,10 +763,23 @@ $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(() => {
})
.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>
</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-background"></div>
<div class="modal-card">
@ -185,14 +189,6 @@
</label>
</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>
<div class="has-text-centered">
<div style="color: red">