redraw updated table when using active toggle switch

This commit is contained in:
Corban-Lee Jones 2024-06-05 14:20:52 +01:00
parent e486885a03
commit 1e9b9e905d

View File

@ -78,12 +78,20 @@ function initSubscriptionTable() {
$("#subTable").on("change", ".sub-toggle-active", async function () {
// Lock all toggles to soft-prevent spam.
// There is a rate limit, but allowing the user to
// reach it from this toggle would be bad.
$(".sub-toggle-active").prop("disabled", true);
try {
const active = $(this).prop("checked");
const sub = subTable.row($(this).closest("tr")).data();
// Update the table row
sub.active = active;
subTable.data(sub).draw();
// Update the database
const subPrimaryKey = await saveSubscription(
sub.id,
sub.name,
@ -101,6 +109,7 @@ $("#subTable").on("change", ".sub-toggle-active", async function () {
);
}
finally {
// Re-enable toggles after 500ms
setTimeout(() => { $(".sub-toggle-active").prop("disabled", false); }, 500)
}
});