From a4d5b7ade38227f8519803644fba1f62808269d4 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sun, 14 Apr 2024 18:38:09 -0700 Subject: [PATCH] moving things to use WithLayout and push the darkmode theme to a cookie that is pulled on layout render --- views/auth/cookie.templ | 2 +- views/auth/login.templ | 2 +- views/home/error.templ | 2 +- views/home/home.templ | 6 +++--- views/layout/body.templ | 2 +- views/layout/util.go | 8 +++++++- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/views/auth/cookie.templ b/views/auth/cookie.templ index a9e8ada..907609b 100644 --- a/views/auth/cookie.templ +++ b/views/auth/cookie.templ @@ -4,7 +4,7 @@ import "templ-test/models" import "templ-test/views/layout" templ ShowCookie(m models.AllCookies) { - @layout.Testing("Cookie Explorer") { + @layout.WithLayout("Cookie Explorer") {

These are stored as cookies

Username: { m.Username }

JWT Token: { m.Token }

diff --git a/views/auth/login.templ b/views/auth/login.templ index 6dc0886..b617169 100644 --- a/views/auth/login.templ +++ b/views/auth/login.templ @@ -3,7 +3,7 @@ package auth import "templ-test/views/layout" templ AuthLogin() { - @layout.WithLayout("Login", true) { + @layout.WithLayout("Login") {
diff --git a/views/home/error.templ b/views/home/error.templ index 7ca9230..f92a3b9 100644 --- a/views/home/error.templ +++ b/views/home/error.templ @@ -3,7 +3,7 @@ package home import "templ-test/views/layout" templ Error(message error) { - @layout.Testing("Error") { + @layout.WithLayout("Error") {

Oops... :(

{ message.Error() }

} diff --git a/views/home/home.templ b/views/home/home.templ index 0a1add7..e6e9f74 100644 --- a/views/home/home.templ +++ b/views/home/home.templ @@ -4,14 +4,14 @@ import "templ-test/views/components/bootstrap" import "templ-test/views/layout" templ Home() { - @layout.WithLayout("Home", true) { + @layout.WithLayout("Home") {

this should be above the alert

@bootstrap.BootstrapAlert("Testing!", bootstrap.VariantDark)

you should now see this under the Alert

- @bootstrap.BootstrapButton("I am in danger", bootstrap.VariantDanger) - @bootstrap.BootstrapButton("I am the darkness", bootstrap.VariantDark) + @bootstrap.BootstrapButton("I am in danger", bootstrap.VariantDanger, bootstrap.ButtonTypeDefault) + @bootstrap.BootstrapButton("I am the darkness", bootstrap.VariantDark, bootstrap.ButtonTypeDefault) } } diff --git a/views/layout/body.templ b/views/layout/body.templ index a626b65..f4eb6e0 100644 --- a/views/layout/body.templ +++ b/views/layout/body.templ @@ -1,6 +1,6 @@ package layout -templ WithLayout(pageName string, useDarkMode bool) { +templ WithLayout(pageName string) { @getHtmlHead() diff --git a/views/layout/util.go b/views/layout/util.go index ea4ec80..78351cd 100644 --- a/views/layout/util.go +++ b/views/layout/util.go @@ -2,8 +2,14 @@ package layout import ( "context" + "templ-test/domain" ) func useLightOrDarkTheme(ctx context.Context) string { - return "dark" + cookie := ctx.Value(domain.CookieSettingsDarkMode) + if cookie == "on" { + return "dark" + } else { + return "light" + } }