Added account page with subpage select
This commit is contained in:
25
handlers/account.go
Normal file
25
handlers/account.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"projectreshoot/view/component/account"
|
||||||
|
"projectreshoot/view/page"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleAccountPage() http.Handler {
|
||||||
|
return http.HandlerFunc(
|
||||||
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
page.Account("General").Render(r.Context(), w)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleAccountSubpage() http.Handler {
|
||||||
|
return http.HandlerFunc(
|
||||||
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
r.ParseForm()
|
||||||
|
subpage := r.FormValue("subpage")
|
||||||
|
account.AccountContent(subpage).Render(r.Context(), w)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"projectreshoot/view/page"
|
"projectreshoot/view/page"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleProfile() http.Handler {
|
func HandleProfilePage() http.Handler {
|
||||||
return http.HandlerFunc(
|
return http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
page.Profile().Render(r.Context(), w)
|
page.Profile().Render(r.Context(), w)
|
||||||
|
|||||||
@@ -63,6 +63,16 @@ func addRoutes(
|
|||||||
// Profile page
|
// Profile page
|
||||||
mux.Handle("GET /profile",
|
mux.Handle("GET /profile",
|
||||||
middleware.RequiresLogin(
|
middleware.RequiresLogin(
|
||||||
handlers.HandleProfile(),
|
handlers.HandleProfilePage(),
|
||||||
|
))
|
||||||
|
|
||||||
|
// Account page
|
||||||
|
mux.Handle("GET /account",
|
||||||
|
middleware.RequiresLogin(
|
||||||
|
handlers.HandleAccountPage(),
|
||||||
|
))
|
||||||
|
mux.Handle("POST /account-select-page",
|
||||||
|
middleware.RequiresLogin(
|
||||||
|
handlers.HandleAccountSubpage(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
15
view/component/account/content.templ
Normal file
15
view/component/account/content.templ
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
templ AccountContent(subpage string) {
|
||||||
|
<form hx-post="/account-select-page">
|
||||||
|
<div class="flex max-w-200 min-h-100 mx-auto bg-mantle mt-10 rounded-xl">
|
||||||
|
@SelectMenu(subpage)
|
||||||
|
<div class="mt-5">
|
||||||
|
<div class="pl-10 text-2xl text-subtext1 underline">
|
||||||
|
{ subpage }
|
||||||
|
</div>
|
||||||
|
// page content
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
55
view/component/account/selectmenu.templ
Normal file
55
view/component/account/selectmenu.templ
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type MenuItem struct {
|
||||||
|
name string
|
||||||
|
href string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMenuItems() []MenuItem {
|
||||||
|
return []MenuItem{
|
||||||
|
{
|
||||||
|
name: "General",
|
||||||
|
href: "general",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Security",
|
||||||
|
href: "security",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Preferences",
|
||||||
|
href: "preferences",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templ SelectMenu(activePage string) {
|
||||||
|
{{
|
||||||
|
menuItems := getMenuItems()
|
||||||
|
page := fmt.Sprintf("{page:'%s'}", activePage)
|
||||||
|
}}
|
||||||
|
<div class="flex w-fit flex-col border-e bg-surface0 rounded-l-xl">
|
||||||
|
<div class="px-4 py-6">
|
||||||
|
<ul class="mt-6 space-y-1" x-data={ page }>
|
||||||
|
for _, item := range menuItems {
|
||||||
|
{{
|
||||||
|
activebind := fmt.Sprintf("page === '%s' && 'bg-mantle'", item.name)
|
||||||
|
}}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
name="subpage"
|
||||||
|
value={ item.name }
|
||||||
|
class="block rounded-lg px-4 py-2 text-md
|
||||||
|
hover:bg-mantle hover:cursor-pointer"
|
||||||
|
:class={ activebind }
|
||||||
|
>
|
||||||
|
{ item.name }
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
10
view/page/account.templ
Normal file
10
view/page/account.templ
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package page
|
||||||
|
|
||||||
|
import "projectreshoot/view/layout"
|
||||||
|
import "projectreshoot/view/component/account"
|
||||||
|
|
||||||
|
templ Account(subpage string) {
|
||||||
|
@layout.Global() {
|
||||||
|
@account.AccountContent(subpage)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user