From b8f13dfc93b00eeb0ca9b088357138309dddfc4c Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Tue, 6 May 2025 22:10:49 +0200 Subject: [PATCH] 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 -
-
- -
- - - +
+ +
+ + }