features/header-tags #4

Merged
jtom38 merged 3 commits from features/header-tags into main 2024-07-14 09:08:17 -07:00
29 changed files with 171 additions and 44 deletions

View File

@ -14,9 +14,39 @@ templ ArticleCardWithThumbnail(title, thumbnailUrl, url, datePosted, sourceName
</div> </div>
</div> </div>
<div class="content"> <div class="content">
{ datePosted }<br/> { datePosted }
<br/>
{ sourceName } { sourceName }
</div> </div>
</div> </div>
</div> </div>
} }
// Creates a card container.
// Accepts children
templ Card() {
<div class="card">
{ children... }
</div>
}
// Creates a image card container.
// Accepts children
templ CardImage() {
<div class="card-image">
{ children... }
</div>
}
//
templ CardImageSize(size string) {
<figure class={ "image", size }>
{ children... }
</figure>
}
templ CardContentContainer() {
<div class="card-content">
{ children... }
</div>
}

View File

@ -1 +0,0 @@
package example

View File

@ -0,0 +1,9 @@
package html
templ Img(src string) {
<img src={ src } />
}
templ ImgAlt(src, alt string) {
<img src={ src } alt={ alt }/>
}

View File

@ -0,0 +1,10 @@
package bulma
// Creates a image wrapper.
// This accepts children.
// Use html.Img() to load a image as a child
templ Image(image string) {
<figure class={ "image", image }>
{ children... }
</figure>
}

View File

@ -1,4 +1,4 @@
package bulma package layout
// Creates a <section> object thats good to break up a page of content. // Creates a <section> object thats good to break up a page of content.
templ Section(title, subtitle string) { templ Section(title, subtitle string) {

View File

@ -20,7 +20,12 @@ func (h *Handler) ArticlesList(c echo.Context) error {
return RenderError(c, err) return RenderError(c, err)
} }
vm := models.ListArticlesViewModel{} vm := models.ListArticlesViewModel{
HeaderMetaTags: models.HeaderMetaTags{
Title: "Articles",
Type: "Page",
},
}
for _, article := range resp.Payload { for _, article := range resp.Payload {
source, err := h.api.Sources.GetById(GetJwtToken(c), article.SourceID) 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 ( import (
"net/http" "net/http"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/home" "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/home"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
func (h *Handler) HomeIndex(c echo.Context) error { 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 { 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 { 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 { func (h *Handler) UserAfterLogin(c echo.Context) error {

View File

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

View File

@ -1,6 +1,7 @@
package models package models
type DebugCookiesViewModel struct { type DebugCookiesViewModel struct {
HeaderMetaTags
Username string Username string
Token string Token string
RefreshToken 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 IsLoggedIn bool
Username string 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" import "git.jamestombleson.com/jtom38/newsbot-api/domain"
type ListAllSourcesViewModel struct { type ListAllSourcesViewModel struct {
HeaderMetaTags
IsError bool IsError bool
Message string Message string
Items []domain.SourceDto Items []domain.SourceDto
} }
type AddSourcePayloadModel struct { type AddSourcePayloadModel struct {
HeaderMetaTags
} }

View File

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

View File

@ -7,7 +7,7 @@ import (
) )
templ List(model models.ListArticlesViewModel) { templ List(model models.ListArticlesViewModel) {
@layout.WithTemplate() { @layout.WithTemplate(model.HeaderMetaTags) {
@filterBar() @filterBar()
for _, item := range model.Items { for _, item := range model.Items {
@bulma.ArticleCardWithThumbnail(item.Article.Title, item.Article.Thumbnail, item.Article.Url, item.Article.PubDate.String(), item.Source.DisplayName) @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) { templ ListArticlesTable(model models.ListArticlesViewModel) {
@layout.WithTemplate() { @layout.WithTemplate(model.HeaderMetaTags) {
@bulma.Table() { @bulma.Table() {
@bulma.TableHeader() { @bulma.TableHeader() {
@bulma.TableRow() { @bulma.TableRow() {
@bulma.TableHeaderData("Title") @bulma.TableHeaderData("Title")
@bulma.TableHeaderData("Source") @bulma.TableHeaderData("Source")
@bulma.TableHeaderDataToolTip("Pub", "Date Published")
@bulma.TableHeaderData("View") @bulma.TableHeaderData("View")
} }
} }
@ -20,6 +21,7 @@ templ ListArticlesTable(model models.ListArticlesViewModel) {
@bulma.TableRow() { @bulma.TableRow() {
@bulma.TableData(item.Article.Title) @bulma.TableData(item.Article.Title)
@bulma.TableData(item.Source.DisplayName) @bulma.TableData(item.Source.DisplayName)
@bulma.TableData(item.Article.PubDate.String())
@bulma.TableDataChildren() { @bulma.TableDataChildren() {
@bulma.Button() { @bulma.Button() {
@bulma.ANewTab(item.Article.Url, "View") @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" import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ Cookies(vm models.DebugCookiesViewModel) { templ Cookies(vm models.DebugCookiesViewModel) {
@layout.WithTemplate() { @layout.WithTemplate(vm.HeaderMetaTags) {
<p> <p>
Token: { vm.Token } Token: { vm.Token }
</p> </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/internal/views/layout"
import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma" import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma"
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ About() { templ About(vm models.HomeAboutViewModel) {
@layout.WithTemplate(){ @layout.WithTemplate(vm.HeaderMetaTags){
@bulma.Title("About this project") @bulma.Title("About this project")
@bulma.Block() { @bulma.Block() {
Newsbot started a small project to send out notifications to discord servers. Newsbot started a small project to send out notifications to discord servers.

View File

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

View File

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

View File

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

View File

@ -1,18 +1,24 @@
package layout package layout
templ WithTemplate() { import (
"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"
)
templ WithTemplate(meta models.HeaderMetaTags) {
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@header() @header(meta)
</head> </head>
<body> <body>
@navBar() @navBar()
<br/> <br/>
<div class="container is-widescreen"> @bl.Container(bulma.BreakpointDefault) {
{ children... } { children... }
@footer() @footer()
</div> }
</body> </body>
</html> </html>
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,16 @@
package users package users
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" import (
import bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout" 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() { templ Logout() {
@layout.WithTemplate(){ @layout.WithTemplate(models.HeaderMetaTags{
@bl.Hero("You are out of here!", "Please login again when you are ready.") 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" "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma"
bh "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/html" bh "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/html"
bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout" 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" "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
) )
templ Profile() { templ Profile() {
@layout.WithTemplate() { @layout.WithTemplate(models.HeaderMetaTags{
Title: "Profile",
Type: "Page",
}) {
@bl.Hero("Profile", "Here you can update your profile 😀") @bl.Hero("Profile", "Here you can update your profile 😀")
@bulma.H2("Sessions", false) @bulma.H2("Sessions", false)
@bulma.Button() { @bulma.Button() {
@bh.ALink("/users/forcelogout", "Terminate all active sessions") @bh.ALink("/users/forcelogout", "Terminate all active sessions")

View File

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