Skip to content

Commit

Permalink
refactor: clean up components
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Aug 16, 2024
1 parent eba0d39 commit 97160bf
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 151 deletions.
7 changes: 6 additions & 1 deletion internal/web/components/default-layout.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package components

import htmx "github.com/zeiss/fiber-htmx"
import (
"github.com/zeiss/fiber-goth/adapters"
htmx "github.com/zeiss/fiber-htmx"
)

// DefaultLayoutProps ...
type DefaultLayoutProps struct {
ClassNames htmx.ClassNames
User adapters.GothUser
Path string
Title string
}
Expand All @@ -18,6 +22,7 @@ func DefaultLayout(props DefaultLayoutProps, node htmx.ErrBoundaryFunc) htmx.Nod
Layout(
LayoutProps{
Path: props.Path,
User: props.User,
},
htmx.Fallback(
htmx.ErrorBoundary(node),
Expand Down
41 changes: 3 additions & 38 deletions internal/web/components/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package components
import (
"github.com/zeiss/fiber-goth/adapters"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/buttons"
"github.com/zeiss/fiber-htmx/components/dividers"
"github.com/zeiss/fiber-htmx/components/drawers"
"github.com/zeiss/fiber-htmx/components/icons"
"github.com/zeiss/fiber-htmx/components/navbars"
"github.com/zeiss/fiber-htmx/components/swap"
"github.com/zeiss/fiber-htmx/components/toasts"
)

Expand Down Expand Up @@ -102,38 +100,10 @@ func Layout(p LayoutProps, children ...htmx.Node) htmx.Node {
),
navbars.NavbarEnd(
navbars.NavbarEndProps{},
swap.Swap(
swap.SwapProps{
ClassNames: htmx.ClassNames{
"swap-rotate": true,
},
},
htmx.Input(
htmx.Class("theme-controller"),
htmx.Value("dark"),
htmx.Attribute("type", "checkbox"),
),
swap.SwapOn(
swap.SwapProps{},
icons.MoonOutlineSmall(
icons.IconProps{},
),
),
swap.SwapOff(
swap.SwapProps{},
icons.SunOutlineSmall(
icons.IconProps{},
),
),
),
buttons.CircleSmall(
buttons.ButtonProps{},
icons.BellAlertOutlineSmall(
icons.IconProps{},
),
),
ProfileMenu(
ProfileMenuProps{},
ProfileMenuProps{
User: p.User,
},
),
),
),
Expand All @@ -155,11 +125,6 @@ func Layout(p LayoutProps, children ...htmx.Node) htmx.Node {
"bg-base-200": false,
},
},
// AccountSwitch(
// AccountSwitchProps{
// User: p.User,
// },
// ),
dividers.Divider(
dividers.DividerProps{},
),
Expand Down
9 changes: 8 additions & 1 deletion internal/web/components/profile-menu.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package components

import (
"github.com/zeiss/fiber-goth/adapters"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/avatars"
"github.com/zeiss/fiber-htmx/components/dropdowns"
"github.com/zeiss/pkg/cast"
)

// ProfileMenuProps ...
type ProfileMenuProps struct {
ClassNames htmx.ClassNames
User adapters.GothUser
}

// ProfileMenu ...
Expand All @@ -33,7 +36,7 @@ func ProfileMenu(p ProfileMenuProps, children ...htmx.Node) htmx.Node {
avatars.AvatarRoundSmall(
avatars.AvatarProps{},
htmx.Img(
htmx.Attribute("src", "https://avatars.githubusercontent.com/u/570959?v=4"),
htmx.Attribute("src", cast.Value(p.User.Image)),
),
),
),
Expand All @@ -45,6 +48,10 @@ func ProfileMenu(p ProfileMenuProps, children ...htmx.Node) htmx.Node {
htmx.Attribute("href", "/me"),
htmx.Text("Profile"),
),
htmx.A(
htmx.Attribute("href", "/logout"),
htmx.Text("Logout"),
),
),
),
)
Expand Down
1 change: 1 addition & 0 deletions internal/web/controllers/accounts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (l *ListAccountsController) Get() error {
components.DefaultLayoutProps{
Title: "Accounts",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
return cards.CardBordered(
Expand Down
43 changes: 1 addition & 42 deletions internal/web/controllers/accounts/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (l *NewAccountControllerImpl) Get() error {
components.DefaultLayoutProps{
Title: "New Account",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
teams := tables.Results[models.Team]{}
Expand Down Expand Up @@ -500,48 +501,6 @@ func (l *NewAccountControllerImpl) Get() error {
),
),
),
cards.CardBordered(
cards.CardProps{
ClassNames: htmx.ClassNames{
tailwind.M2: true,
},
},
cards.Body(
cards.BodyProps{},
cards.Title(
cards.TitleProps{},
htmx.Text("Account Server"),
),
forms.FormControl(
forms.FormControlProps{},
forms.TextInputBordered(
forms.TextInputProps{
Name: "account_server_url",
Placeholder: "https://example.com:8080",
},
),
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
},
htmx.Text("A valid URL with a scheme of http or https. Certificates need be valid."),
),
),
),
cards.Actions(
cards.ActionsProps{},
buttons.Button(
buttons.ButtonProps{},
htmx.Attribute("type", "submit"),
htmx.Text("Create Operator"),
),
),
),
),
cards.CardBordered(
cards.CardProps{
ClassNames: htmx.ClassNames{
Expand Down
1 change: 1 addition & 0 deletions internal/web/controllers/accounts/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (l *ShowAccountControllerImpl) Get() error {
components.DefaultLayoutProps{
Title: "Account",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
var params struct {
Expand Down
1 change: 1 addition & 0 deletions internal/web/controllers/dashboard/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (l *IndexDashboardController) Get() error {
components.DefaultLayoutProps{
Title: "Dashboard",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
return cards.CardBordered(
Expand Down
7 changes: 3 additions & 4 deletions internal/web/controllers/login/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ func (l *IndexLoginController) Get() error {
links.Button(
links.LinkProps{
ClassNames: htmx.ClassNames{
"w-full": true,
"btn-primary": true,
"btn-outline": true,
"w-full": true,
"btn": true,
},
Href: "/login/github",
},
Expand Down Expand Up @@ -121,7 +120,7 @@ func (l *IndexLoginController) Get() error {
"-mb-4": true,
},
},
buttons.OutlinePrimary(
buttons.Button(
buttons.ButtonProps{
ClassNames: htmx.ClassNames{
"w-full": true,
Expand Down
24 changes: 5 additions & 19 deletions internal/web/controllers/me/index.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me

import (
"context"

"github.com/zeiss/fiber-goth/adapters"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/buttons"
"github.com/zeiss/fiber-htmx/components/cards"
Expand All @@ -14,26 +11,13 @@ import (

// MeController ...
type MeController struct {
User adapters.GothUser

store ports.Datastore
htmx.DefaultController
}

// NewMeIndexController ...
func NewMeController(store ports.Datastore) *MeController {
return &MeController{
User: adapters.GothUser{},
store: store,
DefaultController: htmx.DefaultController{},
}
}

// Prepare ...
func (m *MeController) Prepare() error {
return m.store.ReadTx(m.Context(), func(ctx context.Context, tx ports.ReadTx) error {
return tx.GetProfile(ctx, &m.User)
})
return &MeController{store: store}
}

// Get ...
Expand All @@ -42,6 +26,8 @@ func (m *MeController) Get() error {
components.DefaultLayout(
components.DefaultLayoutProps{
Title: "Profile",
Path: m.Path(),
User: m.Session().User,
},
func() htmx.Node {
return cards.CardBordered(
Expand Down Expand Up @@ -71,7 +57,7 @@ func (m *MeController) Get() error {
forms.TextInputBordered(
forms.TextInputProps{
Name: "username",
Value: m.User.Name,
Value: m.Session().User.Name,
Disabled: true,
},
),
Expand Down Expand Up @@ -99,7 +85,7 @@ func (m *MeController) Get() error {
forms.TextInputBordered(
forms.TextInputProps{
Name: "email",
Value: m.User.Email,
Value: m.Session().User.Email,
Disabled: true,
},
),
Expand Down
45 changes: 23 additions & 22 deletions internal/web/controllers/operators/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,34 @@ func (l *ListOperatorsController) Prepare() error {
// Prepare ...
func (l *ListOperatorsController) Get() error {
return l.Render(
components.Page(
components.PageProps{
components.DefaultLayout(
components.DefaultLayoutProps{
Title: "Operators",
Path: l.Path(),
User: l.Session().User,
},
components.Layout(
components.LayoutProps{
Path: l.Ctx().Path(),
},
cards.CardBordered(
cards.CardProps{
ClassNames: htmx.ClassNames{
tailwind.M2: true,
},
},
cards.Body(
cards.BodyProps{},
operators.OperatorsTable(
operators.OperatorsTableProps{
Operators: l.Results.GetRows(),
Offset: l.Results.GetOffset(),
Limit: l.Results.GetLimit(),
Total: l.Results.GetLen(),
func() htmx.Node {
return htmx.Fragment(
cards.CardBordered(
cards.CardProps{
ClassNames: htmx.ClassNames{
tailwind.M2: true,
},
},
cards.Body(
cards.BodyProps{},
operators.OperatorsTable(
operators.OperatorsTableProps{
Operators: l.Results.GetRows(),
Offset: l.Results.GetOffset(),
Limit: l.Results.GetLimit(),
Total: l.Results.GetLen(),
},
),
),
),
),
),
)
},
),
)
}
1 change: 1 addition & 0 deletions internal/web/controllers/operators/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (l *NewOperatorControllerImpl) Get() error {
components.DefaultLayoutProps{
Title: "New Operator",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
return htmx.FormElement(
Expand Down
2 changes: 2 additions & 0 deletions internal/web/controllers/operators/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func (l *ShowOperatorControllerImpl) Get() error {
components.DefaultLayout(
components.DefaultLayoutProps{
Title: "Operator",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
err := l.BindParams(l)
Expand Down
1 change: 1 addition & 0 deletions internal/web/controllers/systems/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (l *ListSystemsController) Get() error {
components.DefaultLayoutProps{
Title: "Systems",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
return cards.CardBordered(
Expand Down
1 change: 1 addition & 0 deletions internal/web/controllers/systems/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (l *NewSystemControllerImpl) Get() error {
components.DefaultLayoutProps{
Title: "New System",
Path: l.Path(),
User: l.Session().User,
},
func() htmx.Node {
return htmx.FormElement(
Expand Down
Loading

0 comments on commit 97160bf

Please sign in to comment.