Moved navigation to the left-side panel.

This commit is contained in:
mikestefanello 2021-12-27 10:09:46 -05:00
parent eafde27809
commit 0239f46247
6 changed files with 59 additions and 20 deletions

View File

@ -6,6 +6,7 @@ import (
"time"
"goweb/context"
"goweb/ent"
"goweb/htmx"
"goweb/msg"
@ -68,6 +69,9 @@ type Page struct {
// IsAuth stores whether or not the user is authenticated
IsAuth bool
// AuthUser stores the authenticated user
AuthUser *ent.User
// StatusCode stores the HTTP status code that will be returned
StatusCode int
@ -137,6 +141,7 @@ func NewPage(ctx echo.Context) Page {
if u := ctx.Get(context.AuthenticatedUserKey); u != nil {
p.IsAuth = true
p.AuthUser = u.(*ent.User)
}
p.HTMX.Request = htmx.GetRequest(ctx)

View File

@ -10,6 +10,7 @@ import (
echomw "github.com/labstack/echo/v4/middleware"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewPage(t *testing.T) {
@ -29,13 +30,16 @@ func TestNewPage(t *testing.T) {
assert.False(t, p.Cache.Enabled)
ctx, _ = tests.NewContext(c.Web, "/abc?def=123")
ctx.Set(context.AuthenticatedUserKey, 1)
usr, err := tests.CreateUser(c.ORM)
require.NoError(t, err)
ctx.Set(context.AuthenticatedUserKey, usr)
ctx.Set(echomw.DefaultCSRFConfig.ContextKey, "csrf")
p = NewPage(ctx)
assert.Equal(t, "/abc", p.Path)
assert.Equal(t, "/abc?def=123", p.URL)
assert.False(t, p.IsHome)
assert.True(t, p.IsAuth)
assert.Equal(t, usr, p.AuthUser)
assert.Equal(t, "csrf", p.CSRF)
}

View File

@ -43,6 +43,7 @@ func (User) Edges() []ent.Edge {
}
}
// Hooks of the User.
func (User) Hooks() []ent.Hook {
return []ent.Hook{
hook.On(

View File

@ -13,31 +13,48 @@
</div>
<div id="navbarMenu" class="navbar-menu">
<div class="navbar-end">
{{link (call .ToURL "home") "Home" .Path "navbar-item"}}
{{link (call .ToURL "about") "About" .Path "navbar-item"}}
{{link (call .ToURL "contact") "Contact" .Path "navbar-item"}}
{{- if .IsAuth}}
{{link (call .ToURL "logout") "Logout" .Path "navbar-item"}}
{{- else}}
{{link (call .ToURL "login") "Login" .Path "navbar-item"}}
{{- end}}
</div>
</div>
</div>
</nav>
<section class="section">
<div class="container">
<div class="box">
{{- if .Title}}
<h1 class="title">{{.Title}}</h1>
{{- end}}
<div class="container mt-5">
<div class="columns">
<div class="column is-2">
<aside class="menu" hx-boost="true">
<p class="menu-label">General</p>
<ul class="menu-list">
<li>{{link (call .ToURL "home") "Dashboard" .Path}}</li>
<li>{{link (call .ToURL "about") "About" .Path}}</li>
<li>{{link (call .ToURL "contact") "Contact" .Path}}</li>
</ul>
<p class="menu-label">Account</p>
<ul class="menu-list">
{{- if .IsAuth}}
<li>{{link (call .ToURL "logout") "Logout" .Path}}</li>
{{- else}}
<li>{{link (call .ToURL "login") "Login" .Path}}</li>
<li>{{link (call .ToURL "register") "Register" .Path}}</li>
<li>{{link (call .ToURL "forgot_password") "Forgot password" .Path}}</li>
{{- end}}
</ul>
</aside>
</div>
<div class="column is-10">
{{template "messages" .}}
{{template "content" .}}
<div class="box">
{{- if .Title}}
<h1 class="title">{{.Title}}</h1>
{{- end}}
{{template "content" .}}
</div>
</div>
</div>
</section>
</div>
{{template "footer" .}}
</body>

View File

@ -1,12 +1,12 @@
{{define "content"}}
<form method="post">
<form method="post" hx-boost="true" action="{{call .ToURL "forgot_password.post"}}">
<div class="content">
<p>Enter your email address and we'll email you a link that allows you to reset your password.</p>
</div>
<div class="field">
<label for="email" class="label">Email address</label>
<div class="control">
<input id="email" type="email" name="email" class="input {{.Form.Submission.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}" required>
<input id="email" type="email" name="email" class="input {{.Form.Submission.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}">
{{template "field-errors" (.Form.Submission.GetFieldErrors "Email")}}
</div>
</div>

View File

@ -11,6 +11,17 @@
{{end}}
{{define "top-content"}}
<section class="hero is-info welcome is-small">
<div class="hero-body">
<div class="container">
<h1 class="title">
Hello{{if .IsAuth}}, {{.AuthUser.Name}}{{end}}
</h1>
<h2 class="subtitle">Welcome back!</h2>
</div>
</div>
</section>
<section class="section">
<h1 class="title">Recent posts</h1>
<h2 class="subtitle">
@ -56,7 +67,8 @@
{{end}}
{{define "file-msg"}}
<article class="message is-small is-info mt-4" x-data="{show: true}" x-show="show">
<div class="block"></div>
<article class="message is-small is-warning" x-data="{show: true}" x-show="show">
<div class="message-header">
<p>Serving files</p>
<button class="delete is-small" aria-label="delete" @click="show = false"></button>