diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-25 21:25:40 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-28 09:07:31 -0600 |
| commit | 9b01d1616e130a589151bf1273e41181ecc727f4 (patch) | |
| tree | 639ec3b3c3857042a551c8e88b09413f590ebcec /app/controllers/dashboard/controller.go | |
| parent | 13ab8de7d09b5d4b10132828277d17ba0543b901 (diff) | |
feat: use htmx to render partials
Diffstat (limited to 'app/controllers/dashboard/controller.go')
| -rw-r--r-- | app/controllers/dashboard/controller.go | 18 |
1 files changed, 18 insertions, 0 deletions
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 + } +} |
