From c2d82a17832590d86c7c243671b64df95913350e Mon Sep 17 00:00:00 2001 From: "Grail Finder (aider)" Date: Sat, 5 Apr 2025 17:36:57 +0300 Subject: refactor: track question status using Status field instead of showNext flag --- internal/handlers/main.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'internal/handlers') 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 = `
Correct! 🎉
` } else { + question.Status = 2 feedback = `
Wrong answer! The correct answer was: ` + getCorrectOption(question) + `
` } @@ -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) } -- cgit v1.2.3