From 985956b3842d49eb0f7429aa844c383ddec6006f Mon Sep 17 00:00:00 2001 From: "Grail Finder (aider)" Date: Fri, 2 May 2025 14:18:19 +0300 Subject: [PATCH] feat: add click-to-reveal color cards with HTMX --- components/index.html | 5 +++-- handlers/handlers.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/components/index.html b/components/index.html index b93bd0d..e22a826 100644 --- a/components/index.html +++ b/components/index.html @@ -50,7 +50,7 @@
{{range $word, $color := .}}
+ cursor: pointer; + " hx-get="/show-color?word={{$word}}" hx-trigger="click" hx-swap="outerHTML"> {{$word}}
{{end}} diff --git a/handlers/handlers.go b/handlers/handlers.go index b6053d7..609984f 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -36,6 +36,29 @@ func HandlePing(w http.ResponseWriter, r *http.Request) { w.Write([]byte("pong")) } +func HandleShowColor(w http.ResponseWriter, r *http.Request) { + word := r.URL.Query().Get("word") + color, exists := roundWords[word] + if !exists { + http.Error(w, "word not found", http.StatusNotFound) + return + } + + w.Header().Set("Content-Type", "text/html") + w.Write([]byte( + fmt.Sprintf(`
%s
`, color, word))) +} + func HandleHome(w http.ResponseWriter, r *http.Request) { tmpl, err := template.ParseGlob("components/*.html") if err != nil {