feat(phase 4b): dark/light theme toggle + file-upload permanently out-of-scope
## Slice A — explicit dark/light toggle projax now ships with two palettes and a 1y cookie to remember the choice. Dark is the new default; ☀ button in the header nav flips to light and writes projax_theme=light. Server reads the cookie via themeFromRequest(r) and injects Theme + ThemeColor into every template via the centralised render(w, r, …) path, so first paint never flashes the wrong theme. Inline JS in layout.tmpl handles the toggle without a server roundtrip. Every panel colour now lives in a CSS variable under :root[data-theme=dark|light]; the only hardcoded hex values left are inside those two :root blocks. A future palette tweak is one edit, not 30 selectors. Graph node colours, kind-badges, highlights and warn/ok/bad all have parallel dark/light values picked for contrast. Standalone SVG download bakes the light palette inline because the downloaded asset has no parent :root providing vars — m's existing snapshots stay print-friendly regardless of his current cookie. Login page keeps its embedded dark CSS — it's the gateway, intentionally always dark. Tests: TestThemeDefaultIsDark, TestThemeCookieRoundTrips, TestThemeCookieUnknownFallsBackToDark, TestThemeTogglePagesShareSameTheme, TestThemeToggleScriptPresent, TestThemeColorMetaHelper. Full suite green. ## Slice B — file-upload permanently out of scope (m, 2026-05-17) docs/design.md moves "File uploads / in-projax storage" from the §3c parked list to a permanent "Out of scope (decided 2026-05-17)" clause with the rationale: PER is the cross-reference index, not the file system. docs/standards/per.md gains the same explicit clause so future shifts working from the PER standard see the constraint where they look. Memory note filed so future workers don't re-propose multipart uploads, attachments tables, or documents buckets. ## docs/design.md §13 Theming Documents the toggle approach, cookie semantics, palette table, the standalone-SVG carve-out, the login-page exception, and the 4b out-of-scope (prefers-color-scheme detection, per-page overrides, transitions on swap).
This commit is contained in:
@@ -358,10 +358,10 @@ func (s *Server) handleTree(w http.ResponseWriter, r *http.Request) {
|
||||
// Fragment swap: only the tree section. The browser keeps the chip
|
||||
// chrome (which itself is HTMX-driven) up to date because we push the
|
||||
// URL via hx-push-url at chip-click time.
|
||||
s.render(w, "tree_section", data)
|
||||
s.render(w, r, "tree_section", data)
|
||||
return
|
||||
}
|
||||
s.render(w, "tree", data)
|
||||
s.render(w, r, "tree", data)
|
||||
}
|
||||
|
||||
// linkKindsByItem returns a map: itemID → set of ref_types attached to that item.
|
||||
@@ -430,7 +430,7 @@ func (s *Server) handleDetail(w http.ResponseWriter, r *http.Request) {
|
||||
s.Logger.Warn("detail docs", "path", it.PrimaryPath(), "err", err)
|
||||
}
|
||||
documents := computePERs(it.PrimaryPath(), docs)
|
||||
s.render(w, "detail", map[string]any{
|
||||
s.render(w, r, "detail", map[string]any{
|
||||
"Title": it.Title,
|
||||
"Item": it,
|
||||
"ParentOptions": parents,
|
||||
@@ -602,7 +602,7 @@ func (s *Server) handleNewForm(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
parent = p
|
||||
}
|
||||
s.render(w, "new", map[string]any{
|
||||
s.render(w, r, "new", map[string]any{
|
||||
"Title": "new",
|
||||
"Parent": parent,
|
||||
"StatusOptions": []string{"active", "done", "archived"},
|
||||
@@ -654,7 +654,7 @@ func (s *Server) handleClassify(w http.ResponseWriter, r *http.Request) {
|
||||
s.fail(w, r, err)
|
||||
return
|
||||
}
|
||||
s.render(w, "classify", map[string]any{
|
||||
s.render(w, r, "classify", map[string]any{
|
||||
"Title": "classify",
|
||||
"Orphans": orphans,
|
||||
"ParentOptions": parents,
|
||||
@@ -688,12 +688,27 @@ func (s *Server) parentOptions(ctx context.Context) ([]ParentOption, error) {
|
||||
// (buildForest + nodeHasAllTags removed in Phase 3b — superseded by
|
||||
// applyTreeFilter in tree_filter.go which handles every filter dimension.)
|
||||
|
||||
func (s *Server) render(w http.ResponseWriter, name string, data map[string]any) {
|
||||
// render writes the named page to w, looking up the user's chosen theme from
|
||||
// the projax_theme cookie on r so the layout's `<html data-theme=…>` and
|
||||
// `<meta name="theme-color">` flip together. Templates that omit the layout
|
||||
// (HTMX fragments, the login page) ignore the injection silently.
|
||||
func (s *Server) render(w http.ResponseWriter, r *http.Request, name string, data map[string]any) {
|
||||
t, ok := s.pages[name]
|
||||
if !ok {
|
||||
http.Error(w, "unknown page: "+name, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if data == nil {
|
||||
data = map[string]any{}
|
||||
}
|
||||
theme := themeFromRequest(r)
|
||||
// Don't clobber if a caller set it explicitly (e.g. tests).
|
||||
if _, set := data["Theme"]; !set {
|
||||
data["Theme"] = theme
|
||||
}
|
||||
if _, set := data["ThemeColor"]; !set {
|
||||
data["ThemeColor"] = themeColorForMeta(theme)
|
||||
}
|
||||
entry := "layout"
|
||||
switch name {
|
||||
case "login":
|
||||
@@ -727,7 +742,7 @@ func (s *Server) fail(w http.ResponseWriter, r *http.Request, err error) {
|
||||
status = http.StatusNotFound
|
||||
}
|
||||
w.WriteHeader(status)
|
||||
s.render(w, "error", map[string]any{
|
||||
s.render(w, r, "error", map[string]any{
|
||||
"Title": "error",
|
||||
"Message": err.Error(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user