From 605c64ef92f0710b532c766019f0dcd86a66d002 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Tue, 6 May 2025 20:00:57 +0200 Subject: [PATCH 1/2] feat: replace air with templ hot reload --- .air.toml | 15 --------------- db/account.go | 3 +-- dev.sh | 6 ++++++ 3 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 .air.toml create mode 100755 dev.sh diff --git a/.air.toml b/.air.toml deleted file mode 100644 index 6346c58..0000000 --- a/.air.toml +++ /dev/null @@ -1,15 +0,0 @@ -root = "." -tmp_dir = "tmp" - -[build] - bin = "./tmp/main" - cmd = "templ generate && go build -o ./tmp/main ." - exclude_dir = ["static", "migrations", "node_modules", "tmp"] - exclude_regex = ["_test.go", "_templ.go"] - include_ext = ["go", "templ"] - send_interrupt = true - kill_delay = "5s" - stop_on_error = true - -[misc] - clean_on_exit = true diff --git a/db/account.go b/db/account.go index fa14b53..5079e5e 100644 --- a/db/account.go +++ b/db/account.go @@ -4,9 +4,8 @@ import ( "spend-sparrow/log" "spend-sparrow/types" - "github.com/jmoiron/sqlx" - "github.com/google/uuid" + "github.com/jmoiron/sqlx" ) type Account interface { diff --git a/dev.sh b/dev.sh new file mode 100755 index 0000000..3df34be --- /dev/null +++ b/dev.sh @@ -0,0 +1,6 @@ +templ generate --watch --proxy="http://localhost:8080" --cmd="go run ." & +npm run watch & + +read -n1 -s +kill $(jobs -p) + -- 2.49.1 From b8f13dfc93b00eeb0ca9b088357138309dddfc4c Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Tue, 6 May 2025 22:10:49 +0200 Subject: [PATCH 2/2] feat(layout): #49 update layout by navigation --- dev.sh | 2 +- handler/render.go | 2 +- handler/{index_and_404.go => root_and_404.go} | 10 +- package.json | 4 +- template/dashboard.templ | 9 ++ template/layout.templ | 104 ++++++++++-------- 6 files changed, 80 insertions(+), 51 deletions(-) rename handler/{index_and_404.go => root_and_404.go} (79%) create mode 100644 template/dashboard.templ diff --git a/dev.sh b/dev.sh index 3df34be..1c8f632 100755 --- a/dev.sh +++ b/dev.sh @@ -1,5 +1,5 @@ templ generate --watch --proxy="http://localhost:8080" --cmd="go run ." & -npm run watch & +npm run watch read -n1 -s kill $(jobs -p) diff --git a/handler/render.go b/handler/render.go index 21e062d..969f79a 100644 --- a/handler/render.go +++ b/handler/render.go @@ -38,7 +38,7 @@ func (render *Render) RenderLayout(r *http.Request, w http.ResponseWriter, slot func (render *Render) RenderLayoutWithStatus(r *http.Request, w http.ResponseWriter, slot templ.Component, user *types.User, status int) { userComp := render.getUserComp(user) - layout := template.Layout(slot, userComp) + layout := template.Layout(slot, userComp, user != nil, r.URL.Path) render.RenderWithStatus(r, w, layout, status) } diff --git a/handler/index_and_404.go b/handler/root_and_404.go similarity index 79% rename from handler/index_and_404.go rename to handler/root_and_404.go index 82245a4..4d836dd 100644 --- a/handler/index_and_404.go +++ b/handler/root_and_404.go @@ -27,10 +27,10 @@ func NewIndex(service service.Auth, render *Render) Index { } func (handler IndexImpl) Handle(router *http.ServeMux) { - router.Handle("/", handler.handleIndexAnd404()) + router.Handle("/", handler.handleRootAnd404()) } -func (handler IndexImpl) handleIndexAnd404() http.HandlerFunc { +func (handler IndexImpl) handleRootAnd404() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { user := middleware.GetUser(r) @@ -41,7 +41,11 @@ func (handler IndexImpl) handleIndexAnd404() http.HandlerFunc { comp = template.NotFound() status = http.StatusNotFound } else { - comp = template.Index() + if user != nil { + comp = template.Dashboard() + } else { + comp = template.Index() + } status = http.StatusOK } diff --git a/package.json b/package.json index d400340..8ee90b6 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "Your (almost) independent tech stack to host on a VPC.", "main": "index.js", "scripts": { - "build": "mkdir -p static/js && cp -f node_modules/htmx.org/dist/htmx.min.js static/js/htmx.min.js && tailwindcss -i input.css -o static/css/tailwind.css --minify", - "watch": "mkdir -p static/js && cp -f node_modules/htmx.org/dist/htmx.min.js static/js/htmx.min.js && tailwindcss -i input.css -o static/css/tailwind.css --watch" + "build": "cp -f node_modules/htmx.org/dist/htmx.min.js static/js/htmx.min.js && tailwindcss -i input.css -o static/css/tailwind.css --minify", + "watch": "cp -f node_modules/htmx.org/dist/htmx.min.js static/js/htmx.min.js && tailwindcss -i input.css -o static/css/tailwind.css --watch" }, "keywords": [], "author": "", diff --git a/template/dashboard.templ b/template/dashboard.templ new file mode 100644 index 0000000..700d65d --- /dev/null +++ b/template/dashboard.templ @@ -0,0 +1,9 @@ +package template + +templ Dashboard() { +
+

+ Dashboard +

+
+} diff --git a/template/layout.templ b/template/layout.templ index 0d5a234..b8c8869 100644 --- a/template/layout.templ +++ b/template/layout.templ @@ -1,52 +1,68 @@ package template -templ Layout(slot templ.Component, user templ.Component) { - - +func layoutLinkClass(isActive bool) string { + if isActive { + return "text-xl hover:bg-gray-100 p-1 duration-100 rounded-xl transition-colors text-gray-900" + } + return "text-xl hover:bg-gray-100 hover:text-gray-900 p-1 duration-200 rounded-xl transition-colors text-gray-400" +} - - - SpendSparrow - - - - - - - - - -
- // Header -
-
- - SpendSparrow logo - SpendSparrow - - @user + }' + /> + + + + +
+ // Header +
+ +
+
+ // Content +
+ if slot != nil { + @slot + } +
+ // Footer
-
-
- // Content -
- if slot != nil { - @slot - } -
- // Footer -
-
- -
- - - +
+ +
+ + } -- 2.49.1