From 10de2f216f48e4ac1426edda82179a09c7002fa0 Mon Sep 17 00:00:00 2001 From: maddalax Date: Thu, 26 Sep 2024 14:40:09 -0500 Subject: [PATCH] Revert "fix example todo" This reverts commit a2b286e9aa33739f86e20fb6437873b83d7b36ff. --- examples/todo-list/main.go | 24 ++++++++++-------------- examples/todo-list/pages/base/root.go | 4 ---- examples/todo-list/partials/task/task.go | 4 ++-- framework/h/app.go | 4 ---- framework/h/qs.go | 5 +---- templates/starter/main.go | 22 ++++++++++------------ 6 files changed, 23 insertions(+), 40 deletions(-) diff --git a/examples/todo-list/main.go b/examples/todo-list/main.go index 791045bf..81ce1ae7 100644 --- a/examples/todo-list/main.go +++ b/examples/todo-list/main.go @@ -2,11 +2,11 @@ package main import ( "embed" + "github.com/labstack/echo/v4" "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" _ "github.com/mattn/go-sqlite3" "io/fs" - "net/http" "todolist/__htmgo" "todolist/ent" "todolist/infrastructure/db" @@ -22,22 +22,18 @@ func main() { return db.Provide() }) + sub, err := fs.Sub(StaticAssets, "assets/dist") + + if err != nil { + panic(err) + } + h.Start(h.AppOpts{ ServiceLocator: locator, LiveReload: true, - Register: func(app *h.App) { - - sub, err := fs.Sub(StaticAssets, "assets/dist") - - if err != nil { - panic(err) - } - - http.FileServerFS(sub) - - app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub))) - - __htmgo.Register(app.Router) + Register: func(e *echo.Echo) { + e.StaticFS("/public", sub) + __htmgo.Register(e) }, }) } diff --git a/examples/todo-list/pages/base/root.go b/examples/todo-list/pages/base/root.go index 7a9ca912..79b125a0 100644 --- a/examples/todo-list/pages/base/root.go +++ b/examples/todo-list/pages/base/root.go @@ -8,10 +8,6 @@ func RootPage(children ...h.Ren) h.Ren { return h.Html( h.HxExtension(h.BaseExtensions()), 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.Script("/public/htmgo.js"), ), diff --git a/examples/todo-list/partials/task/task.go b/examples/todo-list/partials/task/task.go index 80245b1d..bf152685 100644 --- a/examples/todo-list/partials/task/task.go +++ b/examples/todo-list/partials/task/task.go @@ -68,9 +68,9 @@ func CompleteAllIcon(list []*ent.Task) *h.Element { })) return h.Div( - h.ClassX("absolute top-1 left-5 p-2 rotate-90 text-3xl cursor-pointer", map[string]bool{ + h.ClassX("absolute top-0 left-0 p-4 rotate-90 text-2xl cursor-pointer", map[string]bool{ "text-slate-400": notCompletedCount > 0, - }), h.Text("›"), + }), h.Text("❯"), h.PostPartialWithQs(CompleteAll, h.NewQs("complete", h.Ternary(notCompletedCount > 0, "true", "false"))), ) } diff --git a/framework/h/app.go b/framework/h/app.go index 95b56987..f80ae1fe 100644 --- a/framework/h/app.go +++ b/framework/h/app.go @@ -26,10 +26,6 @@ type RequestContext struct { 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{}) { if c.kv == nil { c.kv = make(map[string]interface{}) diff --git a/framework/h/qs.go b/framework/h/qs.go index 31b2b93f..df83474e 100644 --- a/framework/h/qs.go +++ b/framework/h/qs.go @@ -50,7 +50,7 @@ func (q *Qs) ToString() string { func GetQueryParam(ctx *RequestContext, key string) string { value, ok := ctx.URL.Query()[key] - if value == nil || !ok { + if !ok { current := ctx.currentBrowserUrl if current != "" { u, err := url.Parse(current) @@ -59,9 +59,6 @@ func GetQueryParam(ctx *RequestContext, key string) string { } } } - if len(value) == 0 { - return "" - } return value[0] } diff --git a/templates/starter/main.go b/templates/starter/main.go index bd79fac9..68e28eb9 100644 --- a/templates/starter/main.go +++ b/templates/starter/main.go @@ -2,10 +2,10 @@ package main import ( "embed" + "github.com/labstack/echo/v4" "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" "io/fs" - "net/http" "starter-template/__htmgo" ) @@ -15,20 +15,18 @@ var StaticAssets embed.FS func main() { locator := service.NewLocator() + sub, err := fs.Sub(StaticAssets, "assets/dist") + + if err != nil { + panic(err) + } + h.Start(h.AppOpts{ ServiceLocator: locator, LiveReload: true, - Register: func(app *h.App) { - sub, err := fs.Sub(StaticAssets, "assets/dist") - - if err != nil { - panic(err) - } - - http.FileServerFS(sub) - - app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub))) - __htmgo.Register(app.Router) + Register: func(e *echo.Echo) { + e.StaticFS("/public", sub) + __htmgo.Register(e) }, }) }