diff --git a/handlers/handler.go b/handlers/handler.go index d3c9f0f..315852b 100644 --- a/handlers/handler.go +++ b/handlers/handler.go @@ -1,6 +1,7 @@ package handlers import ( + "context" "errors" "templ-test/client" "templ-test/domain" @@ -43,7 +44,16 @@ func (h *Handlers) Register(group echo.Group) { func Render(ctx echo.Context, statusCode int, t templ.Component) error { ctx.Response().Writer.WriteHeader(statusCode) ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) - return t.Render(ctx.Request().Context(), ctx.Response().Writer) + + // take the request context and make it a var + request := ctx.Request().Context() + //Check to see if we the echo context has the cookie we are looking for, if so, create a new context based on what we had and add the value + darkMode, err := ctx.Cookie(domain.CookieSettingsDarkMode) + if err == nil { + request = context.WithValue(request, domain.CookieSettingsDarkMode, darkMode.Value) + } + + return t.Render(request, ctx.Response().Writer) } type jwtToken struct { @@ -101,5 +111,10 @@ func GetCookieValues(ctx echo.Context) models.AllCookies { m.RefreshToken = refresh.Value } + darkMode, err := ctx.Cookie(domain.CookieSettingsDarkMode) + if err == nil { + m.DarkMode = darkMode.Value + } + return m } diff --git a/views/layout/body.templ b/views/layout/body.templ index f4eb6e0..e1af390 100644 --- a/views/layout/body.templ +++ b/views/layout/body.templ @@ -1,20 +1,8 @@ package layout templ WithLayout(pageName string) { - - @getHtmlHead() -
- @bootstrapNavBar() - @getBodyHeader(pageName) -