From 12f158b5a5dc92a88c1c284e6f74934769aa3d49 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Fri, 2 May 2025 14:09:19 +0300 Subject: [PATCH] Feat: show and hide form --- components/createroomform.html | 44 +++++++++++++++++----------------- components/index.html | 2 ++ handlers/elements.go | 13 +++++++++- main.go | 2 ++ 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/components/createroomform.html b/components/createroomform.html index 77d2200..872b077 100644 --- a/components/createroomform.html +++ b/components/createroomform.html @@ -1,24 +1,24 @@ {{define "createform"}} -
- Create a room
- or
- @CustomBtn(templ.Attributes{"hx-get": "/room/hideform", "hx-target": ".create-room-div"}, "Hide Form") -
-
-
-
-
-
-
-
- /*
*/ - @base.LangOption()
-
-
- @CustomBtn(templ.Attributes{"type": "submit"}, "Create Room") -
-
-
- Hello, you should login. -
+{{if .}} +
+ Create a room
+ or
+ +
+
+
+
+
+
+
+
+
+ +
+
+{{else}} +
+ +
+{{end}} {{end}} diff --git a/components/index.html b/components/index.html index 1361feb..b93bd0d 100644 --- a/components/index.html +++ b/components/index.html @@ -43,7 +43,9 @@
{{template "login"}} +
+

Word Color Cards

{{range $word, $color := .}} diff --git a/handlers/elements.go b/handlers/elements.go index 0ed89eb..e539df8 100644 --- a/handlers/elements.go +++ b/handlers/elements.go @@ -6,10 +6,21 @@ import ( ) func HandleShowCreateForm(w http.ResponseWriter, r *http.Request) { + show := true tmpl, err := template.ParseGlob("components/*.html") if err != nil { abortWithError(w, err.Error()) return } - tmpl.ExecuteTemplate(w, "createform", nil) + tmpl.ExecuteTemplate(w, "createform", show) +} + +func HandleHideCreateForm(w http.ResponseWriter, r *http.Request) { + show := false + tmpl, err := template.ParseGlob("components/*.html") + if err != nil { + abortWithError(w, err.Error()) + return + } + tmpl.ExecuteTemplate(w, "createform", show) } diff --git a/main.go b/main.go index 50e31eb..6fb3156 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,9 @@ func ListenToRequests(port string) error { 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) slog.Info("Listening", "addr", port) return server.ListenAndServe() }