Use HTMX fragements on the fitness dashboard

This commit is contained in:
2026-10-02 17:42:29 +02:00
parent aa90a04f91
commit 7749d7c237
5 changed files with 139 additions and 24 deletions
+16
View File
@@ -64,6 +64,14 @@ type pageTypeHandler interface {
redirect(root, fsPath, urlPath string, r *http.Request) (target string, ok bool)
}
// fragmentHandler is optionally implemented by a pageTypeHandler whose page
// updates part of itself over htmx (e.g. one chart of a dashboard). It
// answers only htmx GETs outside the editor and returns false when the
// request is not for one of its fragments, so the full page renders.
type fragmentHandler interface {
serveFragment(w http.ResponseWriter, r *http.Request, root, fsPath, urlPath string) bool
}
// pageTypeHandlers is the registry. Each type registers itself via init().
var pageTypeHandlers []pageTypeHandler
@@ -306,6 +314,14 @@ func (h *handler) serveDir(w http.ResponseWriter, r *http.Request, urlPath, fsPa
return
}
if isHX(r) && !editMode {
for _, ph := range pageTypeHandlers {
if fh, ok := ph.(fragmentHandler); ok && fh.serveFragment(w, r, h.root, fsPath, urlPath) {
return
}
}
}
for _, ph := range pageTypeHandlers {
if target, ok := ph.redirect(h.root, fsPath, urlPath, r); ok {
http.Redirect(w, r, target, http.StatusFound)