feat(ui): implement profile page

This commit is contained in:
Prad Nukala 2024-09-22 02:51:52 -04:00
parent df96e8d562
commit ee7c4531c2
31 changed files with 214 additions and 198 deletions

View File

@ -329,15 +329,6 @@ ipfs-cluster-start:
ipfs-cluster-service init --consensus crdt ipfs-cluster-service init --consensus crdt
ipfs-cluster-service daemon ipfs-cluster-service daemon
xcaddy:
@echo "(proxy) Starting caddy"
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
mkdir -p ./bin
xcaddy build --with github.com/caddy-dns/cloudflare
mv ./caddy ./bin/caddy
# ./bin/caddy adapt ./config/caddy/Caddyfile > ./config/caddy/caddy.json
./bin/caddy run --config ./config/caddy/caddy.json
############################################################################### ###############################################################################
### help ### ### help ###
############################################################################### ###############################################################################

View File

@ -1,9 +1,8 @@
{ {
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json", "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json",
"packages": [ "packages": [
"bun@latest",
"go@1.22", "go@1.22",
"gum@latest", "bun@latest",
"process-compose@latest" "process-compose@latest"
], ],
"env": { "env": {

View File

@ -0,0 +1 @@
package handlers

View File

@ -0,0 +1,23 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
templ Home(c echo.Context) {
@blocks.Card("home-view", blocks.SizeLarge) {
@blocks.H1("Sonr.ID")
@blocks.Text("A Decentralized Web Node Client for the Sonr Network.")
@blocks.Spacer()
<div class="flex flex-col gap-3">
@blocks.Button(blocks.GET("/register", "#home-view"), blocks.PrimaryButtonStyle()) {
@blocks.Text("Get Started")
}
@blocks.Button(blocks.GET("/login", "#home-view")) {
@blocks.Text("Login")
}
</div>
@blocks.PoweredBySonr()
}
}

View File

@ -1,7 +1,7 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.778 // templ: version: v0.2.778
package views package pages
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
@ -13,11 +13,7 @@ import (
"github.com/onsonr/sonr/pkg/nebula/blocks" "github.com/onsonr/sonr/pkg/nebula/blocks"
) )
func HomeView(c echo.Context) error { func Home(c echo.Context) templ.Component {
return echoComponentResponse(c, renderHomeView())
}
func renderHomeView() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {

View File

@ -0,0 +1,19 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
templ Login(c echo.Context) {
@blocks.Card("login-view", blocks.SizeLarge) {
@blocks.H1("Sonr.ID")
@blocks.Text("Neo-tree is a file manager for NeoFS.")
@blocks.Spacer()
@blocks.RadioGroup()
@blocks.Spacer()
@blocks.Button(blocks.GET("/", "#login-view")) {
@blocks.Text("Cancel")
}
}
}

View File

@ -1,7 +1,7 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.778 // templ: version: v0.2.778
package views package pages
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
@ -13,11 +13,7 @@ import (
"github.com/onsonr/sonr/pkg/nebula/blocks" "github.com/onsonr/sonr/pkg/nebula/blocks"
) )
func LoginView(c echo.Context) error { func Login(c echo.Context) templ.Component {
return echoComponentResponse(c, renderLoginView())
}
func renderLoginView() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {

View File

@ -0,0 +1,13 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
templ Authorize(c echo.Context) {
@blocks.Card("authorize-view", blocks.SizeMedium) {
@blocks.H1("Sonr.ID")
@blocks.Text("Neo-tree is a file manager for NeoFS.")
}
}

View File

@ -1,7 +1,7 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.778 // templ: version: v0.2.778
package views package pages
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
@ -13,11 +13,7 @@ import (
"github.com/onsonr/sonr/pkg/nebula/blocks" "github.com/onsonr/sonr/pkg/nebula/blocks"
) )
func AuthorizeView(c echo.Context) error { func Authorize(c echo.Context) templ.Component {
return echoComponentResponse(c, renderAuthorizeView())
}
func renderAuthorizeView() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {

View File

@ -0,0 +1,13 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
templ Profile(c echo.Context) {
@blocks.Card("profile-view", blocks.SizeLarge) {
@blocks.ProfileCard()
@blocks.Tabs()
}
}

View File

@ -1,7 +1,7 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.778 // templ: version: v0.2.778
package views package pages
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
@ -13,11 +13,7 @@ import (
"github.com/onsonr/sonr/pkg/nebula/blocks" "github.com/onsonr/sonr/pkg/nebula/blocks"
) )
func ProfileView(c echo.Context) error { func Profile(c echo.Context) templ.Component {
return echoComponentResponse(c, renderProfileView())
}
func renderProfileView() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {

View File

@ -0,0 +1,20 @@
package pages
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
"github.com/onsonr/sonr/pkg/nebula/islands"
)
templ Register(c echo.Context) {
@blocks.Card("register-view", blocks.SizeMedium) {
@blocks.H2("Account Registration")
@blocks.Spacer()
@blocks.Breadcrumbs()
@islands.BasicInfo(c, islands.InitialForm)
@blocks.Spacer()
@blocks.Button(blocks.GET("/", "#register-view")) {
@blocks.Text("Cancel")
}
}
}

View File

@ -1,7 +1,7 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.778 // templ: version: v0.2.778
package views package pages
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
@ -14,11 +14,7 @@ import (
"github.com/onsonr/sonr/pkg/nebula/islands" "github.com/onsonr/sonr/pkg/nebula/islands"
) )
func RegisterView(c echo.Context) error { func Register(c echo.Context) templ.Component {
return echoComponentResponse(c, renderRegisterView(c))
}
func renderRegisterView(c echo.Context) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {

View File

@ -2,13 +2,14 @@ package nebula
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/views" "github.com/onsonr/sonr/pkg/nebula/routes"
"github.com/onsonr/sonr/pkg/nebula/view"
) )
func RouteViews(e *echo.Echo) { func RouteViews(e *echo.Echo) {
e.GET("/home", views.HomeView) e.GET("/home", view.Render(routes.HomeRoute))
e.GET("/login", views.LoginView) e.GET("/login", view.Render(routes.LoginRoute))
e.GET("/register", views.RegisterView) e.GET("/register", view.Render(routes.RegisterRoute))
e.GET("/profile", views.ProfileView) e.GET("/profile", view.Render(routes.ProfileRoute))
e.GET("/authorize", views.AuthorizeView) e.GET("/authorize", view.Render(routes.AuthorizeRoute))
} }

View File

@ -0,0 +1,37 @@
package routes
import (
"github.com/a-h/templ"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/pages"
)
type Route string
const (
HomeRoute Route = "/home"
LoginRoute Route = "/login"
RegisterRoute Route = "/register"
ProfileRoute Route = "/profile"
AuthorizeRoute Route = "/authorize"
)
func (r Route) Route() string {
return string(r)
}
func (r Route) Component(c echo.Context) templ.Component {
switch r {
case HomeRoute:
return pages.Home(c)
case LoginRoute:
return pages.Login(c)
case RegisterRoute:
return pages.Register(c)
case ProfileRoute:
return pages.Profile(c)
case AuthorizeRoute:
return pages.Authorize(c)
}
return nil
}

29
pkg/nebula/view/view.go Normal file
View File

@ -0,0 +1,29 @@
package view
import (
"bytes"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/routes"
)
// render renders a templ.Component
func Render(r routes.Route) echo.HandlerFunc {
return func(c echo.Context) error {
// Create a buffer to store the rendered HTML
buf := bytes.NewBuffer(nil)
// Render the component to the buffer
err := r.Component(c).Render(c.Request().Context(), buf)
if err != nil {
return err
}
// Set the content type
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
// Write the buffered content to the response
_, err = c.Response().Write(buf.Bytes())
return err
}
}

View File

@ -1,27 +0,0 @@
package views
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
func HomeView(c echo.Context) error {
return echoComponentResponse(c, renderHomeView())
}
templ renderHomeView() {
@blocks.Card("home-view", blocks.SizeLarge) {
@blocks.H1("Sonr.ID")
@blocks.Text("A Decentralized Web Node Client for the Sonr Network.")
@blocks.Spacer()
<div class="flex flex-col gap-3">
@blocks.Button(blocks.GET("/register", "#home-view"), blocks.PrimaryButtonStyle()) {
@blocks.Text("Get Started")
}
@blocks.Button(blocks.GET("/login", "#home-view")) {
@blocks.Text("Login")
}
</div>
@blocks.PoweredBySonr()
}
}

View File

@ -1,24 +0,0 @@
package views
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
func LoginView(c echo.Context) error {
return echoComponentResponse(c, renderLoginView())
}
templ renderLoginView() {
@blocks.Card("login-view", blocks.SizeLarge) {
@blocks.H1("Sonr.ID")
@blocks.Text("Neo-tree is a file manager for NeoFS.")
@blocks.Spacer()
@blocks.RadioGroup()
@blocks.Spacer()
@blocks.Button(blocks.GET("/", "#login-view")) {
@blocks.Text("Cancel")
}
}
}

View File

@ -1,18 +0,0 @@
package views
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
func AuthorizeView(c echo.Context) error {
return echoComponentResponse(c, renderAuthorizeView())
}
templ renderAuthorizeView() {
@blocks.Card("authorize-view", blocks.SizeMedium) {
@blocks.H1("Sonr.ID")
@blocks.Text("Neo-tree is a file manager for NeoFS.")
}
}

View File

@ -1,18 +0,0 @@
package views
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
)
func ProfileView(c echo.Context) error {
return echoComponentResponse(c, renderProfileView())
}
templ renderProfileView() {
@blocks.Card("profile-view", blocks.SizeLarge) {
@blocks.ProfileCard()
@blocks.Tabs()
}
}

View File

@ -1,24 +0,0 @@
package views
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/blocks"
"github.com/onsonr/sonr/pkg/nebula/islands"
)
func RegisterView(c echo.Context) error {
return echoComponentResponse(c, renderRegisterView(c))
}
templ renderRegisterView(c echo.Context) {
@blocks.Card("register-view", blocks.SizeMedium) {
@blocks.H2("Account Registration")
@blocks.Spacer()
@blocks.Breadcrumbs()
@islands.BasicInfo(c, islands.InitialForm)
@blocks.Spacer()
@blocks.Button(blocks.GET("/", "#register-view")) {
@blocks.Text("Cancel")
}
}
}

View File

@ -1,27 +0,0 @@
package views
import (
"bytes"
"github.com/a-h/templ"
"github.com/labstack/echo/v4"
)
// render renders a templ.Component
func echoComponentResponse(c echo.Context, cmp templ.Component) error {
// Create a buffer to store the rendered HTML
buf := &bytes.Buffer{}
// Render the component to the buffer
err := cmp.Render(c.Request().Context(), buf)
if err != nil {
return err
}
// Set the content type
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
// Write the buffered content to the response
_, err = c.Response().Write(buf.Bytes())
return err
}

View File

@ -4,7 +4,7 @@ package main
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/onsonr/sonr/web/src/pages" "github.com/onsonr/sonr/pkg/proxy/routes"
"github.com/syumai/workers" "github.com/syumai/workers"
) )
@ -16,8 +16,8 @@ func main() {
// 1. Display Generic Homepage // 1. Display Generic Homepage
e := echo.New() e := echo.New()
// Configure the server // Configure the server
e.GET("/", pages.HomeView) e.GET("/", routes.HomeView)
e.GET("/allocate", pages.AllocateView) e.GET("/allocate", routes.AllocateView)
// 2. Present Terms Agreement and Checkbox to Accept // 2. Present Terms Agreement and Checkbox to Accept
// 3. Collect UserAgent, Set-Cookie, and Client Headers // 3. Collect UserAgent, Set-Cookie, and Client Headers
// 4. Redirect to DWN Node // 4. Redirect to DWN Node

View File

@ -1,4 +1,4 @@
package pages package routes
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"

View File

@ -1,7 +1,7 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.778 // templ: version: v0.2.778
package pages package routes
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.

View File

@ -1,4 +1,4 @@
package pages package routes
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"

View File

@ -1,7 +1,7 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.778 // templ: version: v0.2.778
package pages package routes
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.

View File

@ -1,4 +1,4 @@
package pages package routes
import ( import (
"bytes" "bytes"

View File

@ -106,10 +106,39 @@ func indexFile(cfg string) templ.Component {
}) })
} }
func serviceWorker() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var4 := templ.GetChildren(ctx)
if templ_7745c5c3_Var4 == nil {
templ_7745c5c3_Var4 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script>\n</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return templ_7745c5c3_Err
})
}
func initializeMotr(config string) templ.ComponentScript { func initializeMotr(config string) templ.ComponentScript {
return templ.ComponentScript{ return templ.ComponentScript{
Name: `__templ_initializeMotr_4943`, Name: `__templ_initializeMotr_d70f`,
Function: `function __templ_initializeMotr_4943(config){const motr = new Motr(JSON.parse(config)); Function: `function __templ_initializeMotr_d70f(config){const motr = new Motr(JSON.parse(config));
async function demo() { async function demo() {
try { try {
@ -157,12 +186,11 @@ func initializeMotr(config string) templ.ComponentScript {
document.getElementById('output').innerHTML = ` + "`" + `<p>Error: ${error.message}</p>` + "`" + `; document.getElementById('output').innerHTML = ` + "`" + `<p>Error: ${error.message}</p>` + "`" + `;
} }
} }
// Run the demo when the page loads // Run the demo when the page loads
window.onload = demo; window.onload = demo;
}`, }`,
Call: templ.SafeScript(`__templ_initializeMotr_4943`, config), Call: templ.SafeScript(`__templ_initializeMotr_d70f`, config),
CallInline: templ.SafeScriptInline(`__templ_initializeMotr_4943`, config), CallInline: templ.SafeScriptInline(`__templ_initializeMotr_d70f`, config),
} }
} }