From c10a995b632134d1762a7e690b52c7a2aaac27ea Mon Sep 17 00:00:00 2001 From: DutchEllie Date: Mon, 7 Mar 2022 13:05:33 +0100 Subject: [PATCH] Okay this is based --- components/aboutpage.go | 6 ++-- components/friendspage.go | 38 ++++++++++++++++++++++ components/guestbookform.go | 1 - components/guestbookpanel.go | 12 ------- components/homepage.go | 62 +++++++++++++++++++----------------- components/navbar.go | 7 ++-- main.go | 2 ++ web/static/style.css | 15 +++++++++ 8 files changed, 93 insertions(+), 50 deletions(-) create mode 100644 components/friendspage.go diff --git a/components/aboutpage.go b/components/aboutpage.go index d5cb344..aa367e1 100644 --- a/components/aboutpage.go +++ b/components/aboutpage.go @@ -15,10 +15,8 @@ func NewAboutPage() *AboutPage { func (a *AboutPage) Render() app.UI { return app.Div().Body( &header{}, - app.Div().Body( - newNavbar(), - &aboutPanel{}, - ).Class("main"), + &navbar{}, + &aboutPanel{}, ) } diff --git a/components/friendspage.go b/components/friendspage.go new file mode 100644 index 0000000..5d66312 --- /dev/null +++ b/components/friendspage.go @@ -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") +} diff --git a/components/guestbookform.go b/components/guestbookform.go index 105a578..53e3250 100644 --- a/components/guestbookform.go +++ b/components/guestbookform.go @@ -47,7 +47,6 @@ func (g *guestbookForm) Render() app.UI { } g.OnSubmit(g.name, g.message) g.clear() - g.Update() }), ).Class("content") } diff --git a/components/guestbookpanel.go b/components/guestbookpanel.go index 3861e59..2b4e18d 100644 --- a/components/guestbookpanel.go +++ b/components/guestbookpanel.go @@ -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 { app.Compo diff --git a/components/homepage.go b/components/homepage.go index 70e8c43..00bfd07 100644 --- a/components/homepage.go +++ b/components/homepage.go @@ -15,46 +15,48 @@ type Homepage struct { showGuestbook bool guestbookUpdated bool + + page string } func NewHomepage() *Homepage { - return &Homepage{showGuestbook: true, guestbookUpdated: false} + return &Homepage{showGuestbook: true, guestbookUpdated: false, page: "home"} } func (p *Homepage) Render() app.UI { gbp := newGuestbookPanel() return app.Div().Body( &header{}, - app.Div().Body( - newNavbar(), - &homePanel{ - onShowClick: func() { - p.showGuestbook = !p.showGuestbook - }, + &navbar{}, + &homePanel{ + onShowClick: func() { + p.showGuestbook = !p.showGuestbook }, - &guestbookForm{ - OnSubmit: func(name, message string) { - var comment entity.Comment - comment.Name = name - comment.Message = message + }, + &guestbookForm{ + OnSubmit: func(name, message string) { + var comment entity.Comment + comment.Name = name + comment.Message = message - jsondata, err := json.Marshal(comment) - if err != nil { - fmt.Printf("err: %v\n", err) - return - } - url := "/api/comment" - req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata)) - if err != nil { - fmt.Printf("err: %v\n", err) - return - } - if req.StatusCode == 200 { - } - defer req.Body.Close() - }, + jsondata, err := json.Marshal(comment) + if err != nil { + fmt.Printf("err: %v\n", err) + return + } + url := "/api/comment" + req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata)) + if err != nil { + fmt.Printf("err: %v\n", err) + return + } + if req.StatusCode == 200 { + p.Update() + } + defer req.Body.Close() }, - app.If(p.showGuestbook, gbp), - ).Class("main"), - ) + }, + //app.If(p.showGuestbook, gbp), + gbp.Render(), + ).Class("main") } diff --git a/components/navbar.go b/components/navbar.go index 6cd6463..ba9fdb0 100644 --- a/components/navbar.go +++ b/components/navbar.go @@ -4,10 +4,8 @@ import "github.com/maxence-charriere/go-app/v9/pkg/app" type navbar struct { app.Compo -} -func newNavbar() *navbar { - return &navbar{} + OnClickButton func(page string) } func (n *navbar) Render() app.UI { @@ -19,6 +17,9 @@ func (n *navbar) Render() app.UI { app.Li().Body( app.A().Href("/about").Text("About"), ), + app.Li().Body( + app.A().Href("/friends").Text("Friends"), + ), ), ).Class("navbar") } diff --git a/main.go b/main.go index 2fd1d63..d61fbf7 100644 --- a/main.go +++ b/main.go @@ -22,8 +22,10 @@ type application struct { func main() { homepage := components.NewHomepage() aboutpage := components.NewAboutPage() + friendspage := components.NewFriendsPage() app.Route("/", homepage) app.Route("/about", aboutpage) + app.Route("/friends", friendspage) // This is executed on the client side only. // It handles client side stuff diff --git a/web/static/style.css b/web/static/style.css index 77d564d..f4d2708 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -69,6 +69,21 @@ body { 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 { font-family: anisha; font-size: 3em;