fix example todo
This commit is contained in:
parent
6ec3dfa790
commit
a2b286e9aa
6 changed files with 40 additions and 23 deletions
|
|
@ -2,11 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/maddalax/htmgo/framework/h"
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
"github.com/maddalax/htmgo/framework/service"
|
"github.com/maddalax/htmgo/framework/service"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
"todolist/__htmgo"
|
"todolist/__htmgo"
|
||||||
"todolist/ent"
|
"todolist/ent"
|
||||||
"todolist/infrastructure/db"
|
"todolist/infrastructure/db"
|
||||||
|
|
@ -22,18 +22,22 @@ func main() {
|
||||||
return db.Provide()
|
return db.Provide()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
h.Start(h.AppOpts{
|
||||||
|
ServiceLocator: locator,
|
||||||
|
LiveReload: true,
|
||||||
|
Register: func(app *h.App) {
|
||||||
|
|
||||||
sub, err := fs.Sub(StaticAssets, "assets/dist")
|
sub, err := fs.Sub(StaticAssets, "assets/dist")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Start(h.AppOpts{
|
http.FileServerFS(sub)
|
||||||
ServiceLocator: locator,
|
|
||||||
LiveReload: true,
|
app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub)))
|
||||||
Register: func(e *echo.Echo) {
|
|
||||||
e.StaticFS("/public", sub)
|
__htmgo.Register(app.Router)
|
||||||
__htmgo.Register(e)
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ func RootPage(children ...h.Ren) h.Ren {
|
||||||
return h.Html(
|
return h.Html(
|
||||||
h.HxExtension(h.BaseExtensions()),
|
h.HxExtension(h.BaseExtensions()),
|
||||||
h.Head(
|
h.Head(
|
||||||
|
h.Meta("viewport", "width=device-width, initial-scale=1"),
|
||||||
|
h.Meta("title", "htmgo todo mvc"),
|
||||||
|
h.Meta("description", "an example of how to build a todo mvc app with htmgo"),
|
||||||
|
h.Meta("charset", "utf-8"),
|
||||||
h.Link("/public/main.css", "stylesheet"),
|
h.Link("/public/main.css", "stylesheet"),
|
||||||
h.Script("/public/htmgo.js"),
|
h.Script("/public/htmgo.js"),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,9 @@ func CompleteAllIcon(list []*ent.Task) *h.Element {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return h.Div(
|
return h.Div(
|
||||||
h.ClassX("absolute top-0 left-0 p-4 rotate-90 text-2xl cursor-pointer", map[string]bool{
|
h.ClassX("absolute top-1 left-5 p-2 rotate-90 text-3xl cursor-pointer", map[string]bool{
|
||||||
"text-slate-400": notCompletedCount > 0,
|
"text-slate-400": notCompletedCount > 0,
|
||||||
}), h.Text("❯"),
|
}), h.Text("›"),
|
||||||
h.PostPartialWithQs(CompleteAll, h.NewQs("complete", h.Ternary(notCompletedCount > 0, "true", "false"))),
|
h.PostPartialWithQs(CompleteAll, h.NewQs("complete", h.Ternary(notCompletedCount > 0, "true", "false"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ type RequestContext struct {
|
||||||
kv map[string]interface{}
|
kv map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *RequestContext) QueryParam(key string) string {
|
||||||
|
return c.Request.URL.Query().Get(key)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *RequestContext) Set(key string, value interface{}) {
|
func (c *RequestContext) Set(key string, value interface{}) {
|
||||||
if c.kv == nil {
|
if c.kv == nil {
|
||||||
c.kv = make(map[string]interface{})
|
c.kv = make(map[string]interface{})
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func (q *Qs) ToString() string {
|
||||||
|
|
||||||
func GetQueryParam(ctx *RequestContext, key string) string {
|
func GetQueryParam(ctx *RequestContext, key string) string {
|
||||||
value, ok := ctx.URL.Query()[key]
|
value, ok := ctx.URL.Query()[key]
|
||||||
if !ok {
|
if value == nil || !ok {
|
||||||
current := ctx.currentBrowserUrl
|
current := ctx.currentBrowserUrl
|
||||||
if current != "" {
|
if current != "" {
|
||||||
u, err := url.Parse(current)
|
u, err := url.Parse(current)
|
||||||
|
|
@ -59,6 +59,9 @@ func GetQueryParam(ctx *RequestContext, key string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(value) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return value[0]
|
return value[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/maddalax/htmgo/framework/h"
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
"github.com/maddalax/htmgo/framework/service"
|
"github.com/maddalax/htmgo/framework/service"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
"starter-template/__htmgo"
|
"starter-template/__htmgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -15,18 +15,20 @@ var StaticAssets embed.FS
|
||||||
func main() {
|
func main() {
|
||||||
locator := service.NewLocator()
|
locator := service.NewLocator()
|
||||||
|
|
||||||
|
h.Start(h.AppOpts{
|
||||||
|
ServiceLocator: locator,
|
||||||
|
LiveReload: true,
|
||||||
|
Register: func(app *h.App) {
|
||||||
sub, err := fs.Sub(StaticAssets, "assets/dist")
|
sub, err := fs.Sub(StaticAssets, "assets/dist")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Start(h.AppOpts{
|
http.FileServerFS(sub)
|
||||||
ServiceLocator: locator,
|
|
||||||
LiveReload: true,
|
app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub)))
|
||||||
Register: func(e *echo.Echo) {
|
__htmgo.Register(app.Router)
|
||||||
e.StaticFS("/public", sub)
|
|
||||||
__htmgo.Register(e)
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue