From 675bfa1fb56680cb8b20ca89538e8a913d8df015 Mon Sep 17 00:00:00 2001 From: Ivan Danyliuk Date: Fri, 16 Nov 2018 16:53:03 +0100 Subject: [PATCH] Add primitive loader --- cmd/txqr-tester/app/app.go | 10 ++++++++-- cmd/txqr-tester/app/loader.go | 17 +++++++++++++++++ cmd/txqr-tester/app/qr.go | 7 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 cmd/txqr-tester/app/loader.go diff --git a/cmd/txqr-tester/app/app.go b/cmd/txqr-tester/app/app.go index 7dad5f6..cf12d4d 100644 --- a/cmd/txqr-tester/app/app.go +++ b/cmd/txqr-tester/app/app.go @@ -24,8 +24,9 @@ type App struct { connected bool - testData []byte - animatingQR []byte + testData []byte + animatingQR []byte + generatingQR bool } // NewApp creates and inits new app page. @@ -105,6 +106,9 @@ func (a *App) SetConnected(val bool) { // ShowNext handles request to show next animated QR. func (a *App) ShowNext() { + a.generatingQR = true + vecty.Rerender(a) + time.Sleep(100 * time.Millisecond) // wait till JS thread pickup rerender before running heavy computaiton. withoit this delay it'll never rerender setup, _ := a.session.StartNext() log.Println("Creating animated gif for", setup) now := time.Now() @@ -112,11 +116,13 @@ func (a *App) ShowNext() { if err != nil { log.Println("[ERROR] Can't generate gif: %v", err) // TODO: session abort + a.generatingQR = false return } log.Println("Took time:", time.Since(now)) a.animatingQR = gif a.session.SetState(StateAnimating) + a.generatingQR = false vecty.Rerender(a) } diff --git a/cmd/txqr-tester/app/loader.go b/cmd/txqr-tester/app/loader.go new file mode 100644 index 0000000..0fc0d9c --- /dev/null +++ b/cmd/txqr-tester/app/loader.go @@ -0,0 +1,17 @@ +package main + +import ( + "github.com/gopherjs/vecty" + "github.com/gopherjs/vecty/elem" +) + +func loader() *vecty.HTML { + return elem.Div( + vecty.Markup( + vecty.Class("title", "has-text-weight-light"), + ), + elem.Heading1( + vecty.Text("Generating..."), + ), + ) +} diff --git a/cmd/txqr-tester/app/qr.go b/cmd/txqr-tester/app/qr.go index b9aee2d..752e101 100644 --- a/cmd/txqr-tester/app/qr.go +++ b/cmd/txqr-tester/app/qr.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "github.com/divan/txqr/qr" "github.com/gopherjs/vecty" @@ -75,6 +76,12 @@ func (a *App) startQR() vecty.ComponentOrHTML { func (a *App) mainQR() vecty.ComponentOrHTML { state := a.session.State() + + log.Println("MainQR: generatingQR", a.generatingQR) + if a.generatingQR { + return loader() + } + if state == StateAnimating { return renderGIF(a.animatingQR) } else if state == StateStarted || state == StateWaitingNext || state == StateNew {