Request object
This commit is contained in:
45
app/data/users.go
Normal file
45
app/data/users.go
Normal file
@ -0,0 +1,45 @@
|
||||
package data
|
||||
|
||||
import "fiber-sessions/app/types"
|
||||
|
||||
var dbUsers map[string]types.User = map[string]types.User{
|
||||
"pero-uuid": {
|
||||
Id: "pero-uuid",
|
||||
Username: "pero",
|
||||
Password: "pero",
|
||||
FirstName: "Pero",
|
||||
LastName: "Perić",
|
||||
},
|
||||
"mirko-uuid": {
|
||||
Id: "mirko-uuid",
|
||||
Username: "mirko",
|
||||
Password: "mirko",
|
||||
FirstName: "Mirko",
|
||||
LastName: "Mirković",
|
||||
},
|
||||
}
|
||||
|
||||
type usersStorage struct {
|
||||
}
|
||||
|
||||
var UsersStorage = usersStorage{}
|
||||
|
||||
func (u usersStorage) GetUserById(id string) *types.User {
|
||||
user, ok := dbUsers[id]
|
||||
if ok {
|
||||
return &user
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u usersStorage) AuthUser(ident string, password string) *types.User {
|
||||
for _, user := range dbUsers {
|
||||
if user.Username == ident {
|
||||
if user.Password == password {
|
||||
return &user
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -1,20 +1,20 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/handlers/usersession"
|
||||
"fiber-sessions/app/data"
|
||||
"fiber-sessions/app/router/requests"
|
||||
"fiber-sessions/app/templates"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Home(ctx *fiber.Ctx) error {
|
||||
requestSession := usersession.NewRequestSession(ctx)
|
||||
request := requests.NewRequest(ctx, data.UsersStorage)
|
||||
|
||||
pc := templates.PageContext{
|
||||
Title: "Welcome to the demo",
|
||||
ActivePage: "home",
|
||||
RequestSession: requestSession,
|
||||
Title: "Welcome to the demo",
|
||||
ActivePage: "home",
|
||||
}
|
||||
Render(ctx, templates.Home(pc))
|
||||
Render(ctx, templates.Home(request, pc))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1,91 +0,0 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/data"
|
||||
"fiber-sessions/app/templates"
|
||||
"fiber-sessions/app/types"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
var pcInteractive templates.PageContext = templates.PageContext{
|
||||
Title: "Welcome to the demo - Interactive",
|
||||
ActivePage: "interactive",
|
||||
}
|
||||
|
||||
func Interactive(f *fiber.Ctx) error {
|
||||
Render(f, templates.Interactive(pcInteractive, data.CatBreeds))
|
||||
return nil
|
||||
}
|
||||
|
||||
func InteractiveSwapContent(f *fiber.Ctx) error {
|
||||
contentIndexStr := f.Query("content")
|
||||
contentIndex, err := strconv.Atoi(contentIndexStr)
|
||||
if err != nil {
|
||||
contentIndex = 0
|
||||
}
|
||||
Render(f, templates.InteractiveSwapContent(pcInteractive, contentIndex))
|
||||
return nil
|
||||
}
|
||||
|
||||
func FilterCatBreeds(f *fiber.Ctx) error {
|
||||
breedQuery := strings.ToLower(f.Query("breed"))
|
||||
countryQuery := f.Query("country")
|
||||
|
||||
var catBreeds []types.CatBreed = []types.CatBreed{}
|
||||
|
||||
for _, cb := range data.CatBreeds {
|
||||
appendToList :=
|
||||
(len(breedQuery) > 0 &&
|
||||
strings.Contains(strings.ToLower(cb.Breed), breedQuery) ||
|
||||
len(breedQuery) == 0) &&
|
||||
((len(countryQuery) > 0 &&
|
||||
cb.Country == countryQuery) ||
|
||||
len(countryQuery) == 0)
|
||||
|
||||
if appendToList {
|
||||
catBreeds = append(catBreeds, cb)
|
||||
}
|
||||
}
|
||||
|
||||
Render(f, templates.RenderCatBreedsTable(catBreeds))
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateForm(f *fiber.Ctx) error {
|
||||
content := templates.ValidateFormContent{
|
||||
Validated: true,
|
||||
NumValue: f.FormValue("number-value"),
|
||||
StrValue: f.FormValue("string-value"),
|
||||
}
|
||||
|
||||
numValue, err := strconv.Atoi(content.NumValue)
|
||||
if err != nil {
|
||||
content.HasNumValueError = true
|
||||
content.NumValueError = "This is not valid number"
|
||||
}
|
||||
if !content.HasNumValueError {
|
||||
if numValue < 0 {
|
||||
content.HasNumValueError = true
|
||||
content.NumValueError = "Value is less than 0"
|
||||
}
|
||||
if numValue > 100 {
|
||||
content.HasNumValueError = true
|
||||
content.NumValueError = "Value is greater than 100"
|
||||
}
|
||||
}
|
||||
|
||||
if len(content.StrValue) < 5 {
|
||||
content.HasStrValueError = true
|
||||
content.StrValueError = "String length is less than 5"
|
||||
}
|
||||
if len(content.StrValue) > 10 {
|
||||
content.HasStrValueError = true
|
||||
content.StrValueError = "String length is more than 10"
|
||||
}
|
||||
|
||||
Render(f, templates.RenderInteractiveForm(content))
|
||||
return nil
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/handlers/usersession"
|
||||
"fiber-sessions/app/data"
|
||||
"fiber-sessions/app/router/requests"
|
||||
"fiber-sessions/app/templates"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@ -13,13 +14,13 @@ var pcLogin templates.PageContext = templates.PageContext{
|
||||
}
|
||||
|
||||
func Login(ctx *fiber.Ctx) error {
|
||||
pcLogin.RequestSession = usersession.NewRequestSession(ctx)
|
||||
Render(ctx, templates.RenderLogin(pcLogin))
|
||||
request := requests.NewRequest(ctx, data.UsersStorage)
|
||||
Render(ctx, templates.RenderLogin(request, pcLogin))
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoginSubmit(ctx *fiber.Ctx) error {
|
||||
requestSession := usersession.NewRequestSession(ctx)
|
||||
request := requests.NewRequest(ctx, data.UsersStorage)
|
||||
|
||||
content := templates.LoginFormValidationContent{
|
||||
Validated: true,
|
||||
@ -39,7 +40,7 @@ func LoginSubmit(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
if !hasError {
|
||||
err := requestSession.LoginUser(content.Username, content.Password)
|
||||
err := request.LoginUser(content.Username, content.Password)
|
||||
if err == nil {
|
||||
ctx.Set("HX-Location", "/")
|
||||
return nil
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/handlers/usersession"
|
||||
"fiber-sessions/app/data"
|
||||
"fiber-sessions/app/router/requests"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Logout(ctx *fiber.Ctx) error {
|
||||
requestSession := usersession.NewRequestSession(ctx)
|
||||
requestSession.Logout()
|
||||
request := requests.NewRequest(ctx, data.UsersStorage)
|
||||
request.Logout()
|
||||
|
||||
ctx.Redirect("/")
|
||||
return nil
|
||||
|
||||
@ -1,113 +0,0 @@
|
||||
package usersession
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fiber-sessions/app/types"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/session"
|
||||
"github.com/gofiber/storage/memory/v2"
|
||||
)
|
||||
|
||||
var sessionStorage = memory.New()
|
||||
var sessionStore = session.New(session.Config{
|
||||
Storage: sessionStorage,
|
||||
})
|
||||
|
||||
const SESSION_EXPIRES = time.Minute * 30
|
||||
|
||||
var dbUsers map[string]types.User = map[string]types.User{
|
||||
"pero-uuid": {
|
||||
Id: "pero-uuid",
|
||||
Username: "pero",
|
||||
Password: "pero",
|
||||
FirstName: "Pero",
|
||||
LastName: "Perić",
|
||||
},
|
||||
"mirko-uuid": {
|
||||
Id: "mirko-uuid",
|
||||
Username: "mirko",
|
||||
Password: "mirko",
|
||||
FirstName: "Mirko",
|
||||
LastName: "Mirković",
|
||||
},
|
||||
}
|
||||
|
||||
type RequestSession struct {
|
||||
ctx *fiber.Ctx
|
||||
session *session.Session
|
||||
User *types.User
|
||||
}
|
||||
|
||||
func NewRequestSession(ctx *fiber.Ctx) *RequestSession {
|
||||
session, err := sessionStore.Get(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var user *types.User = nil
|
||||
|
||||
userId := session.Get("userId")
|
||||
fmt.Printf("userId: %+v\n", userId)
|
||||
if userId != nil {
|
||||
user = getUserById(userId.(string))
|
||||
}
|
||||
|
||||
return &RequestSession{
|
||||
ctx: ctx,
|
||||
session: session,
|
||||
User: user,
|
||||
}
|
||||
}
|
||||
|
||||
func getUserById(id string) *types.User {
|
||||
user, ok := dbUsers[id]
|
||||
if ok {
|
||||
return &user
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getUser(username string, password string) *types.User {
|
||||
for _, user := range dbUsers {
|
||||
if user.Username == username {
|
||||
if user.Password == password {
|
||||
return &user
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RequestSession) LoginUser(username string, password string) error {
|
||||
user := getUser(username, password)
|
||||
|
||||
if user == nil {
|
||||
return errors.New("invalid username or password")
|
||||
}
|
||||
r.User = user
|
||||
|
||||
r.session.Set("userId", r.User.Id)
|
||||
r.session.SetExpiry(SESSION_EXPIRES)
|
||||
if err := r.session.Save(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RequestSession) UserAuthenticated() bool {
|
||||
return r.User != nil
|
||||
}
|
||||
|
||||
func (r *RequestSession) Logout() error {
|
||||
if !r.UserAuthenticated() {
|
||||
return errors.New("user not authenticated")
|
||||
}
|
||||
r.session.Destroy()
|
||||
r.User = nil
|
||||
return nil
|
||||
}
|
||||
81
app/router/requests/requests.go
Normal file
81
app/router/requests/requests.go
Normal file
@ -0,0 +1,81 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fiber-sessions/app/types"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/session"
|
||||
"github.com/gofiber/storage/memory/v2"
|
||||
)
|
||||
|
||||
var sessionStorage = memory.New()
|
||||
var sessionStore = session.New(session.Config{
|
||||
Storage: sessionStorage,
|
||||
})
|
||||
|
||||
const SESSION_EXPIRES = time.Minute * 30
|
||||
|
||||
type UserGetter interface {
|
||||
GetUserById(id string) *types.User
|
||||
AuthUser(username string, password string) *types.User
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
ctx *fiber.Ctx
|
||||
session *session.Session
|
||||
User *types.User
|
||||
userGetter UserGetter
|
||||
}
|
||||
|
||||
func NewRequest(ctx *fiber.Ctx, userGetter UserGetter) *Request {
|
||||
session, err := sessionStore.Get(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var user *types.User = nil
|
||||
|
||||
userId := session.Get("userId")
|
||||
if userId != nil {
|
||||
user = userGetter.GetUserById(userId.(string))
|
||||
}
|
||||
|
||||
return &Request{
|
||||
ctx: ctx,
|
||||
session: session,
|
||||
userGetter: userGetter,
|
||||
User: user,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Request) LoginUser(username string, password string) error {
|
||||
user := r.userGetter.AuthUser(username, password)
|
||||
|
||||
if user == nil {
|
||||
return errors.New("invalid username or password")
|
||||
}
|
||||
r.User = user
|
||||
|
||||
r.session.Set("userId", r.User.Id)
|
||||
r.session.SetExpiry(SESSION_EXPIRES)
|
||||
if err := r.session.Save(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Request) UserAuthenticated() bool {
|
||||
return r.User != nil
|
||||
}
|
||||
|
||||
func (r *Request) Logout() error {
|
||||
if !r.UserAuthenticated() {
|
||||
return errors.New("user not authenticated")
|
||||
}
|
||||
r.session.Destroy()
|
||||
r.User = nil
|
||||
return nil
|
||||
}
|
||||
@ -58,14 +58,6 @@ func initRouter(app *fiber.App) {
|
||||
app.Post("/login", handlers.LoginSubmit)
|
||||
app.Get("/logout", handlers.Logout)
|
||||
|
||||
interactiveGroup := app.Group("/interactive")
|
||||
{
|
||||
interactiveGroup.Get("", handlers.Interactive)
|
||||
interactiveGroup.Get("/swap-content", handlers.InteractiveSwapContent)
|
||||
interactiveGroup.Get("/filter-cat-breeds", handlers.FilterCatBreeds)
|
||||
interactiveGroup.Post("/validate-form", handlers.ValidateForm)
|
||||
}
|
||||
|
||||
app.Static("/static", STATIC_PATH)
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
package templates
|
||||
|
||||
templ Home(pc PageContext) {
|
||||
@baseLayout(pc) {
|
||||
import (
|
||||
"fiber-sessions/app/router/requests"
|
||||
)
|
||||
|
||||
templ Home(request *requests.Request, pc PageContext) {
|
||||
@baseLayout(request, pc) {
|
||||
<p>Bacon ipsum dolor amet venison bacon picanha jerky tenderloin. Hamburger sausage meatball chislic salami. Ball tip tenderloin chuck, venison strip steak kielbasa short loin bresaola short ribs cupim drumstick shoulder pork t-bone. Burgdoggen cupim meatball picanha meatloaf, jowl leberkas kevin. T-bone jowl ham hock salami tenderloin.</p>
|
||||
<p>Beef ribs frankfurter corned beef ground round pork, sausage drumstick. Corned beef turducken beef ribs, tongue burgdoggen capicola kielbasa short loin pork belly tail frankfurter ribeye strip steak meatloaf. Alcatra frankfurter salami cupim strip steak leberkas jerky ham hock biltong swine ball tip prosciutto t-bone andouille. Pork loin hamburger chuck frankfurter ham shankle jowl sausage chislic chicken tenderloin. Capicola tongue beef ribs flank, doner sirloin tri-tip pastrami. Porchetta andouille pork fatback jerky, pancetta pig filet mignon leberkas kielbasa sirloin.</p>
|
||||
<p>Biltong landjaeger drumstick meatball boudin pork chop turducken jerky hamburger filet mignon flank. Venison turducken pork belly, pork chop ground round buffalo strip steak ribeye alcatra pancetta flank salami chislic. Landjaeger flank andouille short ribs. Shoulder beef ribs chuck, corned beef frankfurter turducken prosciutto.</p>
|
||||
|
||||
@ -10,7 +10,11 @@ import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
func Home(pc PageContext) templ.Component {
|
||||
import (
|
||||
"fiber-sessions/app/router/requests"
|
||||
)
|
||||
|
||||
func Home(request *requests.Request, pc PageContext) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
@ -83,7 +87,7 @@ func Home(pc PageContext) templ.Component {
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
templ_7745c5c3_Err = baseLayout(pc).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = baseLayout(request, pc).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@ -1,229 +0,0 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/types"
|
||||
"fiber-sessions/app/data"
|
||||
"slices"
|
||||
"sort"
|
||||
)
|
||||
|
||||
templ interactiveButtonsSection() {
|
||||
<h3 class="mb-3">
|
||||
Interactive buttons
|
||||
</h3>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-info mb-3"
|
||||
hx-get="/interactive/swap-content?content=1"
|
||||
hx-target="#swap-content-target"
|
||||
>
|
||||
Swap to content 1
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-warning mb-3"
|
||||
hx-get="/interactive/swap-content?content=2"
|
||||
hx-target="#swap-content-target"
|
||||
>
|
||||
Swap to content 2
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-danger mb-3"
|
||||
hx-get="/interactive/swap-content?content=3"
|
||||
hx-target="#swap-content-target"
|
||||
>
|
||||
Swap to content 3
|
||||
</button>
|
||||
<p id="swap-content-target">
|
||||
Bacon ipsum dolor amet cow capicola pancetta picanha biltong brisket filet mignon turducken beef ribs burgdoggen landjaeger meatball venison shank. Capicola ham pork chop, biltong kielbasa pancetta short loin jowl cupim pig jerky drumstick turducken burgdoggen beef. Spare ribs flank ribeye cow doner, shank chuck bacon ham hock porchetta kielbasa tri-tip. Ham t-bone chislic, capicola andouille ham hock frankfurter tri-tip sausage kevin landjaeger shank ribeye. Swine tri-tip spare ribs, rump flank bresaola kevin tail. Meatball tail picanha cow, frankfurter ribeye sirloin pork belly short loin pig. Filet mignon spare ribs pastrami, tri-tip ball tip tongue fatback pork chop.
|
||||
</p>
|
||||
}
|
||||
|
||||
func getCatCountriesOptions() []string {
|
||||
var res []string = []string{}
|
||||
|
||||
for _, cb := range data.CatBreeds {
|
||||
if len(cb.Country) > 0 && !slices.Contains(res, cb.Country) {
|
||||
res = append(res, cb.Country)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(res)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
templ catBreedsSection(catBreeds []types.CatBreed) {
|
||||
<h3 class="mt-5 mb-3">
|
||||
Cat breeds
|
||||
</h3>
|
||||
<div class="card mb-2">
|
||||
<div class="card-body">
|
||||
<form
|
||||
class="row g-3 align-items-center"
|
||||
>
|
||||
<div class="col-auto">
|
||||
<label class="form-label">Breed:</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input
|
||||
type="text"
|
||||
name="breed"
|
||||
class="form-control"
|
||||
hx-get="/interactive/filter-cat-breeds"
|
||||
hx-target="#cat-breeds-table"
|
||||
hx-trigger="keyup"
|
||||
hx-include="select[name='country']"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label">Country:</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<select
|
||||
name="country"
|
||||
class="form-select"
|
||||
hx-get="/interactive/filter-cat-breeds"
|
||||
hx-target="#cat-breeds-table"
|
||||
hx-trigger="change"
|
||||
hx-include="input[name='breed']"
|
||||
>
|
||||
<option value="">
|
||||
- All -
|
||||
</option>
|
||||
for _, opt := range getCatCountriesOptions() {
|
||||
<option value={ opt }>
|
||||
{ opt }
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@catBreedsTable(catBreeds)
|
||||
}
|
||||
|
||||
templ catBreedsTable(catBreeds []types.CatBreed) {
|
||||
<table class="table" id="cat-breeds-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Breed</th>
|
||||
<th>Country</th>
|
||||
<th>Origin</th>
|
||||
<th>Coat</th>
|
||||
<th>Pattern</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
for _, breed := range catBreeds {
|
||||
<tr>
|
||||
<td>{ breed.Breed }</td>
|
||||
<td>{ breed.Country }</td>
|
||||
<td>{ breed.Origin }</td>
|
||||
<td>{ breed.Coat }</td>
|
||||
<td>{ breed.Pattern }</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
templ InteractiveSwapContent(pc PageContext, contentIndex int) {
|
||||
switch contentIndex {
|
||||
case 1:
|
||||
<p class="alert alert-info">
|
||||
Bacon ipsum dolor amet t-bone meatball corned beef hamburger cupim rump drumstick tri-tip doner pastrami kielbasa salami pig. Pork loin doner leberkas, jerky fatback chuck corned beef cow rump strip steak shoulder pork belly. Flank hamburger porchetta shank sirloin bresaola chislic pork chop. Chicken jerky strip steak tongue jowl brisket cupim. Shankle t-bone short ribs fatback burgdoggen buffalo cupim prosciutto meatball pig doner boudin.
|
||||
</p>
|
||||
case 2:
|
||||
<p class="alert alert-warning">
|
||||
Rump venison tenderloin, picanha ribeye cupim pork belly sirloin landjaeger jerky prosciutto filet mignon alcatra. Short ribs pork chop rump kevin t-bone ground round hamburger, chislic tenderloin bacon sirloin filet mignon turducken beef pork loin. Buffalo picanha ground round pork chop. Venison cupim pork belly, andouille pastrami tail shankle pancetta. Picanha leberkas cupim turkey buffalo filet mignon pork belly pork chop rump sausage pork loin. Short ribs burgdoggen porchetta hamburger, cupim ribeye capicola shoulder. Pork drumstick kevin, turkey hamburger ground round burgdoggen chuck jerky bacon sausage chislic leberkas.
|
||||
</p>
|
||||
case 3:
|
||||
<p class="alert alert-danger">
|
||||
Biltong ham hock tongue, beef pork andouille fatback flank pork loin ribeye. Rump short loin porchetta, ground round buffalo hamburger salami pig venison beef ribs. Chislic beef ribs sausage fatback pork belly. Ribeye porchetta leberkas, tail hamburger biltong landjaeger short loin filet mignon chicken salami flank.
|
||||
</p>
|
||||
default:
|
||||
<p>
|
||||
Some new content with unknown index...
|
||||
</p>
|
||||
}
|
||||
}
|
||||
|
||||
templ RenderCatBreedsTable(catBreeds []types.CatBreed) {
|
||||
@catBreedsTable(catBreeds)
|
||||
}
|
||||
|
||||
templ RenderInteractiveForm(content ValidateFormContent) {
|
||||
<div class="row" id="validation-form-content">
|
||||
<div class="col">
|
||||
<div class="mb-3">
|
||||
<label for="validation-form-number" class="form-label">Enter number 0..100</label>
|
||||
<input
|
||||
type="text"
|
||||
class={ "form-control",
|
||||
templ.KV("is-invalid", content.HasNumValueError),
|
||||
templ.KV("is-valid", content.Validated && !content.HasNumValueError) }
|
||||
name="number-value"
|
||||
id="validation-form-number"
|
||||
value={ content.NumValue }
|
||||
/>
|
||||
if content.HasNumValueError {
|
||||
<div class="invalid-feedback">{ content.NumValueError }</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="mb-3">
|
||||
<label for="validation-form-string" class="form-label">Enter string, length 5..10</label>
|
||||
<input
|
||||
type="text"
|
||||
class={ "form-control",
|
||||
templ.KV("is-invalid", content.HasStrValueError),
|
||||
templ.KV("is-valid", content.Validated && !content.HasStrValueError) }
|
||||
name="string-value"
|
||||
id="validation-form-string"
|
||||
value={ content.StrValue }
|
||||
/>
|
||||
if content.HasStrValueError {
|
||||
<div class="invalid-feedback">{ content.StrValueError }</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ interactiveFormSection() {
|
||||
<h3 class="mb-3">
|
||||
Form validation
|
||||
</h3>
|
||||
<form
|
||||
hx-post="/interactive/validate-form"
|
||||
hx-target="#validation-form-content"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<div class="card p-4">
|
||||
@RenderInteractiveForm(ValidateFormContent{})
|
||||
<div class="d-flex">
|
||||
<button type="submit" class="btn btn-success ms-auto">
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
|
||||
templ Interactive(pc PageContext, catBreeds []types.CatBreed) {
|
||||
@baseLayout(pc) {
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@interactiveButtonsSection()
|
||||
</div>
|
||||
<div class="col">
|
||||
@interactiveFormSection()
|
||||
</div>
|
||||
</div>
|
||||
@catBreedsSection(catBreeds)
|
||||
}
|
||||
}
|
||||
@ -1,693 +0,0 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.513
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/data"
|
||||
"fiber-sessions/app/types"
|
||||
"slices"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func interactiveButtonsSection() templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h3 class=\"mb-3\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var2 := `Interactive buttons`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h3><button type=\"button\" class=\"btn btn-info mb-3\" hx-get=\"/interactive/swap-content?content=1\" hx-target=\"#swap-content-target\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var3 := `Swap to content 1`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button> <button type=\"button\" class=\"btn btn-warning mb-3\" hx-get=\"/interactive/swap-content?content=2\" hx-target=\"#swap-content-target\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var4 := `Swap to content 2`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button> <button type=\"button\" class=\"btn btn-danger mb-3\" hx-get=\"/interactive/swap-content?content=3\" hx-target=\"#swap-content-target\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var5 := `Swap to content 3`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button><p id=\"swap-content-target\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var6 := `Bacon ipsum dolor amet cow capicola pancetta picanha biltong brisket filet mignon turducken beef ribs burgdoggen landjaeger meatball venison shank. Capicola ham pork chop, biltong kielbasa pancetta short loin jowl cupim pig jerky drumstick turducken burgdoggen beef. Spare ribs flank ribeye cow doner, shank chuck bacon ham hock porchetta kielbasa tri-tip. Ham t-bone chislic, capicola andouille ham hock frankfurter tri-tip sausage kevin landjaeger shank ribeye. Swine tri-tip spare ribs, rump flank bresaola kevin tail. Meatball tail picanha cow, frankfurter ribeye sirloin pork belly short loin pig. Filet mignon spare ribs pastrami, tri-tip ball tip tongue fatback pork chop.`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func getCatCountriesOptions() []string {
|
||||
var res []string = []string{}
|
||||
|
||||
for _, cb := range data.CatBreeds {
|
||||
if len(cb.Country) > 0 && !slices.Contains(res, cb.Country) {
|
||||
res = append(res, cb.Country)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(res)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func catBreedsSection(catBreeds []types.CatBreed) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var7 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var7 == nil {
|
||||
templ_7745c5c3_Var7 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h3 class=\"mt-5 mb-3\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var8 := `Cat breeds`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h3><div class=\"card mb-2\"><div class=\"card-body\"><form class=\"row g-3 align-items-center\"><div class=\"col-auto\"><label class=\"form-label\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var9 := `Breed:`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label></div><div class=\"col-auto\"><input type=\"text\" name=\"breed\" class=\"form-control\" hx-get=\"/interactive/filter-cat-breeds\" hx-target=\"#cat-breeds-table\" hx-trigger=\"keyup\" hx-include=\"select[name='country']\"></div><div class=\"col-auto\"><label class=\"form-label\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var10 := `Country:`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label></div><div class=\"col-auto\"><select name=\"country\" class=\"form-select\" hx-get=\"/interactive/filter-cat-breeds\" hx-target=\"#cat-breeds-table\" hx-trigger=\"change\" hx-include=\"input[name='breed']\"><option value=\"\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var11 := `- All -`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, opt := range getCatCountriesOptions() {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(opt))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(opt)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 96, Col: 13}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></div></form></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = catBreedsTable(catBreeds).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func catBreedsTable(catBreeds []types.CatBreed) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var13 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var13 == nil {
|
||||
templ_7745c5c3_Var13 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<table class=\"table\" id=\"cat-breeds-table\"><thead><tr><th>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var14 := `Breed`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</th><th>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var15 := `Country`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</th><th>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var16 := `Origin`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</th><th>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var17 := `Coat`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</th><th>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var18 := `Pattern`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var18)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</th></tr></thead> <tbody>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, breed := range catBreeds {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var19 string
|
||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(breed.Breed)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 121, Col: 22}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var20 string
|
||||
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(breed.Country)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 122, Col: 24}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var21 string
|
||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(breed.Origin)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 123, Col: 23}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var22 string
|
||||
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(breed.Coat)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 124, Col: 21}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var23 string
|
||||
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(breed.Pattern)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 125, Col: 24}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func InteractiveSwapContent(pc PageContext, contentIndex int) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var24 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var24 == nil {
|
||||
templ_7745c5c3_Var24 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
switch contentIndex {
|
||||
case 1:
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"alert alert-info\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var25 := `Bacon ipsum dolor amet t-bone meatball corned beef hamburger cupim rump drumstick tri-tip doner pastrami kielbasa salami pig. Pork loin doner leberkas, jerky fatback chuck corned beef cow rump strip steak shoulder pork belly. Flank hamburger porchetta shank sirloin bresaola chislic pork chop. Chicken jerky strip steak tongue jowl brisket cupim. Shankle t-bone short ribs fatback burgdoggen buffalo cupim prosciutto meatball pig doner boudin.`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var25)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
case 2:
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"alert alert-warning\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var26 := `Rump venison tenderloin, picanha ribeye cupim pork belly sirloin landjaeger jerky prosciutto filet mignon alcatra. Short ribs pork chop rump kevin t-bone ground round hamburger, chislic tenderloin bacon sirloin filet mignon turducken beef pork loin. Buffalo picanha ground round pork chop. Venison cupim pork belly, andouille pastrami tail shankle pancetta. Picanha leberkas cupim turkey buffalo filet mignon pork belly pork chop rump sausage pork loin. Short ribs burgdoggen porchetta hamburger, cupim ribeye capicola shoulder. Pork drumstick kevin, turkey hamburger ground round burgdoggen chuck jerky bacon sausage chislic leberkas.`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var26)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
case 3:
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"alert alert-danger\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var27 := `Biltong ham hock tongue, beef pork andouille fatback flank pork loin ribeye. Rump short loin porchetta, ground round buffalo hamburger salami pig venison beef ribs. Chislic beef ribs sausage fatback pork belly. Ribeye porchetta leberkas, tail hamburger biltong landjaeger short loin filet mignon chicken salami flank.`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var27)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
default:
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var28 := `Some new content with unknown index...`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var28)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func RenderCatBreedsTable(catBreeds []types.CatBreed) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var29 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var29 == nil {
|
||||
templ_7745c5c3_Var29 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = catBreedsTable(catBreeds).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func RenderInteractiveForm(content ValidateFormContent) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var30 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var30 == nil {
|
||||
templ_7745c5c3_Var30 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"row\" id=\"validation-form-content\"><div class=\"col\"><div class=\"mb-3\"><label for=\"validation-form-number\" class=\"form-label\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var31 := `Enter number 0..100`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var31)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var32 = []any{"form-control",
|
||||
templ.KV("is-invalid", content.HasNumValueError),
|
||||
templ.KV("is-valid", content.Validated && !content.HasNumValueError)}
|
||||
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var32...)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<input type=\"text\" class=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var32).String()))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" name=\"number-value\" id=\"validation-form-number\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(content.NumValue))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if content.HasNumValueError {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"invalid-feedback\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var33 string
|
||||
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(content.NumValueError)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 172, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div><div class=\"col\"><div class=\"mb-3\"><label for=\"validation-form-string\" class=\"form-label\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var34 := `Enter string, length 5..10`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var34)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var35 = []any{"form-control",
|
||||
templ.KV("is-invalid", content.HasStrValueError),
|
||||
templ.KV("is-valid", content.Validated && !content.HasStrValueError)}
|
||||
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var35...)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<input type=\"text\" class=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var35).String()))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" name=\"string-value\" id=\"validation-form-string\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(content.StrValue))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if content.HasStrValueError {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"invalid-feedback\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var36 string
|
||||
templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(content.StrValueError)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/interactive.templ`, Line: 189, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func interactiveFormSection() templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var37 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var37 == nil {
|
||||
templ_7745c5c3_Var37 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h3 class=\"mb-3\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var38 := `Form validation`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var38)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h3><form hx-post=\"/interactive/validate-form\" hx-target=\"#validation-form-content\" hx-swap=\"outerHTML\"><div class=\"card p-4\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = RenderInteractiveForm(ValidateFormContent{}).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"d-flex\"><button type=\"submit\" class=\"btn btn-success ms-auto\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var39 := `Submit`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var39)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button></div></div></form>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func Interactive(pc PageContext, catBreeds []types.CatBreed) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var40 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var40 == nil {
|
||||
templ_7745c5c3_Var40 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Var41 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"row\"><div class=\"col\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = interactiveButtonsSection().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div class=\"col\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = interactiveFormSection().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = catBreedsSection(catBreeds).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
templ_7745c5c3_Err = baseLayout(pc).Render(templ.WithChildren(ctx, templ_7745c5c3_Var41), templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
@ -1,6 +1,10 @@
|
||||
package templates
|
||||
|
||||
templ baseLayout(pc PageContext) {
|
||||
import (
|
||||
"fiber-sessions/app/router/requests"
|
||||
)
|
||||
|
||||
templ baseLayout(request *requests.Request, pc PageContext) {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -22,7 +26,7 @@ templ baseLayout(pc PageContext) {
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
if pc.RequestSession.UserAuthenticated() {
|
||||
if request.UserAuthenticated() {
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/logout">
|
||||
Logout
|
||||
@ -35,15 +39,10 @@ templ baseLayout(pc PageContext) {
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
<li class="nav-item">
|
||||
<a class={ "nav-link", templ.KV("active", pc.ActivePage == "interactive") } href="/interactive">
|
||||
Interactive
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
if pc.RequestSession.UserAuthenticated() {
|
||||
if request.UserAuthenticated() {
|
||||
<p class="alert alert-warning">
|
||||
Hello, { pc.RequestSession.User.FirstName }
|
||||
Hello, { request.User.FirstName }
|
||||
</p>
|
||||
}
|
||||
{ children... }
|
||||
|
||||
@ -10,7 +10,11 @@ import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
func baseLayout(pc PageContext) templ.Component {
|
||||
import (
|
||||
"fiber-sessions/app/router/requests"
|
||||
)
|
||||
|
||||
func baseLayout(request *requests.Request, pc PageContext) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
@ -39,7 +43,7 @@ func baseLayout(pc PageContext) templ.Component {
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(pc.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/layout.templ`, Line: 11, Col: 20}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/layout.templ`, Line: 15, Col: 20}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -84,7 +88,7 @@ func baseLayout(pc PageContext) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if pc.RequestSession.UserAuthenticated() {
|
||||
if request.UserAuthenticated() {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li class=\"nav-item\"><a class=\"nav-link\" href=\"/logout\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
@ -130,52 +134,26 @@ func baseLayout(pc PageContext) templ.Component {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li class=\"nav-item\">")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var10 = []any{"nav-link", templ.KV("active", pc.ActivePage == "interactive")}
|
||||
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var10...)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<a class=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var10).String()))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" href=\"/interactive\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var11 := `Interactive`
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></li></ul>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if pc.RequestSession.UserAuthenticated() {
|
||||
if request.UserAuthenticated() {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"alert alert-warning\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Var12 := `Hello, `
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
|
||||
templ_7745c5c3_Var10 := `Hello, `
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(pc.RequestSession.User.FirstName)
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(request.User.FirstName)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/layout.templ`, Line: 45, Col: 47}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/layout.templ`, Line: 44, Col: 37}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/router/requests"
|
||||
)
|
||||
|
||||
templ LoginFormContent(content LoginFormValidationContent) {
|
||||
<div id="login-form-container">
|
||||
<div class="mb-3">
|
||||
@ -49,8 +53,8 @@ templ LoginFormContent(content LoginFormValidationContent) {
|
||||
</div>
|
||||
}
|
||||
|
||||
templ RenderLogin(pc PageContext) {
|
||||
@baseLayout(pc) {
|
||||
templ RenderLogin(request *requests.Request, pc PageContext) {
|
||||
@baseLayout(request, pc) {
|
||||
<div class="card ms-auto me-auto" style="max-width: 500px;">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title mb-4">
|
||||
|
||||
@ -10,6 +10,10 @@ import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/router/requests"
|
||||
)
|
||||
|
||||
func LoginFormContent(content LoginFormValidationContent) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
@ -71,7 +75,7 @@ func LoginFormContent(content LoginFormValidationContent) templ.Component {
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(content.UsernameError)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/login.templ`, Line: 18, Col: 57}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/login.templ`, Line: 22, Col: 57}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -130,7 +134,7 @@ func LoginFormContent(content LoginFormValidationContent) templ.Component {
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(content.PasswordError)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/login.templ`, Line: 35, Col: 57}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/login.templ`, Line: 39, Col: 57}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -153,7 +157,7 @@ func LoginFormContent(content LoginFormValidationContent) templ.Component {
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(content.LoginError)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/login.templ`, Line: 40, Col: 24}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/templates/login.templ`, Line: 44, Col: 24}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@ -184,7 +188,7 @@ func LoginFormContent(content LoginFormValidationContent) templ.Component {
|
||||
})
|
||||
}
|
||||
|
||||
func RenderLogin(pc PageContext) templ.Component {
|
||||
func RenderLogin(request *requests.Request, pc PageContext) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
@ -229,7 +233,7 @@ func RenderLogin(pc PageContext) templ.Component {
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
templ_7745c5c3_Err = baseLayout(pc).Render(templ.WithChildren(ctx, templ_7745c5c3_Var11), templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = baseLayout(request, pc).Render(templ.WithChildren(ctx, templ_7745c5c3_Var11), templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
package templates
|
||||
|
||||
import "fiber-sessions/app/handlers/usersession"
|
||||
|
||||
type PageContext struct {
|
||||
Title string
|
||||
ActivePage string
|
||||
RequestSession *usersession.RequestSession
|
||||
Title string
|
||||
ActivePage string
|
||||
}
|
||||
|
||||
type ValidateFormContent struct {
|
||||
|
||||
Reference in New Issue
Block a user