From 26f37f58e555e50b5104058c55fa8c17ff03b924 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sat, 19 Apr 2025 09:05:55 -0700 Subject: [PATCH] chore(webui): make add mods behave more like adding items (#1732) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1732 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- static/webui/script.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/static/webui/script.js b/static/webui/script.js index f8fe085c..ed71ed96 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -1260,21 +1260,28 @@ function doAcquireMod() { $("#mod-to-acquire").addClass("is-invalid").focus(); return; } - revalidateAuthz(() => { - $.post({ - url: "/custom/addItems?" + window.authz, - contentType: "application/json", - data: JSON.stringify([ - { - ItemType: uniqueName, - ItemCount: parseInt($("#mod-count").val()) + const count = parseInt($("#mod-count").val()); + if (count != 0) { + revalidateAuthz(() => { + $.post({ + url: "/custom/addItems?" + window.authz, + contentType: "application/json", + data: JSON.stringify([ + { + ItemType: uniqueName, + ItemCount: count + } + ]) + }).done(function () { + if (count > 0) { + toast(loc("code_succAdded")); + } else { + toast(loc("code_succRemoved")); } - ]) - }).done(function () { - document.getElementById("mod-to-acquire").value = ""; - updateInventory(); + updateInventory(); + }); }); - }); + } } const uiConfigs = [...$("#server-settings input[id]")].map(x => x.id);