Limit player name lengths and fix vote UI defaults

This commit is contained in:
2026-02-02 19:39:32 +01:00
parent 1dc67879e5
commit f33545b184
11 changed files with 334 additions and 26 deletions

View File

@@ -195,7 +195,8 @@ function renderVotes() {
const votesMap = Object.fromEntries(state.myVotes.map((v) => [v.suggestionId, v.score]));
state.allSuggestions.forEach((s) => {
const li = buildCard(s, { showAuthor: true, allowEdit: !!state.me?.isAdmin });
const current = votesMap[s.id] ?? 0;
const hasVote = Object.prototype.hasOwnProperty.call(votesMap, s.id);
const current = hasVote ? votesMap[s.id] : 5; // start neutral when no prior vote
const footer = document.createElement("div");
footer.className = "vote-controls";
footer.innerHTML = `
@@ -339,6 +340,7 @@ function setupHandlers() {
e.preventDefault();
const username = $("login-username").value.trim();
const password = $("login-password").value;
if (username.length > 24) return toast("Username must be 24 characters or fewer.", true);
if (!username || !password) return toast(t("auth.needCredentials"), true);
try {
await api.login({ username, password });
@@ -362,6 +364,9 @@ function setupHandlers() {
const password = $("register-password").value;
const displayName = $("register-displayName").value.trim();
const adminKey = $("register-adminkey").value.trim();
if (!displayName) return toast(t("toast.displayNameRequired") || "Display name is required.", true);
if (username.length > 24) return toast("Username must be 24 characters or fewer.", true);
if (displayName.length > 16) return toast("Display name must be 16 characters or fewer.", true);
if (!username || !password) return toast(t("auth.needCredentials"), true);
try {
await api.register({ username, password, displayName, adminKey });
@@ -496,7 +501,7 @@ function buildCard(s, { showAuthor = false, allowDelete = false, allowEdit = fal
${visual}
<div class="card-body">
<div class="card-title-row">
<h3>${s.name}</h3>
<h3 class="card-title" title="${s.name}">${s.name}</h3>
<div class="title-meta">
${showAuthor && s.author ? `<span class="chip">${s.author}</span>` : ""}
${allowEdit ? `<button class="chip" data-edit="${s.id}" type="button">${t("card.edit")}</button>` : ""}