Skip to content

Commit

Permalink
Add modal loading
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptonist committed Jan 14, 2019
1 parent e2b0b35 commit 793f2d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/posts/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ func GetNews() {
}

list := tview.NewList()
list.Box.SetBorder(true)

app := tview.NewApplication()

for ind, post := range posts.Posts {

list = list.AddItem(post.Title, post.Brief, rune(strconv.Itoa(ind)[0]), nil)
}

Expand All @@ -53,7 +54,7 @@ func GetNews() {
app.Stop()
panic(err)
}

list.Box.Blur()
openPost(app, posts.Posts[n].Cuid, list)

}
Expand Down
14 changes: 10 additions & 4 deletions pkg/posts/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
textView.SetBorder(true)

go func() {
if err := app.SetRoot(textView, true).SetFocus(textView).Run(); err != nil {
}()

modal := tview.NewModal().SetText("Loading....")
go func() {
if err := app.SetRoot(modal, false).SetFocus(modal).Run(); err != nil {
app.Stop()
panic(err)
}
}()

var singlePost Post
textView.Write([]byte("[:green:l]Loading....[-:-:-]"))
b, err := makeRequest(fmt.Sprintf("%s/%s", postAPI, postcuid))
if err != nil {
app.Stop()
log.Fatal(err)
}
textView.Clear()

err = json.Unmarshal(b, &singlePost)
if err != nil {
Expand Down Expand Up @@ -101,7 +103,6 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
}

}
textView.ScrollToBeginning()

textView.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEscape {
Expand All @@ -112,6 +113,11 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
}
})

if err := app.SetRoot(textView, true).SetFocus(textView).Run(); err != nil {
app.Stop()
panic(err)
}

}

func writeToTextView(t *tview.TextView, contents ...string) {
Expand Down

0 comments on commit 793f2d2

Please sign in to comment.