diff --git a/app/routers/pages.py b/app/routers/pages.py index d1327a3..1801f93 100644 --- a/app/routers/pages.py +++ b/app/routers/pages.py @@ -77,12 +77,9 @@ async def _resolve_log_date(session: AsyncSession, day: str | None) -> date: def _log_page_context(target: date, paid: bool, user_lang: str = "en") -> dict: - s = get_settings() return { "selected_iso": target.isoformat(), "selected_month": target.strftime("%Y-%m"), - "current_tone": s.CASSANDRA_TONE.upper(), - "current_analysis": s.CASSANDRA_ANALYSIS.upper(), "paid": paid, "user_lang": user_lang, } diff --git a/app/templates/base.html b/app/templates/base.html index 97d1750..850fbca 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -130,12 +130,30 @@ // top-of-page inline script already wrote to . var themePill = document.getElementById('theme-toggle'); if (themePill) themePill.dataset.theme = document.documentElement.dataset.theme || 'light'; + // Sync the /log page's tone badge to the saved tone โ€” server-side + // first render defaults to "pro", but a returning NOVICE user + // should see "novice" before any toggle interaction. + window.cassandraSyncToneBadge(currentTone()); }); + // Sync the optional #tone-badge (currently used on the /log page) to + // the supplied tone. NOVICE renders as "novice"; INTERMEDIATE renders + // as "pro" โ€” matches the header toggle's display labels. Safe to call + // on pages that don't render the badge. + window.cassandraSyncToneBadge = function (tone) { + var badge = document.getElementById('tone-badge'); + if (!badge) return; + var label = (tone === 'NOVICE') ? 'novice' : 'pro'; + badge.className = 'badge badge--tone-' + label; + var span = badge.querySelector('[data-tone-label]'); + if (span) span.textContent = label; + }; + window.cassandraSetTone = function (newTone) { try { localStorage.setItem('cassandra.tone', newTone); } catch (e) {} var pill = document.getElementById('tone-toggle'); if (pill) pill.dataset.tone = newTone; + window.cassandraSyncToneBadge(newTone); // Trigger a re-fetch of every AI-driven HTMX target on the page. // Easiest: dispatch a custom event that the relevant elements // listen to. Simpler still: fire htmx.trigger on the well-known diff --git a/app/templates/log.html b/app/templates/log.html index cadc3f1..51d090e 100644 --- a/app/templates/log.html +++ b/app/templates/log.html @@ -8,9 +8,11 @@ selected {{ selected_iso }}  ยท  - new logs use: - tone {{ current_tone | lower }} - analysis {{ current_analysis | lower }} + {# Tone badge mirrors the header toggle. base.html's DOMContentLoaded + hook and cassandraSetTone() both update this element so the label + stays in step with the user's choice โ€” no need to re-render the + page when the toggle flips. #} + tone pro