spellcheck, and refreshing cake list

This commit is contained in:
bronku 2025-02-01 19:25:53 +01:00
parent 2c90e19eba
commit ea81abb718
9 changed files with 20 additions and 24 deletions

View file

@ -1,15 +1,13 @@
# iroon # iroon
## todo: ## todo:
- [x] extract order creation form into it's own element - [x] extract order creation form into it's own element
- [ ] organize html structure
- [x] option to add additional cakes - [x] option to add additional cakes
- [x] saving orders on server - [x] saving orders on server
- [ ] displaying orders - [ ] displaying orders
- [x] move id to cake struct - [x] move id to cake struct
- [ ] refresh the list on submission - [x] refresh the list on submission
- [ ] peristent storage - [ ] persistent storage
- [x] rudimentary css - [x] rudimentary css
- [ ] organize the cake editor
## ux design ## ux design
### adding an order: ### adding an order:
1. user selects the _add order_ button 1. user selects the _add order_ button

View file

@ -60,7 +60,7 @@ func (c *controller) newCake(w http.ResponseWriter, r *http.Request) {
} }
c.cakes[in.ID] = in c.cakes[in.ID] = in
_ = c.tmpl["cake"].Execute(w, in) _ = c.tmpl["new_cake"].Execute(w, in)
} }
func (c *controller) postNewOrder(w http.ResponseWriter, r *http.Request) { func (c *controller) postNewOrder(w http.ResponseWriter, r *http.Request) {

View file

@ -3,15 +3,14 @@ package main
import ( import (
"embed" "embed"
"fmt" "fmt"
"os"
"net/http" "net/http"
"os"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )
//go:embed public //go:embed public
var public embed.FS //var public embed.FS
//go:embed templates //go:embed templates
var templates embed.FS var templates embed.FS
@ -23,7 +22,7 @@ func main() {
c.LoadRouter(publicfs) c.LoadRouter(publicfs)
c.cakes = make(map[int]Cake) c.cakes = make(map[int]Cake)
c.cakes[0] = Cake{"Sernik", 120, 0} c.cakes[0] = Cake{"Sernik", 120, 0}
c.cakes[1] = Cake{"Malinowa chmórka", 120, 1} c.cakes[1] = Cake{"Malinowa chmurka", 120, 1}
c.cakes[2] = Cake{"Beza Pavlova", 8, 2} c.cakes[2] = Cake{"Beza Pavlova", 8, 2}
err := http.ListenAndServe(":8080", c) err := http.ListenAndServe(":8080", c)

View file

@ -27,5 +27,5 @@
<div id="basket"> <div id="basket">
<h3>Baset</h3> <h3>Baset</h3>
</div> </div>
<div hx-get="available_cakes" hx-swap="innerHTML" hx-trigger="load"></div> <div id="cake_selector" hx-get="available_cakes" hx-swap="innerHTML" hx-trigger="load"></div>
</form> </form>

View file

@ -1,8 +0,0 @@
<div id="cake_preview">
<ul>
<li>ID: {{.ID}}</li>
<li>Name: {{.Name}}</li>
<li>Price: {{.Price}}</li>
</ul>
<button type="button" onClick="document.getElementById('cake_preview').remove()">close</button>
</div>

View file

@ -1,3 +1,4 @@
<h3>Edit cakes</h3>
<form hx-post="new_cake" hx-swap="outerHTML"> <form hx-post="new_cake" hx-swap="outerHTML">
<div> <div>
<label for="name">Name</label> <label for="name">Name</label>
@ -9,5 +10,5 @@
</div> </div>
<input value="{{.ID}}" name="id" hidden></input> <input value="{{.ID}}" name="id" hidden></input>
<button type="submit">Submit</button> <button type="submit">Submit</button>
<button type="button" onclick="document.getElementById('cake_editor').innerText=''">Cancel</button> <button hx-get="edit_cakes" hx-swap="innerHTML" hx-target="closest div">back</button>
</form> </form>

View file

@ -1,10 +1,9 @@
<h3>Edit cakes</h3> <h3>Edit cakes</h3>
<button hx-get="available_cakes" hx-swap="innerHTML" hx-target="closest div">back</button> <button hx-get="available_cakes" hx-swap="innerHTML" hx-target="closest div">back</button>
<button hx-get="cake_editor" hx-swap="innerHTML" hx-target="#cake_editor">New</button> <button hx-get="cake_editor" hx-swap="innerHTML" hx-target="closest #cake_selector">New</button>
<div id="cakes"> <div id="cakes">
{{range $key, $value := .}} {{range $key, $value := .}}
<button hx-get="cake_editor/{{$value.ID}}" hx-swap="innerHTML" hx-target="#cake_editor">{{$value.Name}} <button hx-get="cake_editor/{{$value.ID}}" hx-swap="innerHTML" hx-target="closest #cake_selector">{{$value.Name}}
{{$value.Price}}</button> {{$value.Price}}</button>
{{end}} {{end}}
</div> </div>
<div id="cake_editor"></div>

7
templates/new_cake.html Normal file
View file

@ -0,0 +1,7 @@
<h3>Added cake</h3>
<ul>
<li>ID: {{.ID}}</li>
<li>Name: {{.Name}}</li>
<li>Price: {{.Price}}</li>
</ul>
<button hx-get="edit_cakes" hx-swap="innerHTML" hx-target="closest div">back</button>

View file

@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
func unwrap[T any](output T, err error) T { func _[T any](output T, err error) T {
if err != nil { if err != nil {
panic(err) panic(err)
} }