summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrailFinder <wohilas@gmail.com>2024-04-02 12:29:25 +0300
committerGrailFinder <wohilas@gmail.com>2024-04-02 12:29:25 +0300
commit925b7b7a6a6de1f40262d0fc96be7920b26b0021 (patch)
tree100895b2c086d5764565d44de2e18453b2a85ad2
parent878b071112d7484fd9b22d70ee06afe895de9018 (diff)
Feat: add htmx to show|hide form
-rw-r--r--components/add_action_form.html7
-rw-r--r--components/index.html3
-rw-r--r--internal/handlers/elements.go22
-rw-r--r--internal/models/models.go1
-rw-r--r--internal/server/router.go4
5 files changed, 36 insertions, 1 deletions
diff --git a/components/add_action_form.html b/components/add_action_form.html
index 70403dc..95c869f 100644
--- a/components/add_action_form.html
+++ b/components/add_action_form.html
@@ -1,5 +1,6 @@
{{define "actionform"}}
<div id="actionform">
+ <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="/hideform" hx-target="#actionform">HIDE FORM</button>
<h1>Add action</h1>
<form method="POST">
<label>Name:</label><br />
@@ -16,3 +17,9 @@
</form>
</div>
{{end}}
+
+{{define "showformbtn"}}
+<div id="actionform">
+ <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="/showform" hx-target="#actionform">SHOW FORM</button>
+</div>
+{{end}}
diff --git a/components/index.html b/components/index.html
index 6848f1a..b3da4ea 100644
--- a/components/index.html
+++ b/components/index.html
@@ -6,6 +6,7 @@
<meta charset="utf-8" name="viewport" content="width=device-width,initial-scale=1"/>
<link rel="stylesheet" type="text/css" href="/assets/style.css" />
<link rel="icon" sizes="64x64" href="/assets/favicon/wolfhead_negated.ico" />
+ <script src="https://unpkg.com/htmx.org@1.9.11" integrity="sha384-0gxUXCCR8yv9FM2b+U3FDbsKthCI66oH5IA9fHppQq9DDMHuMauqq1ZHBpJxQ0J0" crossorigin="anonymous"></script>
</head>
<body>
<div id="ancestor">
@@ -14,7 +15,7 @@
{{ template "UserScore" . }}
</div>
<div>
- {{ template "actionform" }}
+ {{ template "showformbtn" }}
</div>
</div>
</body>
diff --git a/internal/handlers/elements.go b/internal/handlers/elements.go
new file mode 100644
index 0000000..c0da7f0
--- /dev/null
+++ b/internal/handlers/elements.go
@@ -0,0 +1,22 @@
+package handlers
+
+import (
+ "html/template"
+ "net/http"
+)
+
+func (h *Handlers) ServeShowForm(w http.ResponseWriter, r *http.Request) {
+ tmpl, err := template.ParseGlob("components/*.html")
+ if err != nil {
+ panic(err)
+ }
+ tmpl.ExecuteTemplate(w, "actionform", nil)
+}
+
+func (h *Handlers) ServeHideForm(w http.ResponseWriter, r *http.Request) {
+ tmpl, err := template.ParseGlob("components/*.html")
+ if err != nil {
+ panic(err)
+ }
+ tmpl.ExecuteTemplate(w, "showformbtn", nil)
+}
diff --git a/internal/models/models.go b/internal/models/models.go
index 42990a3..5d6dfa6 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -21,5 +21,6 @@ type (
Magnitude uint8
Repeatable bool
Type ActionType
+ Done bool
}
)
diff --git a/internal/server/router.go b/internal/server/router.go
index 9b03371..726f8b8 100644
--- a/internal/server/router.go
+++ b/internal/server/router.go
@@ -23,6 +23,10 @@ func (srv *server) ListenToRequests() {
mux.HandleFunc("GET /", h.MainPage)
mux.HandleFunc("POST /", h.HandleForm)
+ // ====== elements ======
+ mux.HandleFunc("GET /showform", h.ServeShowForm)
+ mux.HandleFunc("GET /hideform", h.ServeHideForm)
+
fmt.Printf("Listening on %v\n", server.Addr)
server.ListenAndServe()
}