Files
bookhoard/templates/collection_rules.templ
T
John O'Keefe c54430c254 fix(podcasts): code-review pass over the session's UI surfaces
Findings from the systematic gotcha-class review before the browser
pass:

- The collection smart editor's Apply derived the collection NAME from
  document.title — which parses to "Smart Collection", RENAMING the
  collection on every apply. The server now renders the real name
  (data-collection-name) and the write path refuses to proceed without
  it.
- TestRenderingPartialsRender pinned the pre-episode-collections
  empty-state copy ("No books in this collection yet.") — updated to
  the shipped label ("Nothing in this collection yet."; collections
  hold episodes now).
- The deleted handler-local rule comparators (evaluateRule/
  compareValues — removed in item 3.4's single-evaluator refactor)
  left behind two unit-test files testing the duplicates; deleted.
  Their semantics remain covered at the service level
  (TestEvaluateRules_* over FieldMatches/EvaluateRules) and
  TestTextToString (which actually pins utils.PgTextString) stays.

Everything else reviewed clean against the gotcha classes: templ
whole-expression attrs, ?={ boolean attrs, JSONArg quoting in
x-init/data attrs, Alpine CSP store paths, htmx form-encoding, the
" assert escaping, and the aria-label selector contract on the
player's reload listener.
2026-10-30 19:38:39 -04:00

73 lines
3.2 KiB
Templ

package templates
// CollectionRules is the SMART-collection editor (plan item 3.4): the
// unified filter builder in the collection's scope. One vocabulary
// (services.FilterFieldsPayload — the same wire the All-Books builder
// renders), one engine: Apply writes the tree to the collection and
// the qf engine drives membership everywhere. Legacy rules arrays
// preload as their CONVERTED tree (RulesToFilterTree) — the upgrade
// happens at the first Apply, never silently at load.
templ CollectionRules(user User, collection CollectionData, fieldsJSON string, treeJSON string, scope string) {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Smart Collection - { collection.Name } - Bookhoard</title>
<link href="/static/style.css" rel="stylesheet"/>
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg"/>
</head>
<body
class={ "theme-" + user.Theme }
x-data="collectionRules"
data-collection-name={ collection.Name }
x-init={ "initCollectionRules('" + collection.ID + "', '" + scope + "', " + JSONArg(treeJSON) + ")" }
>
@Header(user, "/collections")
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="mb-6">
<button @click="backToCollection()" class="btn btn-secondary mb-4">
@Icon("arrow-left", "h-4 w-4")
Back to Collection
</button>
<div class="flex items-center gap-4">
<span class="grid place-items-center h-12 w-12 rounded-2xl shrink-0 text-2xl" style={ "background-color: var(--accent-muted); color: " + collection.Color }>{ collection.Icon }</span>
<div>
<h1 class="text-3xl font-bold" style="color: var(--text-primary)">{ collection.Name }</h1>
<p class="flex items-center gap-2" style="color: var(--text-secondary)">
<span class="badge text-xs" style="background-color: var(--accent-muted); color: var(--accent);">⚡ Smart</span>
if scope == "episodes" {
Episodes scope — membership recomputes live from the tree below.
} else {
Books scope — membership recomputes live from the tree below.
}
</p>
</div>
</div>
</div>
<!-- The unified builder island: SAME component + vocabulary as
the All-Books drawer (item 3.3's payload). Apply is
collection-specific (writes the tree; the engine does the
rest). The group-mode chips express ANY/ALL — the tree's
root mode IS the collection's match semantics. -->
<div
x-data="filterBuilderExtra"
data-filter-fields={ JSONArg(fieldsJSON) }
data-scope={ scope }
data-tree={ JSONArg(treeJSON) }
class="card p-6"
>
<div class="flex items-center justify-between mb-3 px-1">
<h2 class="text-lg font-bold" style="color: var(--text-primary)">Filter tree</h2>
</div>
@FilterBuilderRows("items")
<div class="mt-4 pt-4 border-t flex justify-end gap-2" style="border-color: var(--border);">
<button type="button" @click="backToCollection()" class="btn btn-secondary">Cancel</button>
<button type="button" @click="applyCollectionTree()" class="btn btn-primary">Apply to Collection</button>
</div>
</div>
</div>
</body>
</html>
}