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));
+5
View File
@@ -182,6 +182,11 @@ try {
<button id="selectMode" class="ghost toolbar-select" type="button">выбрать</button>
<span class="count" id="count" aria-live="polite"></span>
</div>
<div id="undoBar" class="undo-bar" role="status" aria-live="polite" hidden>
<span id="undoText"></span>
<button id="undoAction" class="link" type="button">отменить скрытие</button>
<button id="undoClose" class="link" type="button" aria-label="Закрыть">×</button>
</div>
<div class="bulk-bar" id="bulkBar" hidden>
<b id="bulkCount" aria-live="polite">0 выбрано</b>
<select id="bulkStatus" aria-label="Статус для выбранных">
+15
View File
@@ -413,6 +413,21 @@ summary:focus-visible,
.toolbar .ghost { flex: 0 0 auto; }
.count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.undo-bar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin: -8px 0 10px;
padding: 8px 12px;
border: 1px solid var(--accent);
border-radius: 12px;
background: var(--panel);
font-size: 13px;
}
.undo-bar[hidden] { display: none; }
.undo-bar #undoAction { margin-left: auto; }
.bulk-bar {
display: flex;
flex-wrap: wrap;