From 1a62c353c1643d1d27becd8510122700f8db21bd Mon Sep 17 00:00:00 2001 From: Frank Tovar Date: Fri, 6 Feb 2026 23:01:15 +0100 Subject: [PATCH] Enforce suggest limit in UI --- wwwroot/app.js | 1 + wwwroot/js/i18n.js | 2 ++ wwwroot/js/ui.js | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/wwwroot/app.js b/wwwroot/app.js index c19abf6..8ff3ab5 100644 --- a/wwwroot/app.js +++ b/wwwroot/app.js @@ -119,6 +119,7 @@ function setupHandlers() { if (openSuggestBtn) { openSuggestBtn.addEventListener("click", (e) => { e.preventDefault(); + if (openSuggestBtn.disabled) return; if (state.phase !== "Suggest") return; openNewSuggestionModal(); }); diff --git a/wwwroot/js/i18n.js b/wwwroot/js/i18n.js index 51e84f2..064352e 100644 --- a/wwwroot/js/i18n.js +++ b/wwwroot/js/i18n.js @@ -44,6 +44,7 @@ const translations = { "suggest.title": "Suggest games (up to 5)", "suggest.new": "Add new suggestion", "suggest.addButton": "Suggest a game", + "suggest.maxReached": "max limit reached", "suggest.jokerAddButton": "🃏 Joker: add another game", "suggest.hint": "Only you can see your suggestions until voting starts.", "form.gameName": "Game name *", @@ -212,6 +213,7 @@ const translations = { "suggest.title": "Schlage Spiele vor (bis zu 5)", "suggest.new": "Neuen Vorschlag hinzufügen", "suggest.addButton": "Spiel vorschlagen", + "suggest.maxReached": "Limit erreicht", "suggest.jokerAddButton": "🃏 Joker: Weiteres Spiel hinzufügen", "suggest.hint": "Nur du siehst deine Vorschläge bis zum Start der Abstimmung.", "form.gameName": "Spielname *", diff --git a/wwwroot/js/ui.js b/wwwroot/js/ui.js index 036e33a..9693ecb 100644 --- a/wwwroot/js/ui.js +++ b/wwwroot/js/ui.js @@ -129,6 +129,16 @@ export function renderWelcome() { el.textContent = t("auth.welcome", { name }); } +function updateSuggestButtonState() { + const btn = $("open-suggest-modal"); + if (!btn) return; + const limit = 5; + const count = state.mySuggestions?.length ?? 0; + const blocked = count >= limit; + btn.disabled = blocked || state.phase !== "Suggest"; + btn.textContent = blocked ? t("suggest.maxReached") : t("suggest.addButton"); +} + export function renderMySuggestions() { const wrap = $("my-suggestions"); if (!wrap) return; @@ -141,6 +151,7 @@ export function renderMySuggestions() { buildCard(s, { showAuthor: false, allowDelete, allowEdit, lockTitle }), ), ); + updateSuggestButtonState(); } export function renderAllSuggestions() {