fix: complete v1.2 account and profile P0 fixes

This commit is contained in:
2026-08-10 00:12:53 +08:00
parent 587962f9c9
commit 97ca20413e
14 changed files with 346 additions and 12 deletions
+67 -2
View File
@@ -178,6 +178,7 @@ function updateUserUI() {
chip.append(avatar, name);
$("#auth-button").textContent = state.user ? "退出登录" : "登录 / 注册";
$("#admin-entry").hidden = !state.user?.is_staff;
if (!state.user) $("#home-match-history").hidden = true;
}
async function loadUser() {
@@ -188,6 +189,7 @@ async function loadUser() {
state.user = null;
}
updateUserUI();
await loadHomeMatchHistory();
}
function card({ meta, title, body, foot, action, onClick, disabled = false }) {
@@ -807,6 +809,15 @@ async function loadProfile() {
metrics.append(item);
});
root.append(heading, pet, metrics);
if (profile.recent_matches?.length) {
const matchTitle = document.createElement("h3");
matchTitle.className = "profile-subtitle";
matchTitle.textContent = "最近实时对局";
const matchList = document.createElement("div");
matchList.className = "match-history-list";
renderMatchHistory(matchList, profile.recent_matches);
root.append(matchTitle, matchList);
}
if (profile.recent_games?.length) {
const gameTitle = document.createElement("h3");
gameTitle.className = "profile-subtitle";
@@ -832,6 +843,51 @@ async function loadProfile() {
}
}
function renderMatchHistory(root, matches) {
root.replaceChildren(
...matches.map((match) => {
const item = document.createElement("article");
item.className = `match-history-item result-${match.result}`;
const summary = document.createElement("div");
const title = document.createElement("b");
title.textContent = `${match.contest} · 对手 ${match.opponent}`;
const time = document.createElement("span");
time.textContent = new Date(match.completed_at).toLocaleString();
summary.append(title, time);
const result = document.createElement("div");
const resultLabel = document.createElement("strong");
resultLabel.textContent =
match.result === "win" ? "胜利" : match.result === "loss" ? "惜败" : "平局";
const delta = document.createElement("span");
const sign = match.rating_delta > 0 ? "+" : "";
delta.textContent = `Rating ${sign}${match.rating_delta}${match.rating_after}`;
result.append(resultLabel, delta);
item.append(summary, result);
return item;
})
);
}
async function loadHomeMatchHistory() {
const section = $("#home-match-history");
if (!state.user) {
section.hidden = true;
return;
}
try {
const profile = await api("progression/me/");
if (!profile.recent_matches?.length) {
section.hidden = true;
return;
}
renderMatchHistory($("#home-match-list"), profile.recent_matches);
section.hidden = false;
} catch (error) {
section.hidden = true;
if (![401, 403].includes(error.status)) console.warn(error);
}
}
const MATH_SYMBOLS = [
["∑", "求和", "一组数或表达式的总和", "\\sum"],
["∏", "连乘", "一组数或表达式的乘积", "\\prod"],
@@ -1189,6 +1245,7 @@ function bindUI() {
window.HuluRealtime?.reset();
state.user = null;
updateUserUI();
if ($("#view-profile").classList.contains("active")) await loadProfile();
showToast("已退出登录");
});
$$("dialog .dialog-close").forEach((button) => button.addEventListener("click", () => button.closest("dialog").close()));
@@ -1209,7 +1266,11 @@ function bindUI() {
state.user = await api("accounts/login/", { method: "POST", body: Object.fromEntries(new FormData(event.target)) });
$("#auth-dialog").close();
updateUserUI();
await loadContent();
await Promise.all([
loadContent(),
loadHomeMatchHistory(),
$("#view-profile").classList.contains("active") ? loadProfile() : null,
]);
showToast("登录成功");
} catch (error) {
$("#auth-error").textContent = error.message;
@@ -1221,7 +1282,11 @@ function bindUI() {
state.user = await api("accounts/register/", { method: "POST", body: Object.fromEntries(new FormData(event.target)) });
$("#auth-dialog").close();
updateUserUI();
await loadContent();
await Promise.all([
loadContent(),
loadHomeMatchHistory(),
$("#view-profile").classList.contains("active") ? loadProfile() : null,
]);
showToast("账号和数学档案已建立");
} catch (error) {
$("#auth-error").textContent = error.message;