ui: log page tone badge follows the toggle (novice / pro)

The Strategic Log Archive panel header used to show two engineery
badges sourced from server config:
  new logs use: tone intermediate analysis speculative

Both were misleading:
- The tone badge described the SERVER's generator setting, not the
  user's reading preference — confusingly disconnected from the
  Novice | Pro toggle in the topbar that actually controls what AI
  panels render.
- The analysis flag is always SPECULATIVE in production, so the badge
  carried no information.

Drop the "new logs use:" prefix and the analysis badge. The tone badge
now mirrors the user's toggle: NOVICE → "novice", INTERMEDIATE → "pro"
(same data values; just the display label flips, matching the header
relabel from 3e1a14f).

Wiring lives in base.html: a new cassandraSyncToneBadge(tone) helper
updates the #tone-badge element when present. Called from
DOMContentLoaded (so the initial badge picks up the localStorage tone)
and from cassandraSetTone (so toggling the header updates the badge
live, without a page refresh).

current_tone / current_analysis are removed from _log_page_context —
log.html was the only consumer and neither key is referenced now.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Giorgio Gilestro 2026-05-29 12:17:49 +02:00
parent 259146ecdc
commit 6c4c711830
3 changed files with 23 additions and 6 deletions

View file

@ -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,
}

View file

@ -130,12 +130,30 @@
// top-of-page inline script already wrote to <html data-theme>.
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

View file

@ -8,9 +8,11 @@
<span class="meta">
selected {{ selected_iso }}
&nbsp;·&nbsp;
<span class="meta__hint">new logs use:</span>
<span class="badge badge--tone-{{ current_tone | lower }}">tone {{ current_tone | lower }}</span>
<span class="badge badge--analysis-{{ current_analysis | lower }}">analysis {{ current_analysis | lower }}</span>
{# 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. #}
<span id="tone-badge" class="badge badge--tone-pro">tone <span data-tone-label>pro</span></span>
</span>
</div>