summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorGrail Finder (aider) <wohilas@gmail.com>2025-04-05 16:52:02 +0300
committerGrail Finder (aider) <wohilas@gmail.com>2025-04-05 16:52:02 +0300
commitb5f3dd055ecc25120df65f6655808d8a8897f1a3 (patch)
tree797efcf2bd68d93272f287ee77ad04bba11b1a64 /components
parent3374cb0fb2ce024eb5da78dc63c7313db8ec4c95 (diff)
feat: extract feedback into template partial and add Correct field
Diffstat (limited to 'components')
-rw-r--r--components/feedback.html33
-rw-r--r--components/index.html10
2 files changed, 36 insertions, 7 deletions
diff --git a/components/feedback.html b/components/feedback.html
new file mode 100644
index 0000000..0eda969
--- /dev/null
+++ b/components/feedback.html
@@ -0,0 +1,33 @@
+{{define "feedback"}}
+{{if .Correct}}
+<div class="correct-feedback">
+ <div class="correct-answer">Correct!</div>
+ <div class="explanation">{{.Explanation}}</div>
+ {{if .ShowNext}}
+ <button
+ hx-get="/next-question?current_id={{.ID}}"
+ hx-target="#ancestor"
+ hx-swap="outerHTML"
+ class="next-button"
+ data-testid="next-button">
+ Next Question →
+ </button>
+ {{end}}
+</div>
+{{else}}
+<div class="error-feedback">
+ <div class="wrong-answer">Try Again</div>
+ <div class="explanation">{{.Explanation}}</div>
+ {{if .ShowNext}}
+ <button
+ hx-get="/next-question?current_id={{.ID}}"
+ hx-target="#ancestor"
+ hx-swap="outerHTML"
+ class="next-button"
+ data-testid="next-button">
+ Next Question →
+ </button>
+ {{end}}
+</div>
+{{end}}
+{{end}}
diff --git a/components/index.html b/components/index.html
index f0f18f0..9c43a50 100644
--- a/components/index.html
+++ b/components/index.html
@@ -13,13 +13,8 @@
<div class="question-text" data-testid="question">
{{.Text}}
</div>
- <div id="feedback" data-testid="feedback" class="{{if .Correct}}correct-feedback{{else}}error-feedback{{end}}">
- {{if .Correct}}
- <div class="correct-answer">Correct!</div>
- {{else}}
- <div class="wrong-answer">Try Again</div>
- {{end}}
- <div class="explanation">{{.Explanation}}</div>
+ <div id="feedback" data-testid="feedback">
+ {{template "feedback" .}}
{{if .ShowNext}}
<button
hx-get="/next-question?current_id={{.ID}}"
@@ -31,6 +26,7 @@
</button>
{{end}}
</div>
+ {{template "feedback" .}}
<div id="options">
<button
data-testid="option1"