feat: add HLTB status page and refresh installs incrementally
CI / test (push) Successful in 2m57s

This commit is contained in:
strsv committed 2026-11-06 23:14:54 +03:00
1 parent d92c7a1964
commit 31f94997d5
13 files changed
+255 -9

No files matched your search

+67
View File
@@ -42,6 +42,9 @@ const state = {
itemsById: new Map(),
moods: [],
editingMood: null,
hltbOffset: 0,
hltbLimit: 100,
hltbLoading: false,
};
const $ = (sel) => document.querySelector(sel);
@@ -1031,6 +1034,65 @@ $("#csGo").addEventListener("click", () => {
runRecommend();
});
function hltbDate(value) {
return value ? esc(String(value).slice(0, 10)) : "—";
}
function hltbRowHtml(item) {
const hours = (value) => value ? (Math.round(value * 10) / 10).toString() : "—";
return `
<tr data-appid="${item.appid}" tabindex="0" role="button" aria-label="Открыть ${esc(item.name)}">
<td class="hltb-name">${esc(item.name)}</td>
<td><span class="status-chip ${item.status === "match" ? "st-playing" : "st-ignore"}">${item.status === "match" ? "совпало" : "не найдено"}</span></td>
<td>${hours(item.main)}</td>
<td>${hours(item.extra)}</td>
<td>${hours(item.complete)}</td>
<td>${item.hltb_id ?? "—"}</td>
<td>${hltbDate(item.checked_at)}</td>
<td>${hltbDate(item.updated_at)}</td>
</tr>`;
}
async function loadHltb(reset = true) {
if (state.hltbLoading) return;
state.hltbLoading = true;
const body = $("#hltbBody");
if (reset) {
state.hltbOffset = 0;
body.innerHTML = '<tr><td colspan="8" class="muted">загрузка…</td></tr>';
}
try {
const params = new URLSearchParams({
limit: String(state.hltbLimit),
offset: String(state.hltbOffset),
});
const query = $("#hltbSearch").value.trim();
const status = $("#hltbFilter").value;
if (query) params.set("q", query);
if (status) params.set("status", status);
const data = await api(`/api/hltb/status?${params}`);
if (reset) body.innerHTML = "";
if (!data.items.length && reset) {
body.innerHTML = '<tr><td colspan="8" class="muted">нет проверенных игр</td></tr>';
}
body.insertAdjacentHTML("beforeend", data.items.map(hltbRowHtml).join(""));
bindRows(body);
state.hltbOffset += data.items.length;
$("#hltbSummary").textContent = `Проверено: ${data.checked} · совпало: ${data.matched}`;
$("#hltbMore").classList.toggle("hidden", state.hltbOffset >= data.total);
} catch (err) {
toast(err.message);
} finally {
state.hltbLoading = false;
}
}
const hltbSearch = debounce(() => loadHltb(true), 280);
$("#hltbSearch").addEventListener("input", hltbSearch);
$("#hltbFilter").addEventListener("change", () => loadHltb(true));
$("#hltbReload").addEventListener("click", () => loadHltb(true));
$("#hltbMore").addEventListener("click", () => loadHltb(false));
async function runRecommend(scroll = true) {
const text = $("#moodText").value.trim();
if (!state.preset && !text) {
@@ -1316,6 +1378,8 @@ function switchView(view) {
});
$("#libraryView").classList.toggle("hidden", view !== "library");
$("#recommendView").classList.toggle("hidden", view !== "recommend");
$("#hltbView").classList.toggle("hidden", view !== "hltb");
if (view === "hltb") loadHltb(true);
try {
const url = new URL(location.href);
if (view === "recommend") url.searchParams.set("view", "recommend");
@@ -1630,6 +1694,7 @@ async function pollJob(silent = false) {
toast(done);
await loadMeta();
await loadGames(true);
if (state.view === "hltb") await loadHltb(true);
} else {
toast("Не удалось выполнить — смотри лог в сайдбаре");
}
@@ -1761,6 +1826,8 @@ if ("serviceWorker" in navigator) {
}
if (mood) $("#moodText").value = mood;
if (preset || mood) await runRecommend(false);
} else if (params.get("view") === "hltb") {
switchView("hltb");
}
if (params.get("game")) openGame(params.get("game"));
})();