feat: add manual HLTB matching
Allow setting an HLTB ID for missed games via POST /api/hltb/match and a small modal on the HLTB page.
This commit is contained in:
1 parent
92c4c62ca9
commit
6644a94d8c
5 files changed
+169
-2
No files matched your search
+49
-2
@@ -1122,10 +1122,12 @@ function hltbDate(value) {
|
||||
}
|
||||
|
||||
function hltbRowHtml(item) {
|
||||
const hours = (value) => value ? (Math.round(value * 10) / 10).toString() : "—";
|
||||
const hours = (value) => value ? (Math.round(value * 10) / 10).toString() : "-";
|
||||
const manual = item.status === "match" ? "" :
|
||||
` <button class="link hltb-manual" type="button" data-appid="${item.appid}" data-name="${esc(item.name)}">сопоставить</button>`;
|
||||
return `
|
||||
<tr data-appid="${item.appid}" tabindex="0" role="button" aria-label="Открыть ${esc(item.name)}">
|
||||
<td class="hltb-name">${esc(item.name)}</td>
|
||||
<td class="hltb-name">${esc(item.name)}${manual}</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>
|
||||
@@ -1176,6 +1178,51 @@ $("#hltbFilter").addEventListener("change", () => loadHltb(true));
|
||||
$("#hltbReload").addEventListener("click", () => loadHltb(true));
|
||||
$("#hltbMore").addEventListener("click", () => loadHltb(false));
|
||||
|
||||
function openHltbMatch(appid, name) {
|
||||
const dialog = $("#hltbMatchDialog");
|
||||
$("#hltbMatchName").textContent = name;
|
||||
$("#hltbMatchId").value = "";
|
||||
dialog.dataset.appid = appid;
|
||||
dialog.showModal();
|
||||
$("#hltbMatchId").focus();
|
||||
}
|
||||
|
||||
$("#hltbBody").addEventListener("click", (event) => {
|
||||
const button = event.target.closest(".hltb-manual");
|
||||
if (!button) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openHltbMatch(button.dataset.appid, button.dataset.name);
|
||||
}, true);
|
||||
|
||||
$("#hltbMatchForm").addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const dialog = $("#hltbMatchDialog");
|
||||
const appid = Number(dialog.dataset.appid);
|
||||
const hltbId = Number($("#hltbMatchId").value);
|
||||
if (!Number.isInteger(hltbId) || hltbId <= 0) {
|
||||
toast("Введи HLTB ID");
|
||||
return;
|
||||
}
|
||||
const button = $("#hltbMatchSave");
|
||||
button.disabled = true;
|
||||
try {
|
||||
const data = await api("/api/hltb/match", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ appid, hltb_id: hltbId }),
|
||||
});
|
||||
dialog.close();
|
||||
toast(`HLTB: ${data.estimated_hours} ч`);
|
||||
await loadHltb(true);
|
||||
await loadMeta();
|
||||
} catch (err) {
|
||||
toast(err.message);
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
$("#hltbMatchCancel").addEventListener("click", () => $("#hltbMatchDialog").close());
|
||||
|
||||
async function runRecommend(scroll = true) {
|
||||
const text = $("#moodText").value.trim();
|
||||
if (!state.preset && !text) {
|
||||
|
||||
@@ -510,6 +510,20 @@ try {
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<dialog id="hltbMatchDialog" class="modal small" aria-labelledby="hltbMatchTitle">
|
||||
<form class="hltb-match-form" id="hltbMatchForm">
|
||||
<h2 id="hltbMatchTitle">Сопоставить с HLTB</h2>
|
||||
<p class="muted" id="hltbMatchName"></p>
|
||||
<label>HLTB ID
|
||||
<input id="hltbMatchId" type="number" min="1" placeholder="например, 11097">
|
||||
</label>
|
||||
<div class="modal-actions">
|
||||
<button type="submit" class="primary" id="hltbMatchSave">Сохранить</button>
|
||||
<button type="button" class="link" id="hltbMatchCancel">отмена</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<dialog id="modal" class="modal" aria-labelledby="modalTitle">
|
||||
<div id="modalBody"></div>
|
||||
</dialog>
|
||||
|
||||
@@ -1152,6 +1152,11 @@ html[data-theme="light"] .game-table tbody tr:hover { background: rgba(23, 32, 5
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
.modal::backdrop { background: rgba(4, 6, 10, .72); backdrop-filter: blur(6px); }
|
||||
.modal.small { width: min(420px, calc(100vw - 36px)); }
|
||||
.hltb-match-form { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
|
||||
.hltb-match-form h2 { margin: 0; font-size: 18px; }
|
||||
.hltb-match-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
|
||||
.modal-actions { display: flex; align-items: center; gap: 10px; }
|
||||
|
||||
.modal-grid {
|
||||
display: grid;
|
||||
|
||||
Reference in new issue
Block a user