Updated handlers, views and models to support meta tags

This commit is contained in:
James Tombleson 2024-07-14 09:07:16 -07:00
parent e8d4570dba
commit ad3756d27d
23 changed files with 110 additions and 37 deletions

View File

@ -20,7 +20,12 @@ func (h *Handler) ArticlesList(c echo.Context) error {
return RenderError(c, err)
}
vm := models.ListArticlesViewModel{}
vm := models.ListArticlesViewModel{
HeaderMetaTags: models.HeaderMetaTags{
Title: "Articles",
Type: "Page",
},
}
for _, article := range resp.Payload {
source, err := h.api.Sources.GetById(GetJwtToken(c), article.SourceID)
@ -36,5 +41,5 @@ func (h *Handler) ArticlesList(c echo.Context) error {
}
return Render(c, http.StatusOK, articles.ListArticlesTable(vm))
return Render(c, http.StatusOK, articles.List(vm))
}

View File

@ -3,14 +3,27 @@ package handlers
import (
"net/http"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/home"
"github.com/labstack/echo/v4"
)
func (h *Handler) HomeIndex(c echo.Context) error {
return Render(c, http.StatusOK, home.Index())
return Render(c, http.StatusOK, home.Index(models.HomeIndexViewModel{
HeaderMetaTags: models.HeaderMetaTags{
Title: "Newsbot",
Description: "Welcome to your news",
Url: "",
Type: "Page",
},
}))
}
func (h *Handler) HomeAbout(c echo.Context) error {
return Render(c, http.StatusOK, home.About())
}
return Render(c, http.StatusOK, home.About(models.HomeAboutViewModel{
HeaderMetaTags: models.HeaderMetaTags{
Title: "About",
Type: "Page",
},
}))
}

View File

@ -11,7 +11,12 @@ import (
)
func (h *Handler) UserLogin(c echo.Context) error {
return Render(c, http.StatusOK, users.LoginNew())
return Render(c, http.StatusOK, users.LoginNew(models.UsersLoginViewModel{
HeaderMetaTags: models.HeaderMetaTags{
Title: "Login",
Type: "Page",
},
}))
}
func (h *Handler) UserAfterLogin(c echo.Context) error {

View File

@ -3,10 +3,12 @@ package models
import "git.jamestombleson.com/jtom38/newsbot-api/domain"
type ListArticlesViewModel struct {
HeaderMetaTags
Items []ListArticleSourceModel
}
type ListArticleSourceModel struct {
HeaderMetaTags
Article domain.ArticleDto
Source domain.SourceDto
}

View File

@ -1,6 +1,7 @@
package models
type DebugCookiesViewModel struct {
HeaderMetaTags
Username string
Token string
RefreshToken string

9
internal/models/home.go Normal file
View File

@ -0,0 +1,9 @@
package models
type HomeIndexViewModel struct {
HeaderMetaTags
}
type HomeAboutViewModel struct {
HeaderMetaTags
}

View File

@ -4,3 +4,11 @@ type LayoutIsLoggedInViewModel struct {
IsLoggedIn bool
Username string
}
type HeaderMetaTags struct {
Title string
Url string
Image string
Description string
Type string
}

View File

@ -3,11 +3,12 @@ package models
import "git.jamestombleson.com/jtom38/newsbot-api/domain"
type ListAllSourcesViewModel struct {
HeaderMetaTags
IsError bool
Message string
Items []domain.SourceDto
}
type AddSourcePayloadModel struct {
HeaderMetaTags
}

View File

@ -1,5 +1,9 @@
package models
type UsersLoginViewModel struct {
HeaderMetaTags
}
type AfterLoginViewModel struct {
Message string
Success bool

View File

@ -7,7 +7,7 @@ import (
)
templ List(model models.ListArticlesViewModel) {
@layout.WithTemplate() {
@layout.WithTemplate(model.HeaderMetaTags) {
@filterBar()
for _, item := range model.Items {
@bulma.ArticleCardWithThumbnail(item.Article.Title, item.Article.Thumbnail, item.Article.Url, item.Article.PubDate.String(), item.Source.DisplayName)

View File

@ -7,12 +7,13 @@ import (
)
templ ListArticlesTable(model models.ListArticlesViewModel) {
@layout.WithTemplate() {
@layout.WithTemplate(model.HeaderMetaTags) {
@bulma.Table() {
@bulma.TableHeader() {
@bulma.TableRow() {
@bulma.TableHeaderData("Title")
@bulma.TableHeaderData("Source")
@bulma.TableHeaderDataToolTip("Pub", "Date Published")
@bulma.TableHeaderData("View")
}
}
@ -20,6 +21,7 @@ templ ListArticlesTable(model models.ListArticlesViewModel) {
@bulma.TableRow() {
@bulma.TableData(item.Article.Title)
@bulma.TableData(item.Source.DisplayName)
@bulma.TableData(item.Article.PubDate.String())
@bulma.TableDataChildren() {
@bulma.Button() {
@bulma.ANewTab(item.Article.Url, "View")

View File

@ -4,7 +4,7 @@ import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ Cookies(vm models.DebugCookiesViewModel) {
@layout.WithTemplate() {
@layout.WithTemplate(vm.HeaderMetaTags) {
<p>
Token: { vm.Token }
</p>

View File

@ -2,9 +2,10 @@ package home
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma"
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ About() {
@layout.WithTemplate(){
templ About(vm models.HomeAboutViewModel) {
@layout.WithTemplate(vm.HeaderMetaTags){
@bulma.Title("About this project")
@bulma.Block() {
Newsbot started a small project to send out notifications to discord servers.

View File

@ -3,11 +3,12 @@ package home
import (
b "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma"
bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
)
templ Index() {
@layout.WithTemplate() {
templ Index(vm models.HomeIndexViewModel) {
@layout.WithTemplate(vm.HeaderMetaTags) {
@bl.Hero("Welcome to Newsbot!", "Your new home for your news.")
@b.Block() {
News bot is a self hostable solution to aggregating your news.

View File

@ -1,7 +1,12 @@
package layout
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ Error(err error) {
@WithTemplate() {
@WithTemplate(models.HeaderMetaTags{
Title: "Error",
Description: err.Error(),
}) {
<h1 class="title">Error</h1>
<h2 class="subtitle">{ err.Error() } </h2>
}

View File

@ -1,17 +1,18 @@
package layout
import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma"
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ header() {
templ header(meta models.HeaderMetaTags) {
@bulma.UseBulmaCdn()
<link rel="stylesheet" href="/css/main.css"/>
<script src="https://unpkg.com/htmx.org@1.9.11" integrity="sha384-0gxUXCCR8yv9FM2b+U3FDbsKthCI66oH5IA9fHppQq9DDMHuMauqq1ZHBpJxQ0J0" crossorigin="anonymous"></script>
<meta charset="utf-8"/>
<meta property="og:title" content=""/>
<meta property="og:url" content=""/>
<meta property="og:image" content=""/>
<meta property="og:description" content=""/>
<meta property="og:type" content=""/>
<meta property="og:title" content={ meta.Title }/>
<meta property="og:url" content={ meta.Url }/>
<meta property="og:image" content={ meta.Image }/>
<meta property="og:description" content={ meta.Image }/>
<meta property="og:type" content={ meta.Type }/>
<style type="text/css">
.pin-bottom {
position: absolute;

View File

@ -15,7 +15,7 @@ var (
)
templ Add(model models.AddSourcePayloadModel) {
@layout.WithTemplate() {
@layout.WithTemplate(model.HeaderMetaTags) {
@bl.Hero("New Source", "")
@bulma.Block() {
At this time only direct RSS links are allowed to be provided.

View File

@ -8,7 +8,7 @@ import (
)
templ ListAll(model models.ListAllSourcesViewModel) {
@layout.WithTemplate() {
@layout.WithTemplate(model.HeaderMetaTags) {
@bulma.Button() {
@bh.ALink("/sources/add", "New Source")
}

View File

@ -3,6 +3,7 @@ package users
import (
"git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/form"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
)
var (
@ -11,8 +12,8 @@ var (
}
)
templ LoginNew() {
@layout.WithTemplate() {
templ LoginNew(vm models.UsersLoginViewModel) {
@layout.WithTemplate(vm.HeaderMetaTags) {
@form.New(p) {
@form.Field() {
@form.Label("Username")

View File

@ -1,9 +1,10 @@
package users
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ Login() {
@layout.WithTemplate() {
templ Login(vm models.UsersLoginViewModel) {
@layout.WithTemplate(vm.HeaderMetaTags) {
<form hx-post="/users/login">
<div class="field">
<label class="label">Username</label>

View File

@ -1,10 +1,16 @@
package users
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
import bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout"
import (
bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
)
templ Logout() {
@layout.WithTemplate(){
@bl.Hero("You are out of here!", "Please login again when you are ready.")
}
}
@layout.WithTemplate(models.HeaderMetaTags{
Title: "Logged Out",
Type: "Page",
}) {
@bl.Hero("You are out of here!", "Please login again when you are ready.")
}
}

View File

@ -4,13 +4,16 @@ import (
"git.jamestombleson.com/jtom38/newsbot-portal/components/bulma"
bh "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/html"
bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
)
templ Profile() {
@layout.WithTemplate() {
@layout.WithTemplate(models.HeaderMetaTags{
Title: "Profile",
Type: "Page",
}) {
@bl.Hero("Profile", "Here you can update your profile 😀")
@bulma.H2("Sessions", false)
@bulma.Button() {
@bh.ALink("/users/forcelogout", "Terminate all active sessions")

View File

@ -2,13 +2,17 @@ package users
import (
"git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/form"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
)
templ SignUp() {
@layout.WithTemplate() {
@layout.WithTemplate(models.HeaderMetaTags{
Title: "Signup",
Type: "Page",
}) {
@form.New(form.NewParam{HxPost: "/users/signup"}) {
@form.Field(){
@form.Field() {
@form.Label("Username")
@form.Control() {
@form.TextInput("username", form.InputTypeText, "username or email address")