From 9b01d1616e130a589151bf1273e41181ecc727f4 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 25 Apr 2025 21:25:40 -0600 Subject: feat: use htmx to render partials --- app/controllers/dashboard/controller.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app/controllers/dashboard/controller.go') diff --git a/app/controllers/dashboard/controller.go b/app/controllers/dashboard/controller.go index 220871f..0f165ad 100644 --- a/app/controllers/dashboard/controller.go +++ b/app/controllers/dashboard/controller.go @@ -20,6 +20,7 @@ func (c *Controller) MountTo(mux *http.ServeMux) { requireUser := middleware.RequireUser() mux.Handle("GET /dashboard", requireUser(http.HandlerFunc(c.Show))) + mux.Handle("GET /dashboard/nav", http.HandlerFunc(c.Navigation)) } func (c *Controller) Show(w http.ResponseWriter, r *http.Request) { @@ -35,3 +36,20 @@ func (c *Controller) Show(w http.ResponseWriter, r *http.Request) { return } } + +func (c *Controller) Navigation(w http.ResponseWriter, r *http.Request) { + currentUser := cfg.CurrentUser.From(r.Context()) + + w.WriteHeader(http.StatusOK) + w.Header().Add("Content-Type", "text/html") + + dto := &NavigationDTO{ + CurrentUser: currentUser, + IsLoggedIn: currentUser != nil, + } + if err := views.Render(w, "dashboard/nav", dto); err != nil { + log.WithFields(r.Context(), log.Fields{"error": err}) + w.WriteHeader(http.StatusInternalServerError) + return + } +} -- cgit v1.2.3