diff options
author | Grail Finder (aider) <wohilas@gmail.com> | 2025-04-05 17:36:57 +0300 |
---|---|---|
committer | Grail Finder (aider) <wohilas@gmail.com> | 2025-04-05 17:36:57 +0300 |
commit | c2d82a17832590d86c7c243671b64df95913350e (patch) | |
tree | abaf1e843a4bb62aff01a69f34f84138e27f2806 /internal/handlers/main.go | |
parent | ab6249bd1b9f16bdfdd75c7ea450f1cfd7ee8acd (diff) |
refactor: track question status using Status field instead of showNext flag
Diffstat (limited to 'internal/handlers/main.go')
-rw-r--r-- | internal/handlers/main.go | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/internal/handlers/main.go b/internal/handlers/main.go index 4a64380..97a54cd 100644 --- a/internal/handlers/main.go +++ b/internal/handlers/main.go @@ -16,7 +16,6 @@ type Handlers struct { cfg config.Config log *slog.Logger repo repos.FullRepo - showNext bool // Tracks when to show next button } // NewHandlers constructor @@ -80,11 +79,12 @@ func (h *Handlers) HandleAnswer(w http.ResponseWriter, r *http.Request) { return } selectedIdx++ // in db index starts from 1 - h.showNext = true feedback := "" if selectedIdx == int(question.CorrectIndex) { + question.Status = 1 feedback = `<div data-testid="feedback" class="feedback">Correct! 🎉</div>` } else { + question.Status = 2 feedback = `<div data-testid="feedback" class="feedback">Wrong answer! The correct answer was: ` + getCorrectOption(question) + `</div>` } @@ -119,7 +119,6 @@ func (h *Handlers) HandleNextQuestion(w http.ResponseWriter, r *http.Request) { return } - h.showNext = false // Reset flag for new question h.renderQuestion(w, question) } @@ -133,8 +132,6 @@ func (h *Handlers) renderQuestion(w http.ResponseWriter, question *models.Questi // Add ShowNext flag to template data type TemplateData struct { *models.Question - ShowNext bool - Correct bool } err = tmpl.ExecuteTemplate(w, "main", &TemplateData{ @@ -161,6 +158,5 @@ func (h *Handlers) MainPage(w http.ResponseWriter, r *http.Request) { return } - h.showNext = false h.renderQuestion(w, question) } |