Simplify auth UI with single toggle and headings

This commit is contained in:
2026-02-02 17:41:37 +01:00
parent 7a71e4831d
commit 30b0bf8481
3 changed files with 23 additions and 9 deletions

View File

@@ -53,9 +53,14 @@ function setAuthMode(mode) {
document.querySelectorAll(".auth-form").forEach(form => {
form.classList.toggle("hidden", form.dataset.mode !== mode);
});
document.querySelectorAll("[data-auth-tab]").forEach(btn => {
btn.classList.toggle("active", btn.dataset.authTab === mode);
});
const title = $("auth-title");
const toggleBtn = $("auth-toggle");
if (title) {
title.textContent = mode === "login" ? t("auth.loginHeading") : t("auth.registerHeading");
}
if (toggleBtn) {
toggleBtn.textContent = mode === "login" ? t("auth.switchToRegister") : t("auth.switchToLogin");
}
}
function clearUserState() {
@@ -299,9 +304,10 @@ function renderPhaseTitles() {
}
function setupHandlers() {
document.querySelectorAll("[data-auth-tab]").forEach(btn => {
btn.addEventListener("click", () => setAuthMode(btn.dataset.authTab));
});
const toggleAuth = $("auth-toggle");
if (toggleAuth) {
toggleAuth.addEventListener("click", () => setAuthMode(state.authMode === "login" ? "register" : "login"));
}
setAuthMode(state.authMode);
const langSelects = Array.from(document.querySelectorAll(".lang-select"));

View File

@@ -16,9 +16,9 @@
<div class="auth-logo">
<img src="logo.png" alt="CoopGameChooser logo" />
</div>
<div class="stack horizontal">
<button class="ghost active" data-auth-tab="login" type="button" data-i18n="auth.loginTab">Log in</button>
<button class="ghost" data-auth-tab="register" type="button" data-i18n="auth.registerTab">Register</button>
<div class="stack">
<h2 id="auth-title" data-i18n="auth.loginHeading">Log in</h2>
<button class="ghost" id="auth-toggle" type="button" data-i18n="auth.switchToRegister">Need an account? Register</button>
</div>
<div class="stack lang-field">
<span class="label" data-i18n="lang.label">Language</span>

View File

@@ -12,6 +12,10 @@ const translations = {
"auth.adminKey": "Admin key (optional)",
"auth.loginSubmit": "Log in",
"auth.registerSubmit": "Create account",
"auth.loginHeading": "Log in",
"auth.registerHeading": "Create account",
"auth.switchToRegister": "Need an account? Register",
"auth.switchToLogin": "Have an account? Log in",
"auth.logout": "Logout",
"auth.welcome": "Welcome, {name}!",
"auth.defaultName": "Player",
@@ -111,6 +115,10 @@ const translations = {
"auth.adminKey": "Admin-Schlüssel (optional)",
"auth.loginSubmit": "Anmelden",
"auth.registerSubmit": "Konto erstellen",
"auth.loginHeading": "Anmelden",
"auth.registerHeading": "Konto erstellen",
"auth.switchToRegister": "Noch kein Konto? Registrieren",
"auth.switchToLogin": "Schon ein Konto? Anmelden",
"auth.logout": "Abmelden",
"auth.welcome": "Willkommen, {name}!",
"auth.defaultName": "Spieler",