Skip to content

Commit

Permalink
add top nav
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfaerman committed Jan 31, 2024
1 parent 54f18b6 commit c9a3098
Show file tree
Hide file tree
Showing 21 changed files with 909 additions and 1,175 deletions.
2 changes: 1 addition & 1 deletion internal/dao/events.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions internal/handlers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

validator "github.com/go-playground/validator/v10"
"github.com/ryanfaerman/netctl/internal/middleware"
"github.com/ryanfaerman/netctl/internal/models"
"github.com/ryanfaerman/netctl/internal/services"
"github.com/ryanfaerman/netctl/internal/views"
"github.com/ryanfaerman/netctl/web/named"
Expand All @@ -29,6 +30,7 @@ func (h account) Routes(r chi.Router) {
})

r.Get(named.Route("account-profile", "/profile/{callsign}"), h.Show)
r.Get(named.Route("account-profile-self", "/profile"), h.Show)
r.Get(named.Route("account-edit", "/profile/{callsign}/edit"), h.Edit)
r.Post(named.Route("account-edit-save", "/profile/{callsign}/edit/-/save"), h.Update)
}
Expand Down Expand Up @@ -87,19 +89,32 @@ func (h account) Setup(w http.ResponseWriter, r *http.Request) {
}

func (h account) Show(w http.ResponseWriter, r *http.Request) {
var account *models.Account

callsign := chi.URLParam(r, "callsign")
ctx := services.CSRF.GetContext(r.Context(), r)
if callsign == "" {
a, err := services.Session.GetAccount(r.Context())
if err != nil {
ErrorHandler(err)(w, r)
return
}
account = a
// get account from session
} else {
a, err := services.Account.FindByCallsign(r.Context(), callsign)
if err != nil {
ErrorHandler(err)(w, r)
return
}
account = a

a, err := services.Account.FindByCallsign(ctx, callsign)
if err != nil {
ErrorHandler(err)(w, r)
return
}
ctx := services.CSRF.GetContext(r.Context(), r)

a.About = services.Markdown.MustRenderString(a.About)
account.About = services.Markdown.MustRenderString(account.About)

v := views.Account{
Account: a,
Account: account,
}
v.Profile().Render(ctx, w)
}
Expand Down
19 changes: 19 additions & 0 deletions internal/middleware/path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package middleware

import (
"fmt"
"net/http"

"github.com/davecgh/go-spew/spew"
"github.com/go-chi/chi"
"github.com/ryanfaerman/netctl/web/named"
)

func Path(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c := chi.RouteContext(r.Context())
spew.Dump(c.RoutePattern(), c.URLParams)
fmt.Println("lookup", named.Lookup(c.RoutePattern()))
next.ServeHTTP(w, r)
})
}
7 changes: 1 addition & 6 deletions internal/services/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"net/http"

"github.com/davecgh/go-spew/spew"
"github.com/mrz1836/postmark"
"github.com/ryanfaerman/netctl/config"
"github.com/ryanfaerman/netctl/internal/models"
Expand Down Expand Up @@ -137,9 +136,7 @@ func (session) Destroy(ctx context.Context) error {
return nil
}

var (
ErrNoAccountInSession = errors.New("no account in session")
)
var ErrNoAccountInSession = errors.New("no account in session")

func (session) GetAccount(ctx context.Context) (*models.Account, error) {
id, ok := global.session.Get(ctx, "account_id").(int64)
Expand All @@ -154,7 +151,5 @@ func (s session) MustGetAccount(ctx context.Context) *models.Account {
if err != nil {
panic(err)
}
spew.Dump(u)
spew.Dump(u.Ready())
return u
}
2 changes: 1 addition & 1 deletion internal/sql/queries/events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ DELETE FROM events_recovery WHERE id = ?1;
-- name: GetEventsForCallsign :many
SELECT *
FROM events
WHERE event_type = ?1
WHERE event_type = ?1
AND json_extract(event_data, '$.callsign') = @callsign;
68 changes: 11 additions & 57 deletions internal/views/account.templ
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ type Account struct {
Account *models.Account
}

func (v Account) Nav() Menu {
return Menu{
{Value: "Profile", URL: named.URLFor("account-profile", v.Account.Callsign().Call), Icon: IconAttrs{Name: "file-lines"}},
{Value: "Billing", URL: "#", Icon: IconAttrs{Name: "list-check"}},
{Value: "Reports", URL: "#", Icon: IconAttrs{Name: "receipt"}},
{Value: "Settings", URL: "#", Icon: IconAttrs{Name: "sliders"}},
}
}

templ (v Account) Profile() {
@Page() {
<header class="app-header">
@v.LocalBar()
</header>
@Page(v.Nav()) {
<div class="grid-container split">
<div>
<h1>{ v.Account.Name }</h1>
Expand All @@ -28,10 +34,7 @@ templ (v Account) Profile() {
}

templ (v Account) Edit() {
@Page() {
<header class="app-header">
@v.LocalBar()
</header>
@Page(v.Nav()) {
<div class="grid-container split">
<div>
"Editing { v.Account.Name }!"
Expand Down Expand Up @@ -90,52 +93,3 @@ templ (v Account) EditFormWithErrors(input AccountEditFormInput, inputErrs Accou
})
}
}

templ (v Account) LocalBar() {
<div class="local-bar">
<nav>
<ul>
<li class="app-name">
<a href="/">
@Icon("tower-cell")
Net Control
</a>
</li>
<li>
<a href="#" class="tab">
@Icon("file-lines")
Preamble
</a>
</li>
<li>
<a href="#" class="tab active">
@Icon("list-check")
Check Ins
</a>
</li>
<li>
<a href="#" class="tab">
@Icon("receipt")
Reports
</a>
</li>
<li>
<a href="#" class="tab">
@Icon("sliders")
Settings
</a>
</li>
</ul>
</nav>
<nav>
<ul>
<li>
<a href="#" class="tab">
@Icon("user")
Account
</a>
</li>
</ul>
</nav>
</div>
}
139 changes: 15 additions & 124 deletions internal/views/account_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c9a3098

Please sign in to comment.