feat: add recommendation feedback
CI / test (push) Successful in 19s

This commit is contained in:
strsv committed 2026-11-06 09:20:28 +03:00
1 parent f25d218756
commit 044d0279b3
17 files changed
+288 -20

No files matched your search

+41
View File
@@ -31,6 +31,7 @@ const state = {
meta: null,
selectionMode: false,
selected: new Set(),
recommendContext: null,
};
const $ = (sel) => document.querySelector(sel);
@@ -249,6 +250,12 @@ function cardHtml(g, mode = "library") {
: `<p class="card-desc loading" data-appid="${g.appid}">Описание подгружается…</p>`;
const matched = mode === "reco" && g.matched && g.matched.length
? `<p class="matched">${g.matched.map(esc).join(" · ")}</p>` : "";
const feedback = mode === "reco" ? `
<div class="feedback-row">
${[["like", "в точку"], ["dislike", "не то"], ["played", "уже играл"], ["ignore", "не хочу"]]
.map(([verdict, label]) => `<button class="fb${g.feedback === verdict ? " active" : ""}" type="button"
data-verdict="${verdict}" data-appid="${g.appid}">${label}</button>`).join("")}
</div>` : "";
return `
<article class="card" data-appid="${g.appid}" tabindex="0" role="button" aria-label="Открыть ${esc(g.name)}">
<div class="cover">
@@ -262,6 +269,7 @@ function cardHtml(g, mode = "library") {
<div class="card-genres">${genres}</div>
${matched}
${desc}
${feedback}
<div class="card-status">${statusChip(g.status)}</div>
</div>
</article>`;
@@ -306,6 +314,7 @@ function bindCards(root) {
if (card.dataset.bound) return;
card.dataset.bound = "1";
const activate = (event) => {
if (event && event.target instanceof Element && event.target.closest(".feedback-row")) return;
if (state.selectionMode && card.closest("#grid")) {
if (event && event.target instanceof Element && event.target.closest(".select-box")) return;
toggleSelected(Number(card.dataset.appid));
@@ -647,6 +656,7 @@ async function runRecommend(scroll = true) {
min_review: Number($("#optReview").value),
limit: 36,
};
state.recommendContext = { preset: state.preset, mood: state.preset ? null : text };
const data = await api("/api/recommend", { method: "POST", body: JSON.stringify(body) });
const mood = data.mood;
$("#recoSummary").classList.remove("hidden");
@@ -667,6 +677,37 @@ async function runRecommend(scroll = true) {
}
}
recoGrid.addEventListener("click", async (event) => {
const button = event.target instanceof Element && event.target.closest("button[data-verdict]");
if (!button) return;
event.stopPropagation();
const context = state.recommendContext;
if (!context) return;
const appid = Number(button.dataset.appid);
const verdict = button.dataset.verdict;
button.disabled = true;
try {
await api("/api/feedback", {
method: "POST",
body: JSON.stringify({ appid, verdict, preset: context.preset, mood: context.mood }),
});
const row = button.closest(".feedback-row");
row.querySelectorAll("button").forEach((item) => item.classList.toggle("active", item === button));
button.disabled = false;
if (verdict === "like") {
toast("Учли: в точку");
} else {
const card = button.closest(".card");
card.classList.add("dismissed");
setTimeout(() => card.remove(), 220);
toast("Учли: больше не покажем под этим настроением");
}
} catch (err) {
button.disabled = false;
toast(err.message);
}
});
/* ---------- game modal ---------- */
function modalSkeleton() {
+15 -1
View File
@@ -453,7 +453,21 @@ html[data-theme="light"] .select-box {
min-height: 0;
margin-top: 6px;
}
.grid.list-view .card-status { margin-top: 6px; }
.grid.list-view .feedback-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.feedback-row .fb {
padding: 3px 7px;
border-radius: 6px;
border: 1px solid var(--border);
background: transparent;
color: var(--muted);
font-size: 10.5px;
transition: .15s;
}
.feedback-row .fb:hover { border-color: var(--border-strong); color: var(--text); }
.feedback-row .fb.active { border-color: transparent; background: var(--accent); color: #0a0d13; }
.card.dismissed { opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s; }
.card-status { margin-top: 6px; }
.grid.list-view .select-box { right: 6px; bottom: 6px; width: 24px; height: 24px; }
.card {