From 5cf1f1199eaef5133b4b06a0392da5ec6aceaee8 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sat, 3 May 2025 09:18:05 +0300 Subject: [PATCH] Feat: components chain --- components/cardtable.html | 10 ++++++++++ components/cardword.html | 32 ++++++++++++++++++++++++-------- components/index.html | 38 ++++++++++++++++++++------------------ components/room.html | 23 +---------------------- handlers/handlers.go | 13 +++++++++++-- models/main.go | 1 + models/state.go | 6 ++++++ 7 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 components/cardtable.html diff --git a/components/cardtable.html b/components/cardtable.html new file mode 100644 index 0000000..6609337 --- /dev/null +++ b/components/cardtable.html @@ -0,0 +1,10 @@ +{{define "cardtable"}} + +
+
+ {{range .Room.Cards}} + {{template "cardword" .}} + {{end}} +
+
+{{end}} diff --git a/components/cardword.html b/components/cardword.html index 2f23e3e..7d8e91a 100644 --- a/components/cardword.html +++ b/components/cardword.html @@ -1,13 +1,29 @@ {{define "cardword"}} -
{{.Word}}
+{{else}} +
+ {{.Word}} +
+{{end}} {{end}} diff --git a/components/index.html b/components/index.html index 5b2eb57..fe83049 100644 --- a/components/index.html +++ b/components/index.html @@ -46,24 +46,26 @@
-

Word Color Cards

-
- {{range $word, $color := .}} -
- {{$word}} -
- {{end}} -
+ + {{template "room" .}} + + + + + + + + + + + + + + + + + + diff --git a/components/room.html b/components/room.html index 19d4092..90c3faf 100644 --- a/components/room.html +++ b/components/room.html @@ -18,28 +18,7 @@ - - -
-
- {{range .Room.Cards}} -
- {{if .Revealed}} - {{.Word}} - {{else}} - - {{end}} -
- {{end}} -
-
- + {{template "cardtable" .}}

Join Red Team

diff --git a/handlers/handlers.go b/handlers/handlers.go index b1ea3f1..71cbf5d 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -2,6 +2,7 @@ package handlers import ( "golias/config" + "golias/models" "golias/pkg/cache" "html/template" "log/slog" @@ -43,6 +44,14 @@ func HandleHome(w http.ResponseWriter, r *http.Request) { return } // check if user in a room - roomID := getRoomIDFromCtx(r.Context()) - tmpl.ExecuteTemplate(w, "main", roundWords) + // roomID := getRoomIDFromCtx(r.Context()) + // roomID = "test-id" + // if roomID != "" { + // // get room data + // userState := models.MakeTestState() + // tmpl.ExecuteTemplate(w, "room", userState) + // return + // } + userState := models.MakeTestState() + tmpl.ExecuteTemplate(w, "main", userState) } diff --git a/models/main.go b/models/main.go index d169b48..59e1510 100644 --- a/models/main.go +++ b/models/main.go @@ -62,6 +62,7 @@ type RoomPublic struct { BlueMime string RedGuessers []string BlueGuessers []string + Cards []WordCard } func (r Room) ToPublic() RoomPublic { diff --git a/models/state.go b/models/state.go index d0408f2..f0b93bc 100644 --- a/models/state.go +++ b/models/state.go @@ -50,15 +50,21 @@ type UserState struct { func MakeTestState() *UserState { cards := []WordCard{ {Word: "hamster", Color: "blue"}, + {Word: "child", Color: "red"}, + {Word: "wheel", Color: "white"}, + {Word: "condition", Color: "black"}, + {Word: "test", Color: "white"}, } room := RoomPublic{ ID: "test-id", CreatedAt: time.Now(), CreatorName: "test-name", + Cards: cards, } return &UserState{ Username: "test-name", Team: UserTeamNone, Role: UserRoleNone, + Room: room, } }