Feat: show colors by pressing words

This commit is contained in:
Grail Finder
2025-05-02 15:21:28 +03:00
parent 8b768f919b
commit 322743e33d
6 changed files with 48 additions and 33 deletions

View File

@ -1,6 +1,7 @@
package handlers
import (
"golias/models"
"html/template"
"net/http"
)
@ -24,3 +25,24 @@ func HandleHideCreateForm(w http.ResponseWriter, r *http.Request) {
}
tmpl.ExecuteTemplate(w, "createform", show)
}
func HandleShowColor(w http.ResponseWriter, r *http.Request) {
word := r.URL.Query().Get("word")
color, exists := roundWords[word]
log.Debug("got show-color request", "word", word, "color", color)
if !exists {
abortWithError(w, "word is not found")
return
}
tmpl, err := template.ParseGlob("components/*.html")
if err != nil {
abortWithError(w, err.Error())
return
}
cardword := models.WordCard{
Word: word,
Color: models.StrToWordColor(color),
Revealed: true,
}
tmpl.ExecuteTemplate(w, "cardword", cardword)
}

View File

@ -36,29 +36,6 @@ func HandlePing(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("pong"))
}
func HandleShowColor(w http.ResponseWriter, r *http.Request) {
word := r.URL.Query().Get("word")
color, exists := roundWords[word]
if !exists {
http.Error(w, "word not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(
fmt.Sprintf(`<div style="
background-color: %s;
padding: 1rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
min-width: 100px;
text-align: center;
color: white;
text-shadow: 0 2px 4px rgba(0,0,0,0.8);
cursor: pointer;
">%s</div>`, color, word)))
}
func HandleHome(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseGlob("components/*.html")
if err != nil {