diff --git a/assets/css/base/_typography.css b/assets/css/base/_typography.css index 9ecba8d..21a8594 100644 --- a/assets/css/base/_typography.css +++ b/assets/css/base/_typography.css @@ -34,6 +34,16 @@ h1, h2 { font-family: 'DM Serif Display', serif; font-weight: 400; letter-spacin h1 { max-width: 590px; font-size: clamp(56px, 6vw, 87px); line-height: .93; } h1 em { color: var(--color-coral); font-weight: 400; } +.settings-header { + font-size: 3rem; +} + +.settings-subtitle { + font-size: 1rem;; + color: var(--color-base-content); + opacity: 0.7; +} + @media (max-width: 650px) { h1 { font-size: clamp(51px, 15vw, 68px); } } \ No newline at end of file diff --git a/assets/css/layouts/_nav.css b/assets/css/layouts/_nav.css index 18093e0..c0ce8d6 100644 --- a/assets/css/layouts/_nav.css +++ b/assets/css/layouts/_nav.css @@ -14,7 +14,12 @@ .nav-links a { transition: opacity .2s; } .nav-links a:hover { opacity: .55; } .nav-links a.nav-cta:hover { opacity: 1; } -.nav-user { color: var(--color-muted); font-weight: 500; } +.nav-user-menu { position: relative; } +.nav-user-menu summary { display: flex; align-items: center; gap: 6px; list-style: none; cursor: pointer; color: var(--color-muted); font-weight: 500; } +.nav-user-menu summary::-webkit-details-marker { display: none; } +.nav-user-menu summary::after { content: "▾"; font-size: 10px; } +.nav-user-menu-panel { position: absolute; right: 0; top: calc(100% + 14px); z-index: 20; display: grid; gap: 12px; min-width: 170px; padding: 16px; border-radius: 10px; background: var(--color-canvas-raised); box-shadow: 0 18px 40px rgba(23,53,45,.15); } +html[data-theme="dark"] .nav-user-menu-panel { box-shadow: 0 18px 40px rgba(0, 0, 0, .45); } .nav-cta, .primary-button, .light-button { display: inline-flex; align-items: center; justify-content: center; gap: 13px; border-radius: 999px; font-weight: 600; transition: transform .2s, background .2s; @@ -37,5 +42,6 @@ .nav-links.open { display: flex; } .nav-cta { width: 100%; } .nav-links { display: none; position: absolute; top: 65px; left: 0; right: 0; padding: 24px; flex-direction: column; align-items: stretch; gap: 22px; border-radius: 10px; background: var(--color-canvas-raised); box-shadow: 0 18px 40px rgba(23,53,45,.15); } + .nav-user-menu-panel { position: static; min-width: 0; padding: 12px 0 0; background: transparent; box-shadow: none; } html[data-theme="dark"] .nav-links { box-shadow: 0 18px 40px rgba(0, 0, 0, .45); } } \ No newline at end of file diff --git a/assets/js/nav.js b/assets/js/nav.js index 810c94e..4e72b9c 100644 --- a/assets/js/nav.js +++ b/assets/js/nav.js @@ -4,6 +4,11 @@ const WRAP = ".nav-wrap"; const TOGGLE = ".menu-button"; const LINKS = ".nav-links"; +const USER_MENU = ".nav-user-menu"; + +const closeUserMenus = () => { + document.querySelectorAll(`${USER_MENU}[open]`).forEach((menu) => menu.removeAttribute("open")); +}; const setOpen = (open) => { const wrap = document.querySelector(WRAP); @@ -26,6 +31,16 @@ document.addEventListener("click", (event) => { return; } + if (target.closest(`${USER_MENU} a`)) { + closeUserMenus(); + setOpen(false); + return; + } + + if (!target.closest(USER_MENU)) { + closeUserMenus(); + } + if (target.closest(`${LINKS} a`)) { setOpen(false); return; @@ -39,6 +54,7 @@ document.addEventListener("click", (event) => { document.addEventListener("keydown", (event) => { if (event.key === "Escape") { setOpen(false); + closeUserMenus(); } }); diff --git a/lib/chesstrainer/attempts.ex b/lib/chesstrainer/attempts.ex index 492224a..74f3766 100644 --- a/lib/chesstrainer/attempts.ex +++ b/lib/chesstrainer/attempts.ex @@ -70,6 +70,39 @@ defmodule Chesstrainer.Attempts do |> Repo.one() end + @doc """ + Aggregated attempt totals for `user_id`. + + Returns a map with `:attempts`, `:solved`, `:failed` and `:endgames` (the + number of distinct puzzles tried). + """ + def stats_for_user(user_id) do + Attempt + |> where([a], a.user_id == ^user_id) + |> select([a], %{ + attempts: count(a.id), + solved: filter(count(a.id), a.outcome == :solved), + failed: filter(count(a.id), a.outcome == :failed), + endgames: count(a.endgame_id, :distinct) + }) + |> Repo.one() + end + + @doc """ + The attempts of `user_id`, newest first, with each endgame preloaded. + + Pass `limit: n` to cap the history (the profile page shows a recent window; + exports pass no limit). + """ + def list_attempts_for_user(user_id, opts \\ []) do + Attempt + |> where([a], a.user_id == ^user_id) + |> order_by([a], desc: a.inserted_at) + |> maybe_limit(Keyword.get(opts, :limit)) + |> preload(:endgame) + |> Repo.all() + end + @doc """ The distinct endgame ids `user_id` has attempted in the last `days` days. @@ -87,4 +120,7 @@ defmodule Chesstrainer.Attempts do end defp rated(query), do: where(query, [a], not is_nil(a.rated_at)) + + defp maybe_limit(query, nil), do: query + defp maybe_limit(query, limit) when is_integer(limit), do: limit(query, ^limit) end diff --git a/lib/chesstrainer_web/components/layouts.ex b/lib/chesstrainer_web/components/layouts.ex index 3d797c8..8f3912f 100644 --- a/lib/chesstrainer_web/components/layouts.ex +++ b/lib/chesstrainer_web/components/layouts.ex @@ -67,6 +67,7 @@ defmodule ChesstrainerWeb.Layouts do assigns |> assign(:nav_links, nav_links(assigns.current_scope)) |> assign(:start_href, start_href(assigns.current_scope)) + |> assign(:user, signed_in_user(assigns.current_scope)) ~H"""
@@ -92,11 +93,22 @@ defmodule ChesstrainerWeb.Layouts do