Okay this is based

This commit is contained in:
DutchEllie 2022-03-07 13:05:33 +01:00
parent e92d0f2c26
commit c10a995b63
Signed by: DutchEllie
SSH Key Fingerprint: SHA256:dKq6ZSgN5E3Viqrw/+xAdf2VdR6hdRGNyrYqXXwfjTY
8 changed files with 93 additions and 50 deletions

View File

@ -15,10 +15,8 @@ func NewAboutPage() *AboutPage {
func (a *AboutPage) Render() app.UI { func (a *AboutPage) Render() app.UI {
return app.Div().Body( return app.Div().Body(
&header{}, &header{},
app.Div().Body( &navbar{},
newNavbar(), &aboutPanel{},
&aboutPanel{},
).Class("main"),
) )
} }

38
components/friendspage.go Normal file
View File

@ -0,0 +1,38 @@
package components
import "github.com/maxence-charriere/go-app/v9/pkg/app"
type FriendsPage struct {
app.Compo
}
func NewFriendsPage() *FriendsPage {
return &FriendsPage{}
}
func (f *FriendsPage) Render() app.UI {
return app.Div().Body(
&header{},
&navbar{},
&friendsPanel{},
).Class("main")
}
type friendsPanel struct {
app.Compo
}
func (f *friendsPanel) Render() app.UI {
return app.Div().Body(
app.P().
Text(`My friends!`).
Class("p-h1"),
app.Ul().Body(
app.Li().Body(
app.IFrame().
Src("forestofunix.xyz").
Class("friend-iframe"),
),
),
).Class("content")
}

View File

@ -47,7 +47,6 @@ func (g *guestbookForm) Render() app.UI {
} }
g.OnSubmit(g.name, g.message) g.OnSubmit(g.name, g.message)
g.clear() g.clear()
g.Update()
}), }),
).Class("content") ).Class("content")
} }

View File

@ -65,18 +65,6 @@ func (g *guestbookPanel) LoadComments() {
} }
} }
func (g *guestbookPanel) OnMount(ctx app.Context) {
//g.LoadComments()
}
func (g *guestbookPanel) OnUpdate(ctx app.Context) {
if g.CommentUpdate {
g.LoadComments()
g.Update()
g.CommentUpdate = false
}
}
type guestbookComment struct { type guestbookComment struct {
app.Compo app.Compo

View File

@ -15,46 +15,48 @@ type Homepage struct {
showGuestbook bool showGuestbook bool
guestbookUpdated bool guestbookUpdated bool
page string
} }
func NewHomepage() *Homepage { func NewHomepage() *Homepage {
return &Homepage{showGuestbook: true, guestbookUpdated: false} return &Homepage{showGuestbook: true, guestbookUpdated: false, page: "home"}
} }
func (p *Homepage) Render() app.UI { func (p *Homepage) Render() app.UI {
gbp := newGuestbookPanel() gbp := newGuestbookPanel()
return app.Div().Body( return app.Div().Body(
&header{}, &header{},
app.Div().Body( &navbar{},
newNavbar(), &homePanel{
&homePanel{ onShowClick: func() {
onShowClick: func() { p.showGuestbook = !p.showGuestbook
p.showGuestbook = !p.showGuestbook
},
}, },
&guestbookForm{ },
OnSubmit: func(name, message string) { &guestbookForm{
var comment entity.Comment OnSubmit: func(name, message string) {
comment.Name = name var comment entity.Comment
comment.Message = message comment.Name = name
comment.Message = message
jsondata, err := json.Marshal(comment) jsondata, err := json.Marshal(comment)
if err != nil { if err != nil {
fmt.Printf("err: %v\n", err) fmt.Printf("err: %v\n", err)
return return
} }
url := "/api/comment" url := "/api/comment"
req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata)) req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata))
if err != nil { if err != nil {
fmt.Printf("err: %v\n", err) fmt.Printf("err: %v\n", err)
return return
} }
if req.StatusCode == 200 { if req.StatusCode == 200 {
} p.Update()
defer req.Body.Close() }
}, defer req.Body.Close()
}, },
app.If(p.showGuestbook, gbp), },
).Class("main"), //app.If(p.showGuestbook, gbp),
) gbp.Render(),
).Class("main")
} }

View File

@ -4,10 +4,8 @@ import "github.com/maxence-charriere/go-app/v9/pkg/app"
type navbar struct { type navbar struct {
app.Compo app.Compo
}
func newNavbar() *navbar { OnClickButton func(page string)
return &navbar{}
} }
func (n *navbar) Render() app.UI { func (n *navbar) Render() app.UI {
@ -19,6 +17,9 @@ func (n *navbar) Render() app.UI {
app.Li().Body( app.Li().Body(
app.A().Href("/about").Text("About"), app.A().Href("/about").Text("About"),
), ),
app.Li().Body(
app.A().Href("/friends").Text("Friends"),
),
), ),
).Class("navbar") ).Class("navbar")
} }

View File

@ -22,8 +22,10 @@ type application struct {
func main() { func main() {
homepage := components.NewHomepage() homepage := components.NewHomepage()
aboutpage := components.NewAboutPage() aboutpage := components.NewAboutPage()
friendspage := components.NewFriendsPage()
app.Route("/", homepage) app.Route("/", homepage)
app.Route("/about", aboutpage) app.Route("/about", aboutpage)
app.Route("/friends", friendspage)
// This is executed on the client side only. // This is executed on the client side only.
// It handles client side stuff // It handles client side stuff

View File

@ -69,6 +69,21 @@ body {
padding: 5px; padding: 5px;
} }
.friend-frame {
width: 290px;
height: 200px;
overflow: hidden;
list-style: none;
text-decoration: none;
-ms-zoom: 0.75;
-moz-transform: scale(0.75);
-moz-transform-origin: 0 0;
-o-transform: scale(0.75);
-o-transform-origin: 0 0;
-webkit-transform: scale(0.75);
-webkit-transform-origin: 0 0;
}
.p-h1 { .p-h1 {
font-family: anisha; font-family: anisha;
font-size: 3em; font-size: 3em;