Compare commits

..

6 Commits

6 changed files with 64 additions and 10 deletions

13
components/cardword.html Normal file
View 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}}

View File

@ -49,8 +49,8 @@
<h1>Word Color Cards</h1>
<div style="display: flex; gap: 1rem; flex-wrap: wrap; padding: 1rem;">
{{range $word, $color := .}}
<div style="
background-color: {{$color}};
<div id="card-{{$word}}" class="slide-it" style="
background-color: beige;
padding: 1rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
@ -58,7 +58,8 @@
text-align: center;
color: white;
text-shadow: 0 2px 4px rgba(0,0,0,0.8);
">
cursor: pointer;"
hx-get="/word/show-color?word={{$word}}" hx-trigger="click" hx-swap="outerHTML transition:true swap:.2s">
{{$word}}
</div>
{{end}}

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

@ -31,7 +31,7 @@ func LogRequests(next http.Handler) http.Handler {
duration := time.Since(start)
log.Debug("request completed",
"method", r.Method,
"path", r.URL.Path,
"path", r.URL.RequestURI(),
"status", ww.status,
"duration", duration.String(),
)

View File

@ -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()
}

View File

@ -9,8 +9,24 @@ const (
WordColorBlue = "blue"
WordColorRed = "red"
WordColorBlack = "black"
WordColorUknown = "beige"
)
func StrToWordColor(s string) WordColor {
switch s {
case "white":
return WordColorWhite
case "blue":
return WordColorBlue
case "red":
return WordColorRed
case "black":
return WordColorBlack
default:
return WordColorUknown
}
}
type Room struct {
ID string `json:"id" db:"id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
@ -19,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
@ -41,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