From 69c6c50ccc5ef54412d05b63cad63cc5fa767580 Mon Sep 17 00:00:00 2001 From: DutchEllie Date: Fri, 25 Mar 2022 14:02:14 +0100 Subject: [PATCH] Guestbook loading still broken --- src/guestbook.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/guestbook.go b/src/guestbook.go index 8a2febd..09b2738 100644 --- a/src/guestbook.go +++ b/src/guestbook.go @@ -33,6 +33,7 @@ type guestbook struct { // TODO: The comments are loaded like 2 or 3 times every time the page is loaded... func (g *guestbook) OnMount(ctx app.Context) { + ctx.Handle("guestbook-loadcomments", g.onHandleLoadComments) g.LoadComments(ctx) } @@ -138,7 +139,8 @@ func (g guestbook) Render() app.UI { ctx.Dispatch(func(ctx app.Context) { g.clear() }) - g.LoadComments(ctx) + ctx.NewAction("guestbook-loadcomments") + //g.LoadComments(ctx) }), app.If( g.gbModalOpen, @@ -162,6 +164,7 @@ func (g guestbook) Render() app.UI { func (g *guestbook) LoadComments(ctx app.Context) { // TODO: maybe you can put this in a localbrowser storage? + fmt.Printf("Called LoadComments()\n") url := ApiURL + "/comment" ctx.Async(func() { res, err := http.Get(url) @@ -191,6 +194,13 @@ func (g *guestbook) clear() { g.message = "" } +func (g *guestbook) onHandleLoadComments(ctx app.Context, a app.Action) { + g.LoadComments(ctx) + ctx.Dispatch(func(ctx app.Context) { + g.Update() + }) +} + type guestbookAlertModal struct { app.Compo