feat: keep undo available after hide-scope toast

Show a persistent undo bar for series/tag hiding so the action can be reverted after the notification closes.
This commit is contained in:
strsv committed 2026-11-07 00:49:10 +03:00
1 parent 49a7ab9918
commit 9943081baa
7 files changed
+61 -7

No files matched your search

+33 -4
View File
@@ -42,6 +42,7 @@ const state = {
itemsById: new Map(),
moods: [],
editingMood: null,
hideUndo: null,
hltbOffset: 0,
hltbLimit: 100,
hltbLoading: false,
@@ -765,6 +766,18 @@ function firstSelectedGame() {
return appid == null ? null : state.itemsById.get(appid);
}
function updateUndoBar() {
const bar = $("#undoBar");
if (!bar) return;
const undo = state.hideUndo;
const visible = !!(undo && undo.previous && undo.previous.length);
bar.hidden = !visible;
if (visible) {
$("#undoText").textContent =
`Скрыто игр: ${undo.previous.length}${undo.label ? ` (${undo.label})` : ""}.`;
}
}
async function hideScope(body) {
try {
const result = await api("/api/personal/hide-scope", {
@@ -775,21 +788,30 @@ async function hideScope(body) {
await loadGames(true);
await loadMeta();
const previous = result.previous || [];
state.hideUndo = {
previous,
label: body.scope === "series" ? "серия" : `тег «${body.tag}»`,
};
updateUndoBar();
toast(`Скрыто игр: ${result.updated}`, previous.length ? {
label: "отменить",
onClick: () => restoreBulk(previous),
onClick: () => restoreBulk(previous, true),
} : null);
} catch (err) {
toast(err.message);
}
}
async function restoreBulk(items) {
async function restoreBulk(items, clearHideUndo = false) {
try {
await api("/api/personal/restore", {
method: "POST",
body: JSON.stringify({ items }),
});
if (clearHideUndo) {
state.hideUndo = null;
updateUndoBar();
}
toast("Действие отменено");
await loadGames(true);
await loadMeta();
@@ -1584,7 +1606,7 @@ $("#bulkSeries").addEventListener("click", () => {
toast("Сначала выберите игру");
return;
}
if (!confirm(`Скрыть все игры серии «${game.name}»? Отменить можно в уведомлении.`)) return;
if (!confirm(`Скрыть все игры серии «${game.name}»? Отменить можно в уведомлении или на панели «отменить скрытие».`)) return;
hideScope({ scope: "series", appid: game.appid });
});
$("#bulkTag").addEventListener("click", () => {
@@ -1595,10 +1617,17 @@ $("#bulkTag").addEventListener("click", () => {
}
const tag = (prompt("Тег для скрытия:", (game.tags || [])[0] || "") || "").trim();
if (!tag) return;
if (!confirm(`Скрыть все игры с тегом «${tag}»? Отменить можно в уведомлении.`)) return;
if (!confirm(`Скрыть все игры с тегом «${tag}»? Отменить можно в уведомлении или на панели «отменить скрытие».`)) return;
hideScope({ scope: "tag", tag });
});
$("#bulkClear").addEventListener("click", clearSelection);
$("#undoAction").addEventListener("click", () => {
if (state.hideUndo) restoreBulk(state.hideUndo.previous, true);
});
$("#undoClose").addEventListener("click", () => {
state.hideUndo = null;
updateUndoBar();
});
updateBulkBar();
$("#more").addEventListener("click", () => loadGames(false));