Files
bookhoard/templates/library_switcher.templ
T
John O'Keefe 7bf5697c71 fix(podcasts): library switcher leaked literal "continue" and the podcasts option
The D13 podcast exclusion (9a148c23) was written as a templ
`if !IsBookLibrary(...) { continue }` — but templ markup control flow
has NO continue STATEMENT: codegen emitted the word as a TEXT node
(visible junk between options on every page's library subbar) and
rendered the podcasts option anyway, defeating the exclusion. The real
browser sweep caught what every Go/API test structurally cannot:
generated markup that renders wrong yet compiles clean.

Rewritten as an inverted guard (the idiomatic templ skip). New render
pin TestLibrarySwitcherExcludesPodcasts fails on both halves of the
original leak — the literal text AND the presence of the podcasts
option — so this codegen gotcha class stays tripped-wired.
2026-10-30 20:50:38 -04:00

90 lines
3.2 KiB
Templ

package templates
// LibrarySwitcher renders the sticky subbar: title + library select on
// the left (title hidden below `sm` — phones need the row width for the
// select + actions + the dashboard's stats widget), optional action
// buttons on the right. `center` is an
// optional slot between them (nil = unused) — the dashboard passes its
// "This Week" stats widget here so it participates in the bar's
// justify-between layout as the middle group.
templ LibrarySwitcher(libData []LibraryData, currentLibraryID string, title string, center templ.Component, actions ...templ.Component) {
<div
class="app-subbar backdrop-blur border-b"
style="background-color: color-mix(in srgb, var(--bg-primary) 88%, transparent); border-color: color-mix(in srgb, var(--text-primary) 6%, transparent);"
>
<div class="w-full px-4 sm:px-6 lg:px-8 py-3 flex items-center justify-between gap-4">
<div class="flex items-center gap-3 min-w-0">
if title != "" {
<span class="text-base font-bold tracking-tight shrink-0 hidden sm:inline" style="color: var(--text-primary)">{ title }</span>
} else {
<label class="text-sm font-medium" style="color: var(--text-secondary)">Library</label>
}
<select
id="library-select"
name="library_id"
class="input w-auto py-1.5 pr-8 cursor-pointer"
>
<option value="">All Libraries ({ TotalMediaCount(libData) })</option>
for _, lib := range libData {
// Podcasts libraries are feed-managed (plan D13): never
// in the book-library switcher — feeds surface via
// /podcasts only. Presentation-layer filter so every
// switcher consumer is correct at once.
// (templ markup control flow has NO `continue`
// statement — codegen emits it as literal TEXT and
// renders the option anyway, browser-sweep finding
// 2026-10-30; keep the skip as an inverted guard.)
if IsBookLibrary(lib.TypeName) {
if lib.Offline {
if lib.ID == currentLibraryID {
<option value={ lib.ID } selected>{ lib.Name } ({ lib.MediaCount }) — storage offline</option>
} else {
<option value={ lib.ID }>{ lib.Name } ({ lib.MediaCount }) — storage offline</option>
}
} else if lib.ID == currentLibraryID {
<option value={ lib.ID } selected>{ lib.Name } ({ lib.MediaCount })</option>
} else {
<option value={ lib.ID }>{ lib.Name } ({ lib.MediaCount })</option>
}
}
}
</select>
</div>
if center != nil {
@center
}
if len(actions) > 0 {
<div class="flex items-center gap-2">
for _, action := range actions {
@action
}
</div>
}
</div>
<div
id="loading-spinner"
class="hidden fixed inset-0 flex items-center justify-center z-50"
style="background-color: color-mix(in srgb, var(--bg-primary) 55%, transparent);"
>
<div class="animate-spin rounded-full h-12 w-12 border-b-2" style="border-color: var(--accent);"></div>
</div>
</div>
}
templ DashboardActions() {
<button
data-action="open-dashboard-settings"
class="icon-btn"
title="Customize Dashboard"
>
@Icon("grid", "h-5 w-5")
</button>
<button
data-action="reload-page"
class="icon-btn"
title="Refresh"
>
@Icon("refresh", "h-5 w-5")
</button>
}