From bdd9c8d9634d2b42077e4bf1a3162c6d20cc0f96 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sat, 13 Apr 2024 11:50:05 -0700 Subject: [PATCH] reworked how the views should be setup to make it cleaner and also starting to figure out how to work with the context with templ --- views/auth/cookie.templ | 4 +- views/auth/login.templ | 6 +-- views/home/error.templ | 10 +++++ views/{ => home}/home.templ | 11 ++--- views/home/settings.templ | 9 ++++ views/layout/body.templ | 27 ++++++++++++ views/layout/header.templ | 19 ++++++++ views/{layout.templ => layout/navbar.templ} | 48 +-------------------- views/layout/util.go | 9 ++++ 9 files changed, 84 insertions(+), 59 deletions(-) create mode 100644 views/home/error.templ rename views/{ => home}/home.templ (80%) create mode 100644 views/home/settings.templ create mode 100644 views/layout/body.templ create mode 100644 views/layout/header.templ rename views/{layout.templ => layout/navbar.templ} (54%) create mode 100644 views/layout/util.go diff --git a/views/auth/cookie.templ b/views/auth/cookie.templ index ff7bf00..a9e8ada 100644 --- a/views/auth/cookie.templ +++ b/views/auth/cookie.templ @@ -1,10 +1,10 @@ package auth -import "templ-test/views" import "templ-test/models" +import "templ-test/views/layout" templ ShowCookie(m models.AllCookies) { - @views.WithLayout("Cookie Explorer", true) { + @layout.Testing("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 a6e6728..6dc0886 100644 --- a/views/auth/login.templ +++ b/views/auth/login.templ @@ -1,9 +1,9 @@ package auth -import "templ-test/views" +import "templ-test/views/layout" templ AuthLogin() { - @views.WithLayout("Login", true) { + @layout.WithLayout("Login", true) {
@@ -20,4 +20,4 @@ templ AuthLogin() { } -} \ No newline at end of file +} diff --git a/views/home/error.templ b/views/home/error.templ new file mode 100644 index 0000000..7ca9230 --- /dev/null +++ b/views/home/error.templ @@ -0,0 +1,10 @@ +package home + +import "templ-test/views/layout" + +templ Error(message error) { + @layout.Testing("Error") { +

Oops... :(

+

{ message.Error() }

+ } +} diff --git a/views/home.templ b/views/home/home.templ similarity index 80% rename from views/home.templ rename to views/home/home.templ index f02c7eb..0a1add7 100644 --- a/views/home.templ +++ b/views/home/home.templ @@ -1,9 +1,10 @@ -package views +package home import "templ-test/views/components/bootstrap" +import "templ-test/views/layout" templ Home() { - @Testing("Home", true) { + @layout.WithLayout("Home", true) {

this should be above the alert

@@ -14,9 +15,3 @@ templ Home() { } } - -templ List() { - @Testing("Lists", true) { - - } -} diff --git a/views/home/settings.templ b/views/home/settings.templ new file mode 100644 index 0000000..30da693 --- /dev/null +++ b/views/home/settings.templ @@ -0,0 +1,9 @@ +package home + +import "templ-test/views/layout" + +templ UserSettings() { + @layout.Testing("Settings") { +

This is not ready yet

+ } +} diff --git a/views/layout/body.templ b/views/layout/body.templ new file mode 100644 index 0000000..a626b65 --- /dev/null +++ b/views/layout/body.templ @@ -0,0 +1,27 @@ +package layout + +templ WithLayout(pageName string, useDarkMode bool) { + + @getHtmlHead() + + @bootstrapNavBar() + @getBodyHeader(pageName) +
+ { children... } +
+ + +} + +templ Testing(pageName string) { + + @getHtmlHead() + + @bootstrapNavBar() + @getBodyHeader(pageName) +
+ { children... } +
+ + +} diff --git a/views/layout/header.templ b/views/layout/header.templ new file mode 100644 index 0000000..7a338a0 --- /dev/null +++ b/views/layout/header.templ @@ -0,0 +1,19 @@ +package layout + +templ getHtmlHead() { + + + + + + + + + +} + +templ getBodyHeader(pageName string) { +
+

{ pageName }

+
+} \ No newline at end of file diff --git a/views/layout.templ b/views/layout/navbar.templ similarity index 54% rename from views/layout.templ rename to views/layout/navbar.templ index 1557aae..9101e8b 100644 --- a/views/layout.templ +++ b/views/layout/navbar.templ @@ -1,51 +1,7 @@ -package views - -templ WithLayout(pageName string, useDarkMode bool) { - - @getHtmlHead() - - @bootstrapNavBar() - @getBodyHeader(pageName) -
- { children... } -
- - -} - -templ Testing(pageName string, useDarkMode bool) { - - @getHtmlHead() - - @bootstrapNavBar() - @getBodyHeader(pageName) -
- { children... } -
- - -} - -templ getHtmlHead() { - - - - - - - - - -} - -templ getBodyHeader(pageName string) { -
-

{ pageName }

-
-} +package layout templ bootstrapNavBar() { -