frontend: fix bugs according to monsterTable
This commit is contained in:
parent
b82e138c4d
commit
309ade3e72
4 changed files with 13 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"ddServer/model"
|
||||
"embed"
|
||||
"html/template"
|
||||
"log"
|
||||
|
|
@ -8,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
// MainHandler
|
||||
func MainHandler(content embed.FS) http.HandlerFunc {
|
||||
func MainHandler(content embed.FS, monsters *[]model.Monster) http.HandlerFunc {
|
||||
log.Print("MainHandler called")
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl, err := template.ParseFS(content, "templates/main.html", "templates/monsterForm.html", "templates/monster.html", "templates/monsterTable.html")
|
||||
|
|
@ -17,8 +18,12 @@ func MainHandler(content embed.FS) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
err = tmpl.ExecuteTemplate(w, "main", map[string]interface{}{
|
||||
"Title": "Dungeons & Dragons Monster Generator",
|
||||
"Monsters": *monsters,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Template execution error: %v\n", err)
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -28,7 +28,7 @@ func main() {
|
|||
http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename))
|
||||
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.FS(content))))
|
||||
http.HandleFunc("/addMonster", handlers.AddMonster(&Monsters))
|
||||
http.HandleFunc("/main", handlers.MainHandler(content))
|
||||
http.HandleFunc("/main", handlers.MainHandler(content, &Monsters))
|
||||
http.HandleFunc("/about", handlers.AboutHandler(content))
|
||||
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
||||
http.HandleFunc("/monsterTable", handlers.MonsterTableHandler(content, &Monsters))
|
||||
|
|
|
|||
|
|
@ -11,15 +11,15 @@
|
|||
|
||||
<div id="navbarBasicExample" class="navbar-menu">
|
||||
<div class="navbar-start">
|
||||
<a href="/" class="navbar-item" hx-get="/main" hx-target="#main-content">
|
||||
<a href="/" class="navbar-item" hx-get="/main" hx-target="#main-content" hx-boost="true">
|
||||
Dungeons & Dragons
|
||||
</a>
|
||||
|
||||
<a href="/about" class="navbar-item" hx-get="/about" hx-target="#main-content">
|
||||
<a href="/about" class="navbar-item" hx-get="/about" hx-target="#main-content" hx-boost="true">
|
||||
About
|
||||
</a>
|
||||
|
||||
<a href="/contact" class="navbar-item" hx-get="/contact" hx-target="#main-content">
|
||||
<a href="/contact" class="navbar-item" hx-get="/contact" hx-target="#main-content" hx-boost="true">
|
||||
Contact
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<p class="title is-4">Monster Form</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form action="/submit" method="post" class="">
|
||||
<form hx-boost="true" action="/submit" method="post" class="">
|
||||
<div class="field">
|
||||
<td><label for="filename">Filename:</label></td>
|
||||
<div class="control"><input type="text" name="filename" required placeholder="Dateiname"
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
<div class="field">
|
||||
<div class="control">
|
||||
<button type="button" hx-post="/addMonster" hx-trigger="click" hx-target="#monster-table"
|
||||
hx-swap="outerHTML" class="button is-info">Add
|
||||
hx-swap="outerHTML" class="button is-info" hx-boost="true">Add
|
||||
Monster</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue