feat: add undo for bulk personal actions
CI / test (push) Successful in 35s

This commit is contained in:
strsv committed 2026-11-06 18:24:13 +03:00
1 parent 94cc60b393
commit 1bd4ca8c53
10 files changed
+143 -22

No files matched your search

+36 -4
View File
@@ -366,7 +366,7 @@ async function fillDescriptions() {
}
}
function toast(message) {
function toast(message, action = null) {
let el = $("#toast");
if (!el) {
el = document.createElement("div");
@@ -374,10 +374,24 @@ function toast(message) {
el.className = "toast";
document.body.appendChild(el);
}
el.textContent = message;
el.innerHTML = "";
const text = document.createElement("span");
text.textContent = message;
el.appendChild(text);
if (action) {
const button = document.createElement("button");
button.type = "button";
button.className = "toast-action";
button.textContent = action.label;
button.addEventListener("click", () => {
el.classList.remove("show");
action.onClick();
});
el.appendChild(button);
}
el.classList.add("show");
clearTimeout(el._timer);
el._timer = setTimeout(() => el.classList.remove("show"), 2600);
el._timer = setTimeout(() => el.classList.remove("show"), action ? 8000 : 2600);
}
/* ---------- meta ---------- */
@@ -556,10 +570,28 @@ async function bulkUpdate(fields) {
method: "POST",
body: JSON.stringify({ appids, ...fields }),
});
toast(`Обновлено игр: ${result.updated}`);
clearSelection();
await loadGames(true);
await loadMeta();
const previous = result.previous || [];
toast(`Обновлено игр: ${result.updated}`, previous.length ? {
label: "отменить",
onClick: () => restoreBulk(previous),
} : null);
} catch (err) {
toast(err.message);
}
}
async function restoreBulk(items) {
try {
await api("/api/personal/restore", {
method: "POST",
body: JSON.stringify({ items }),
});
toast("Действие отменено");
await loadGames(true);
await loadMeta();
} catch (err) {
toast(err.message);
}