Okay this is based
This commit is contained in:
parent
e92d0f2c26
commit
c10a995b63
|
@ -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{},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
|
@ -47,7 +47,6 @@ func (g *guestbookForm) Render() app.UI {
|
|||
}
|
||||
g.OnSubmit(g.name, g.message)
|
||||
g.clear()
|
||||
g.Update()
|
||||
}),
|
||||
).Class("content")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
2
main.go
2
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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue