Compare commits
3 Commits
8d83d6f545
...
5a950af7a1
Author | SHA1 | Date | |
---|---|---|---|
5a950af7a1 | |||
97c08947a9 | |||
2810aa9de0 |
@ -3,7 +3,6 @@ package handlers
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
||||
@ -76,39 +75,6 @@ func NewServer(ctx context.Context, configs config.Configs, apiClient apiclient.
|
||||
return s
|
||||
}
|
||||
|
||||
// This custom Render replaces Echo's echo.Context.Render() with templ's templ.Component.Render().
|
||||
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
|
||||
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
||||
ctx.Response().Writer.WriteHeader(statusCode)
|
||||
return t.Render(ctx.Request().Context(), ctx.Response().Writer)
|
||||
}
|
||||
|
||||
/*
|
||||
func (s *Handler) WriteError(c echo.Context, errMessage error, HttpStatusCode int) error {
|
||||
return c.JSON(HttpStatusCode, domain.BaseResponse{
|
||||
Message: errMessage.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Handler) WriteMessage(c echo.Context, msg string, HttpStatusCode int) error {
|
||||
return c.JSON(HttpStatusCode, domain.BaseResponse{
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Handler) InternalServerErrorResponse(c echo.Context, msg string) error {
|
||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Handler) UnauthorizedResponse(c echo.Context, msg string) error {
|
||||
return c.JSON(http.StatusUnauthorized, domain.BaseResponse{
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
// If the token is not valid then an json error will be returned.
|
||||
// If the token has the wrong scope, a json error will be returned.
|
||||
// If the token passes all the checks, it is valid and is returned back to the caller.
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.jamestombleson.com/jtom38/newsbot-portal/internal/domain"
|
||||
"github.com/a-h/templ"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -60,3 +61,18 @@ func ValidateJwt(ctx echo.Context, sharedSecret, issuer string) (jwtToken, error
|
||||
|
||||
return *claims, nil
|
||||
}
|
||||
|
||||
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
|
||||
ctx.Response().Writer.WriteHeader(statusCode)
|
||||
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
||||
|
||||
// take the request context and make it a var
|
||||
request := ctx.Request().Context()
|
||||
//Check to see if we the echo context has the cookie we are looking for, if so, create a new context based on what we had and add the value
|
||||
//darkMode, err := ctx.Cookie(domain.CookieSettingsDarkMode)
|
||||
//if err == nil {
|
||||
// request = context.WithValue(request, domain.CookieSettingsDarkMode, darkMode.Value)
|
||||
//}
|
||||
|
||||
return t.Render(request, ctx.Response().Writer)
|
||||
}
|
||||
|
31
internal/views/articles/filter.templ
Normal file
31
internal/views/articles/filter.templ
Normal file
@ -0,0 +1,31 @@
|
||||
package articles
|
||||
|
||||
templ filterBar() {
|
||||
<!-- Main container -->
|
||||
<nav class="level">
|
||||
<!-- Left side -->
|
||||
<div class="level-left">
|
||||
<div class="level-item">
|
||||
<p class="subtitle is-5"><strong>123</strong> posts</p>
|
||||
</div>
|
||||
<div class="level-item">
|
||||
<div class="field has-addons">
|
||||
<p class="control">
|
||||
<input class="input" type="text" placeholder="Find a post"/>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button class="button">Search</button>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Right side -->
|
||||
<div class="level-right">
|
||||
<p class="level-item"><strong>All</strong></p>
|
||||
<p class="level-item"><a>Published</a></p>
|
||||
<p class="level-item"><a>Drafts</a></p>
|
||||
<p class="level-item"><a>Deleted</a></p>
|
||||
<p class="level-item"><a class="button is-success">New</a></p>
|
||||
</div>
|
||||
</nav>
|
||||
}
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
templ List(model models.ListArticlesViewModel) {
|
||||
@layout.WithTemplate() {
|
||||
@filterBar()
|
||||
for _, item := range model.Items {
|
||||
<div class="card">
|
||||
<div class="card-image">
|
||||
|
@ -18,7 +18,7 @@ templ navBar() {
|
||||
</div>
|
||||
<div id="navbarBasicExample" class="navbar-menu">
|
||||
<div class="navbar-start">
|
||||
<a class="navbar-item" href="articles">Articles</a>
|
||||
<a class="navbar-item" href="/articles">Articles</a>
|
||||
<a class="navbar-item">Documentation</a>
|
||||
<!--
|
||||
<div class="navbar-item has-dropdown is-hoverable">
|
||||
|
@ -8,6 +8,7 @@ templ WithTemplate() {
|
||||
</head>
|
||||
<body>
|
||||
@navBar()
|
||||
<br/>
|
||||
<div class="container is-widescreen">
|
||||
{ children... }
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user