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