Feat: show colors by pressing words
This commit is contained in:
13
components/cardword.html
Normal file
13
components/cardword.html
Normal file
@ -0,0 +1,13 @@
|
||||
{{define "cardword"}}
|
||||
<div id="card-%s" style="
|
||||
background-color: {{.Color}};
|
||||
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;"> {{.Word}}
|
||||
</div>
|
||||
{{end}}
|
@ -49,7 +49,7 @@
|
||||
<h1>Word Color Cards</h1>
|
||||
<div style="display: flex; gap: 1rem; flex-wrap: wrap; padding: 1rem;">
|
||||
{{range $word, $color := .}}
|
||||
<div style="
|
||||
<div id="card-{{$word}}" class="slide-it" style="
|
||||
background-color: beige;
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
@ -58,8 +58,8 @@
|
||||
text-align: center;
|
||||
color: white;
|
||||
text-shadow: 0 2px 4px rgba(0,0,0,0.8);
|
||||
cursor: pointer;
|
||||
" hx-get="/show-color?word={{$word}}" hx-trigger="click" hx-swap="outerHTML">
|
||||
cursor: pointer;"
|
||||
hx-get="/word/show-color?word={{$word}}" hx-trigger="click" hx-swap="outerHTML transition:true swap:.2s">
|
||||
{{$word}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
4
main.go
4
main.go
@ -16,16 +16,16 @@ func ListenToRequests(port string) error {
|
||||
ReadTimeout: time.Second * 5,
|
||||
WriteTimeout: time.Second * 5,
|
||||
}
|
||||
|
||||
fs := http.FileServer(http.Dir("assets/"))
|
||||
mux.Handle("GET /assets/", http.StripPrefix("/assets/", fs))
|
||||
|
||||
//
|
||||
mux.HandleFunc("GET /ping", handlers.HandlePing)
|
||||
mux.HandleFunc("GET /", handlers.HandleHome)
|
||||
mux.HandleFunc("POST /login", handlers.HandleFrontLogin)
|
||||
//elements
|
||||
mux.HandleFunc("GET /room/createform", handlers.HandleShowCreateForm)
|
||||
mux.HandleFunc("GET /room/hideform", handlers.HandleHideCreateForm)
|
||||
mux.HandleFunc("GET /word/show-color", handlers.HandleShowColor)
|
||||
slog.Info("Listening", "addr", port)
|
||||
return server.ListenAndServe()
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ const (
|
||||
WordColorBlue = "blue"
|
||||
WordColorRed = "red"
|
||||
WordColorBlack = "black"
|
||||
WordColorUknown = "beige"
|
||||
)
|
||||
|
||||
func StrToWordColor(s string) WordColor {
|
||||
@ -22,7 +23,7 @@ func StrToWordColor(s string) WordColor {
|
||||
case "black":
|
||||
return WordColorBlack
|
||||
default:
|
||||
return "beige"
|
||||
return WordColorUknown
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +35,7 @@ type Room struct {
|
||||
RoomLink string
|
||||
CreatorName string `json:"creator_name"`
|
||||
PlayerList []string `json:"player_list"`
|
||||
TeamTurn string
|
||||
RedMime string
|
||||
BlueMime string
|
||||
RedGuessers []string
|
||||
@ -56,6 +58,7 @@ type RoomPublic struct {
|
||||
CreatorName string `json:"creator_name"`
|
||||
GameSettings *GameSettings `json:"settings"`
|
||||
RedMime string
|
||||
TeamTurn string
|
||||
BlueMime string
|
||||
RedGuessers []string
|
||||
BlueGuessers []string
|
||||
|
Reference in New Issue
Block a user