From 0206d848943aa70acaf0f1f2e658650c7e6015a7 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Tue, 9 Jul 2024 08:32:24 -0700 Subject: [PATCH 01/17] Created some components for bulma to make it easier to build new pages --- internal/views/bulma/button.templ | 34 +++++++++++++++++++++++++ internal/views/bulma/form/control.templ | 8 ++++++ internal/views/bulma/form/field.templ | 8 ++++++ internal/views/bulma/form/input.templ | 9 +++++++ internal/views/bulma/form/label.templ | 6 +++++ internal/views/bulma/form/new.templ | 7 +++++ internal/views/bulma/form/submit.templ | 5 ++++ internal/views/bulma/form/util.go | 6 +++++ internal/views/bulma/util.go | 10 ++++++++ 9 files changed, 93 insertions(+) create mode 100644 internal/views/bulma/button.templ create mode 100644 internal/views/bulma/form/control.templ create mode 100644 internal/views/bulma/form/field.templ create mode 100644 internal/views/bulma/form/input.templ create mode 100644 internal/views/bulma/form/label.templ create mode 100644 internal/views/bulma/form/new.templ create mode 100644 internal/views/bulma/form/submit.templ create mode 100644 internal/views/bulma/form/util.go create mode 100644 internal/views/bulma/util.go diff --git a/internal/views/bulma/button.templ b/internal/views/bulma/button.templ new file mode 100644 index 0000000..865a605 --- /dev/null +++ b/internal/views/bulma/button.templ @@ -0,0 +1,34 @@ +package bulma + +templ Button(color string, isLight, isDark bool) { + if isLight { + + } + if isDark { + + } + if !isLight && !isDark { + + } +} + +templ ButtonNewTab(url, text string) { + +} + + +templ ALink(url, title string) { + { title } +} + +templ ANewTab(url, text string) { + { text } +} diff --git a/internal/views/bulma/form/control.templ b/internal/views/bulma/form/control.templ new file mode 100644 index 0000000..d5183b2 --- /dev/null +++ b/internal/views/bulma/form/control.templ @@ -0,0 +1,8 @@ +package form + +// Div container to add a input field to. +templ Control() { +
+ { children... } +
+} \ No newline at end of file diff --git a/internal/views/bulma/form/field.templ b/internal/views/bulma/form/field.templ new file mode 100644 index 0000000..ad7b0c3 --- /dev/null +++ b/internal/views/bulma/form/field.templ @@ -0,0 +1,8 @@ +package form + +// This creates a field that you can add a Label, Control or Input object. +templ Field() { +
+ { children... } +
+} \ No newline at end of file diff --git a/internal/views/bulma/form/input.templ b/internal/views/bulma/form/input.templ new file mode 100644 index 0000000..5255d18 --- /dev/null +++ b/internal/views/bulma/form/input.templ @@ -0,0 +1,9 @@ +package form + +templ Input(color, id, fieldType string) { + if color == "" { + + } else { + + } +} diff --git a/internal/views/bulma/form/label.templ b/internal/views/bulma/form/label.templ new file mode 100644 index 0000000..66deea3 --- /dev/null +++ b/internal/views/bulma/form/label.templ @@ -0,0 +1,6 @@ +package form + +// This will create a small bit of text to add context to the form. +templ Label(text string) { + +} \ No newline at end of file diff --git a/internal/views/bulma/form/new.templ b/internal/views/bulma/form/new.templ new file mode 100644 index 0000000..a0a4190 --- /dev/null +++ b/internal/views/bulma/form/new.templ @@ -0,0 +1,7 @@ +package form + +templ New(postUrl string) { +
+ { children... } +
+} \ No newline at end of file diff --git a/internal/views/bulma/form/submit.templ b/internal/views/bulma/form/submit.templ new file mode 100644 index 0000000..e12ada7 --- /dev/null +++ b/internal/views/bulma/form/submit.templ @@ -0,0 +1,5 @@ +package form + +templ Submit(text, color string) { + +} \ No newline at end of file diff --git a/internal/views/bulma/form/util.go b/internal/views/bulma/form/util.go new file mode 100644 index 0000000..34750a1 --- /dev/null +++ b/internal/views/bulma/form/util.go @@ -0,0 +1,6 @@ +package form + +const ( + InputTypeText = "text" + InputTypePassword = "password" +) diff --git a/internal/views/bulma/util.go b/internal/views/bulma/util.go new file mode 100644 index 0000000..f53dfd9 --- /dev/null +++ b/internal/views/bulma/util.go @@ -0,0 +1,10 @@ +package bulma + +const ( + ColorPrimary = "is-primary" + ColorInfo = "is-info" + ColorLink = "is-link" + ColorWarning = "is-warning" + ColorSuccess = "is-success" + ColorError = "is-error" +) From bb135917cfb53cf1bd1eb94006c264977063de05 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Tue, 9 Jul 2024 08:32:38 -0700 Subject: [PATCH 02/17] new login page with the new components --- internal/views/users/login copy.templ | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 internal/views/users/login copy.templ diff --git a/internal/views/users/login copy.templ b/internal/views/users/login copy.templ new file mode 100644 index 0000000..8cb72a2 --- /dev/null +++ b/internal/views/users/login copy.templ @@ -0,0 +1,26 @@ +package users + +import ( + "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/bulma/form" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" +) + +templ LoginNew() { + @layout.WithTemplate() { + @form.New("/users/login") { + @form.Field() { + @form.Label("Username") + @form.Control() { + @form.Input("", "username", "text") + } + } + @form.Field(){ + @form.Label("Password") + @form.Control(){ + @form.Input("", "password", form.InputTypePassword) + } + } + @form.Submit("Submit", "is-primary") + } + } +} From d1f72aa0f1bae37584503ac98f2d475c7b6c43e2 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Tue, 9 Jul 2024 08:32:59 -0700 Subject: [PATCH 03/17] /logout was not working correctly because it was doing jwt checks --- internal/handlers/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/handlers/handler.go b/internal/handlers/handler.go index 8015ba8..500554c 100644 --- a/internal/handlers/handler.go +++ b/internal/handlers/handler.go @@ -71,8 +71,8 @@ func NewServer(ctx context.Context, configs config.Configs, apiClient apiclient. users.POST("/login", s.UserAfterLogin) users.GET("/signup", s.UserSignUp) users.POST("/signup", s.UserAfterSignUp) - users.Use(ValidateJwtMiddleware(configs.JwtSecret)) users.GET("/logout", s.UsersLogout) + users.Use(ValidateJwtMiddleware(configs.JwtSecret)) users.GET("/profile", s.UserProfile) s.Router = router From b6a6bb0043b74cbeee6badcf8e5361a285a7a1cc Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Tue, 9 Jul 2024 08:33:15 -0700 Subject: [PATCH 04/17] playing with more components --- internal/views/sources/add.templ | 15 ++++++++++++--- internal/views/sources/listAll.templ | 11 ++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/views/sources/add.templ b/internal/views/sources/add.templ index a61a503..bdd3cda 100644 --- a/internal/views/sources/add.templ +++ b/internal/views/sources/add.templ @@ -1,10 +1,19 @@ package sources -import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" -import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" +import ( + "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/bulma" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/bulma/form" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" +) templ Add(model models.AddSourcePayloadModel) { @layout.WithTemplate() { -
+

New Source

+

At this time only direct RSS links are allowed to be provided

+ @form.New("/sources/add") { + @form.Input("", "url", "text") + @form.Submit("Submit", bulma.ColorPrimary) + } } } diff --git a/internal/views/sources/listAll.templ b/internal/views/sources/listAll.templ index f1872a5..6f2379b 100644 --- a/internal/views/sources/listAll.templ +++ b/internal/views/sources/listAll.templ @@ -1,12 +1,17 @@ package sources -import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" -import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" +import ( + "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/bulma" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" +) templ ListAll(model models.ListAllSourcesViewModel) { @layout.WithTemplate() { for _, item := range model.Items { - { item.DisplayName } - { item.Source } + @bulma.Button(bulma.ColorPrimary, false, false) { + @bulma.ANewTab(item.Url, item.DisplayName) + }
} } From 435dfbda40a29022fd293a2bb0b251a33779612a Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Tue, 9 Jul 2024 08:33:25 -0700 Subject: [PATCH 05/17] moved login to use my new form --- internal/handlers/users.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/handlers/users.go b/internal/handlers/users.go index 44bb90a..cc05b12 100644 --- a/internal/handlers/users.go +++ b/internal/handlers/users.go @@ -11,7 +11,7 @@ import ( ) func (h *Handler) UserLogin(c echo.Context) error { - return Render(c, http.StatusOK, users.Login()) + return Render(c, http.StatusOK, users.LoginNew()) } func (h *Handler) UserAfterLogin(c echo.Context) error { From 574695bfb01184f23663b875b09ab9a0c8a3b66f Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Thu, 11 Jul 2024 08:08:58 -0700 Subject: [PATCH 06/17] moved view components out of internal and added some more --- .../views => components}/bulma/button.templ | 26 +++++----- .../views => components}/bulma/card.templ | 0 .../bulma/form/control.templ | 0 .../bulma/form/field.templ | 0 components/bulma/form/input.templ | 15 ++++++ .../bulma/form/label.templ | 0 components/bulma/form/new.templ | 13 +++++ components/bulma/form/select.templ | 33 +++++++++++++ .../bulma/form/submit.templ | 0 components/bulma/form/textarea.templ | 5 ++ components/bulma/form/util.go | 8 +++ .../views => components}/bulma/hero.templ | 0 components/bulma/notification.templ | 7 +++ .../views => components}/bulma/section.templ | 0 components/bulma/tags.templ | 13 +++++ components/bulma/title.templ | 49 +++++++++++++++++++ {internal/views => components}/bulma/util.go | 4 ++ components/templ-html/br.templ | 5 ++ components/templ-html/href.templ | 9 ++++ internal/views/articles/list.templ | 7 ++- internal/views/bulma/form/input.templ | 9 ---- internal/views/bulma/form/new.templ | 7 --- internal/views/bulma/form/util.go | 6 --- internal/views/home/index.templ | 2 +- internal/views/sources/add.templ | 19 ++++--- internal/views/sources/addAfter.templ | 11 +++++ internal/views/sources/listAll.templ | 10 +++- internal/views/users/afterLogin.templ | 13 +++-- internal/views/users/afterSignUp.templ | 10 ++-- internal/views/users/login copy.templ | 18 ++++--- internal/views/users/logout.templ | 2 +- internal/views/users/profile.templ | 18 ++++--- internal/views/users/signup.templ | 35 +++++++------ 33 files changed, 261 insertions(+), 93 deletions(-) rename {internal/views => components}/bulma/button.templ (55%) rename {internal/views => components}/bulma/card.templ (100%) rename {internal/views => components}/bulma/form/control.templ (100%) rename {internal/views => components}/bulma/form/field.templ (100%) create mode 100644 components/bulma/form/input.templ rename {internal/views => components}/bulma/form/label.templ (100%) create mode 100644 components/bulma/form/new.templ create mode 100644 components/bulma/form/select.templ rename {internal/views => components}/bulma/form/submit.templ (100%) create mode 100644 components/bulma/form/textarea.templ create mode 100644 components/bulma/form/util.go rename {internal/views => components}/bulma/hero.templ (100%) create mode 100644 components/bulma/notification.templ rename {internal/views => components}/bulma/section.templ (100%) create mode 100644 components/bulma/tags.templ create mode 100644 components/bulma/title.templ rename {internal/views => components}/bulma/util.go (71%) create mode 100644 components/templ-html/br.templ create mode 100644 components/templ-html/href.templ delete mode 100644 internal/views/bulma/form/input.templ delete mode 100644 internal/views/bulma/form/new.templ delete mode 100644 internal/views/bulma/form/util.go create mode 100644 internal/views/sources/addAfter.templ diff --git a/internal/views/bulma/button.templ b/components/bulma/button.templ similarity index 55% rename from internal/views/bulma/button.templ rename to components/bulma/button.templ index 865a605..5385978 100644 --- a/internal/views/bulma/button.templ +++ b/components/bulma/button.templ @@ -1,21 +1,18 @@ package bulma -templ Button(color string, isLight, isDark bool) { - if isLight { - - } - if isDark { - - } - if !isLight && !isDark { - +} + +// Used to create a button and lets you define the color. +// Accepts children. +templ ButtonColor(color string) { + - } } templ ButtonNewTab(url, text string) { @@ -24,7 +21,6 @@ templ ButtonNewTab(url, text string) { } - templ ALink(url, title string) { { title } } diff --git a/internal/views/bulma/card.templ b/components/bulma/card.templ similarity index 100% rename from internal/views/bulma/card.templ rename to components/bulma/card.templ diff --git a/internal/views/bulma/form/control.templ b/components/bulma/form/control.templ similarity index 100% rename from internal/views/bulma/form/control.templ rename to components/bulma/form/control.templ diff --git a/internal/views/bulma/form/field.templ b/components/bulma/form/field.templ similarity index 100% rename from internal/views/bulma/form/field.templ rename to components/bulma/form/field.templ diff --git a/components/bulma/form/input.templ b/components/bulma/form/input.templ new file mode 100644 index 0000000..d793c66 --- /dev/null +++ b/components/bulma/form/input.templ @@ -0,0 +1,15 @@ +package form + +templ TextInput(color, id, fieldType, placeholder string) { + if color == "" { + + } else { + + } +} + +templ Checkbox(text, id string) { + +} diff --git a/internal/views/bulma/form/label.templ b/components/bulma/form/label.templ similarity index 100% rename from internal/views/bulma/form/label.templ rename to components/bulma/form/label.templ diff --git a/components/bulma/form/new.templ b/components/bulma/form/new.templ new file mode 100644 index 0000000..8f5029e --- /dev/null +++ b/components/bulma/form/new.templ @@ -0,0 +1,13 @@ +package form + +type NewParam struct { + HxPost string +} + +templ New(param NewParam) { + if param.HxPost != "" { +
+ { children... } +
+ } +} diff --git a/components/bulma/form/select.templ b/components/bulma/form/select.templ new file mode 100644 index 0000000..8adffdc --- /dev/null +++ b/components/bulma/form/select.templ @@ -0,0 +1,33 @@ +package form + +templ SelectOne(color string, isRound bool) { + if isRound { +
+ +
+ } else { +
+ +
+ } +} + +templ SelectOneItem(name string) { + +} + +templ SelectMany(howManySelectable int, color string, isRound bool) { +
+ +
+} + +templ SelectManyItem(name string) { + +} diff --git a/internal/views/bulma/form/submit.templ b/components/bulma/form/submit.templ similarity index 100% rename from internal/views/bulma/form/submit.templ rename to components/bulma/form/submit.templ diff --git a/components/bulma/form/textarea.templ b/components/bulma/form/textarea.templ new file mode 100644 index 0000000..d922742 --- /dev/null +++ b/components/bulma/form/textarea.templ @@ -0,0 +1,5 @@ +package form + +templ TextArea(id, placeholder, color string) { +