Compare commits
6 Commits
12f158b5a5
...
322743e33d
Author | SHA1 | Date | |
---|---|---|---|
322743e33d | |||
8b768f919b | |||
722da6d4fa | |||
990d8660b3 | |||
ad8982a112 | |||
985956b384 |
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,8 +49,8 @@
|
|||||||
<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: {{$color}};
|
background-color: beige;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
||||||
@ -58,7 +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;"
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
@ -31,7 +31,7 @@ func LogRequests(next http.Handler) http.Handler {
|
|||||||
duration := time.Since(start)
|
duration := time.Since(start)
|
||||||
log.Debug("request completed",
|
log.Debug("request completed",
|
||||||
"method", r.Method,
|
"method", r.Method,
|
||||||
"path", r.URL.Path,
|
"path", r.URL.RequestURI(),
|
||||||
"status", ww.status,
|
"status", ww.status,
|
||||||
"duration", duration.String(),
|
"duration", duration.String(),
|
||||||
)
|
)
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,28 @@ import "time"
|
|||||||
type WordColor string
|
type WordColor string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WordColorWhite = "white"
|
WordColorWhite = "white"
|
||||||
WordColorBlue = "blue"
|
WordColorBlue = "blue"
|
||||||
WordColorRed = "red"
|
WordColorRed = "red"
|
||||||
WordColorBlack = "black"
|
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 {
|
type Room struct {
|
||||||
ID string `json:"id" db:"id"`
|
ID string `json:"id" db:"id"`
|
||||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||||
@ -19,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
|
||||||
@ -41,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