Feat: show and hide form
This commit is contained in:
		| @@ -1,24 +1,24 @@ | ||||
| {{define "createform"}} | ||||
|  <div class="create-room-div"> | ||||
| {{if .}} | ||||
|  <div id="create-room" class="create-room-div"> | ||||
|     Create a room <br/> | ||||
|     or<br/> | ||||
|             @CustomBtn(templ.Attributes{"hx-get": "/room/hideform", "hx-target": ".create-room-div"}, "Hide Form") | ||||
|     <button button class="justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" hx-get="/room/hideform" hx-target=".create-room-div" >Hide Form</button> | ||||
|     <form hx-post="/room/create" hx-target="#ancestor"> | ||||
| 	<label For="room_name">Room Name</label><br/> | ||||
| 	<input type="text" id="room_name" name="room_name" class="text-center text-black" value={utils.MakeDefaultRoomName(utils.GetUsername(c))}/><br/> | ||||
| 	<label For="game_time">Game Time:</label><br/> | ||||
| 	<input type="number" id="game_time" name="game_time" class="text-center text-black" value="300"/><br/> | ||||
|                 <label For="minority_number">Minority Number:</label><br/> | ||||
|                 <input type="number" id="minority_number" name="minority_number" class="text-center text-black" value="1"/><br/> | ||||
| 	<label For="language">Language:</label><br/> | ||||
|                 /* <input type="text" id="language" name="language" class="text-center text-black" value="en"/><br/> */ | ||||
|                 @base.LangOption()<br/> | ||||
| 	<input type="text" id="language" name="language" class="text-center text-black" value="en"/><br/> | ||||
| 	<label For="password">Password:</label><br/> | ||||
| 	<input type="text" id="password" name="room_pass" class="text-center text-black" value="" placeholder="Leave empty for open room"/><br/> | ||||
|                 @CustomBtn(templ.Attributes{"type": "submit"}, "Create Room") | ||||
|     <button button class="justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" type="submit" >Create Room</button> | ||||
|     </form> | ||||
| </div> | ||||
|         <div class="create-room-div"> | ||||
|             Hello, you should login. | ||||
| {{else}} | ||||
| <div id="create-room" class="create-room-div"> | ||||
|     <button button id="create-form-btn" type="submit" class="justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" hx-get="/room/createform" hx-swap="outerHTML">SHOW ROOM CREATE FORM</button> | ||||
| </div> | ||||
| {{end}} | ||||
| {{end}} | ||||
|   | ||||
| @@ -43,7 +43,9 @@ | ||||
| <body> | ||||
| <div id=ancestor> | ||||
| 	{{template "login"}} | ||||
| 	<div id="create-room" class="create-room-div"> | ||||
| 	    <button button id="create-form-btn" type="submit" class="justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" hx-get="/room/createform" hx-swap="outerHTML">SHOW ROOM CREATE FORM</button> | ||||
| 	</div> | ||||
| 	<h1>Word Color Cards</h1> | ||||
| 	<div style="display: flex; gap: 1rem; flex-wrap: wrap; padding: 1rem;"> | ||||
| 		{{range $word, $color := .}} | ||||
|   | ||||
| @@ -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) | ||||
| } | ||||
|   | ||||
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder