diff options
author | Grail Finder <wohilas@gmail.com> | 2025-04-05 17:56:01 +0300 |
---|---|---|
committer | Grail Finder (aider) <wohilas@gmail.com> | 2025-04-05 17:56:01 +0300 |
commit | 96441a431eaca60b1b798e997608812c8be76598 (patch) | |
tree | e21349c8301074964a84ff0f11d2bcdaa83c9e31 | |
parent | c2d82a17832590d86c7c243671b64df95913350e (diff) |
feat: update question template and simplify handler logic
-rw-r--r-- | components/index.html | 7 | ||||
-rw-r--r-- | internal/handlers/main.go | 12 |
2 files changed, 10 insertions, 9 deletions
diff --git a/components/index.html b/components/index.html index 3efca24..d3811b1 100644 --- a/components/index.html +++ b/components/index.html @@ -10,12 +10,17 @@ </head> <body> <div id="ancestor"> + {{if .Requirement}} + <p>{{.Requirement}}</p> + {{end}} <div class="question-text" data-testid="question"> {{.Text}} </div> <div id="feedback" data-testid="feedback"> - {{if .Correct}}{{template "feedback" .}}{{else if .Requirement}}{{template "feedback" .}}{{end}} {{if ne .Status 0}} + <div> + {{.Explanation}} + </div> <button hx-get="/next-question?current_id={{.ID}}" hx-target="#ancestor" diff --git a/internal/handlers/main.go b/internal/handlers/main.go index 97a54cd..4717f3c 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -13,9 +13,9 @@ import ( // Handlers structure type Handlers struct { - cfg config.Config - log *slog.Logger - repo repos.FullRepo + cfg config.Config + log *slog.Logger + repo repos.FullRepo } // NewHandlers constructor @@ -134,10 +134,7 @@ func (h *Handlers) renderQuestion(w http.ResponseWriter, question *models.Questi *models.Question } - err = tmpl.ExecuteTemplate(w, "main", &TemplateData{ - Question: question, - ShowNext: h.showNext, - }) + err = tmpl.ExecuteTemplate(w, "main", question) if err != nil { h.log.Error("failed to render template", "error", err) } @@ -157,6 +154,5 @@ func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) { abortWithError(w, "Question not found") return } - h.renderQuestion(w, question) } |