diff options
Diffstat (limited to 'internal/handlers')
-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) } |