From aa95074ee0bad6779e96b6bab3fe08e8849b97a4 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 22 Mar 2025 01:10:41 -0700 Subject: [PATCH] chore(webui): give feedback via toasts instead of alerts (#1269) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1269 --- static/webui/index.html | 1 + static/webui/script.js | 28 +++++++++++++++++++++++----- static/webui/translations/de.js | 1 + static/webui/translations/en.js | 1 + static/webui/translations/fr.js | 1 + static/webui/translations/ru.js | 1 + static/webui/translations/zh.js | 1 + 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/static/webui/index.html b/static/webui/index.html index b698eb04..56e95ac8 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -593,6 +593,7 @@ +
diff --git a/static/webui/script.js b/static/webui/script.js index 544e768f..12894c2b 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -707,7 +707,7 @@ function maxRankAllEquipment(categories) { return sendBatchGearExp(batchData); } - alert(loc("code_noEquipmentToRankUp")); + toast(loc("code_noEquipmentToRankUp")); }); }); } @@ -740,6 +740,7 @@ function sendBatchGearExp(data) { contentType: "application/json", data: JSON.stringify(data) }).done(() => { + toast(loc("code_succRankUp")); updateInventory(); }); }); @@ -822,7 +823,7 @@ function doAcquireMiscItems() { } ]) }).done(function () { - alert(loc("code_succAdded")); + toast(loc("code_succAdded")); }); }); } @@ -1019,9 +1020,9 @@ function doUnlockAllFocusSchools() { await unlockFocusSchool(upgradeType); } if (Object.keys(missingFocusUpgrades).length == 0) { - alert(loc("code_focusAllUnlocked")); + toast(loc("code_focusAllUnlocked")); } else { - alert(loc("code_focusUnlocked").split("|COUNT|").join(Object.keys(missingFocusUpgrades).length)); + toast(loc("code_focusUnlocked").split("|COUNT|").join(Object.keys(missingFocusUpgrades).length)); } }); }); @@ -1155,7 +1156,7 @@ function doImport() { inventory: JSON.parse($("#import-inventory").val()) }) }).then(function () { - alert(loc("code_succImport")); + toast(loc("code_succImport")); updateInventory(); }); }); @@ -1192,3 +1193,20 @@ function doQuestUpdate(operation) { updateInventory(); }); } + +function toast(text) { + const toast = document.createElement("div"); + toast.className = "toast align-items-center text-bg-primary border-0"; + const div = document.createElement("div"); + div.className = "d-flex"; + const body = document.createElement("div"); + body.className = "toast-body"; + body.textContent = text; + div.appendChild(body); + const button = document.createElement("button"); + button.className = "btn-close btn-close-white me-2 m-auto"; + button.setAttribute("data-bs-dismiss", "toast"); + div.appendChild(button); + toast.appendChild(div); + new bootstrap.Toast(document.querySelector(".toast-container").appendChild(toast)).show(); +} diff --git a/static/webui/translations/de.js b/static/webui/translations/de.js index 5fc61661..a3b4af35 100644 --- a/static/webui/translations/de.js +++ b/static/webui/translations/de.js @@ -26,6 +26,7 @@ dict = { code_renamePrompt: `Neuen benutzerdefinierten Namen eingeben:`, code_remove: `Entfernen`, code_addItemsConfirm: `Bist du sicher, dass du |COUNT| Gegenstände zu deinem Account hinzufügen möchtest?`, + code_succRankUp: `[UNTRANSLATED] Successfully ranked up.`, code_noEquipmentToRankUp: `Keine Ausstattung zum Rangaufstieg verfügbar.`, code_succAdded: `Erfolgreich hinzugefügt.`, code_buffsNumber: `Anzahl der Buffs`, diff --git a/static/webui/translations/en.js b/static/webui/translations/en.js index 9896e46a..4b10f0cf 100644 --- a/static/webui/translations/en.js +++ b/static/webui/translations/en.js @@ -25,6 +25,7 @@ dict = { code_renamePrompt: `Enter new custom name:`, code_remove: `Remove`, code_addItemsConfirm: `Are you sure you want to add |COUNT| items to your account?`, + code_succRankUp: `Successfully ranked up.`, code_noEquipmentToRankUp: `No equipment to rank up.`, code_succAdded: `Successfully added.`, code_buffsNumber: `Number of buffs`, diff --git a/static/webui/translations/fr.js b/static/webui/translations/fr.js index 52b4537a..fc40232a 100644 --- a/static/webui/translations/fr.js +++ b/static/webui/translations/fr.js @@ -26,6 +26,7 @@ dict = { code_renamePrompt: `Nouveau nom :`, code_remove: `Retirer`, code_addItemsConfirm: `Ajouter |COUNT| items à l'inventaire ?`, + code_succRankUp: `[UNTRANSLATED] Successfully ranked up.`, code_noEquipmentToRankUp: `No equipment to rank up.`, code_succAdded: `Ajouté.`, code_buffsNumber: `Nombre de buffs`, diff --git a/static/webui/translations/ru.js b/static/webui/translations/ru.js index 0a50f913..e8148b85 100644 --- a/static/webui/translations/ru.js +++ b/static/webui/translations/ru.js @@ -26,6 +26,7 @@ dict = { code_renamePrompt: `Введите новое имя:`, code_remove: `Удалить`, code_addItemsConfirm: `Вы уверены, что хотите добавить |COUNT| предметов на ваш аккаунт?`, + code_succRankUp: `[UNTRANSLATED] Successfully ranked up.`, code_noEquipmentToRankUp: `Нет снаряжения для повышения ранга.`, code_succAdded: `Успешно добавлено.`, code_buffsNumber: `Количество усилений`, diff --git a/static/webui/translations/zh.js b/static/webui/translations/zh.js index 2f11b930..f3dc7543 100644 --- a/static/webui/translations/zh.js +++ b/static/webui/translations/zh.js @@ -26,6 +26,7 @@ dict = { code_renamePrompt: `输入新的自定义名称:`, code_remove: `移除`, code_addItemsConfirm: `确定要向账户添加 |COUNT| 件物品吗?`, + code_succRankUp: `[UNTRANSLATED] Successfully ranked up.`, code_noEquipmentToRankUp: `没有可升级的装备。`, code_succAdded: `已成功添加。`, code_buffsNumber: `增益数量`,