summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder (aider) <wohilas@gmail.com>2025-03-29 15:07:04 +0300
committerGrail Finder (aider) <wohilas@gmail.com>2025-03-29 15:07:04 +0300
commitc30ab382560ddbed5c90043090c78fbb56b5fffa (patch)
tree25f18e897b25558f29320d70ea78aa8c9b83cdf7
parent3f4d489bfc98695a29ff2f069b438c060e30b972 (diff)
feat: return HTML feedback for answers
-rw-r--r--components/index.html9
-rw-r--r--internal/handlers/main.go12
2 files changed, 14 insertions, 7 deletions
diff --git a/components/index.html b/components/index.html
index 5af9278..68f15ad 100644
--- a/components/index.html
+++ b/components/index.html
@@ -10,16 +10,17 @@
</head>
<body>
<div id="ancestor">
- <div>
+ <div class="question-text">
{{.Text}}
</div>
- <div>
+ <div id="feedback"></div>
+ <div id="options">
{{range $index, $option := .Options}}
<button
hx-post="/answer"
hx-vals='{"selected": "{{$index}}", "question_id": "{{$.ID}}"}'
- hx-target="#ancestor"
- hx-swap="outerHTML"
+ hx-target="#feedback"
+ hx-swap="innerHTML"
class="option-button"
>
{{$option}}
diff --git a/internal/handlers/main.go b/internal/handlers/main.go
index 86d0915..c167cae 100644
--- a/internal/handlers/main.go
+++ b/internal/handlers/main.go
@@ -49,9 +49,15 @@ func (h *Handlers) HandleAnswer(w http.ResponseWriter, r *http.Request) {
"selected", selectedIndex,
"question_id", questionID)
- // TODO: Add actual answer validation logic here
- // For now just return the same question
- h.MainPage(w, r)
+ var feedback string
+ if selectedIndex == "1" {
+ feedback = `<div class="feedback">Correct! 🎉</div>`
+ } else {
+ feedback = `<div class="feedback">Wrong answer, try again! ❌</div>`
+ }
+
+ w.Header().Set("Content-Type", "text/html")
+ w.Write([]byte(feedback))
}
func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) {