Skip to content

Commit 793f2d2

Browse files
committed
Add modal loading
1 parent e2b0b35 commit 793f2d2

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pkg/posts/news.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ func GetNews() {
3434
}
3535

3636
list := tview.NewList()
37+
list.Box.SetBorder(true)
38+
3739
app := tview.NewApplication()
3840

3941
for ind, post := range posts.Posts {
40-
4142
list = list.AddItem(post.Title, post.Brief, rune(strconv.Itoa(ind)[0]), nil)
4243
}
4344

@@ -53,7 +54,7 @@ func GetNews() {
5354
app.Stop()
5455
panic(err)
5556
}
56-
57+
list.Box.Blur()
5758
openPost(app, posts.Posts[n].Cuid, list)
5859

5960
}

pkg/posts/post.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ func openPost(app *tview.Application, postcuid string, list *tview.List) {
2828
textView.SetBorder(true)
2929

3030
go func() {
31-
if err := app.SetRoot(textView, true).SetFocus(textView).Run(); err != nil {
31+
}()
32+
33+
modal := tview.NewModal().SetText("Loading....")
34+
go func() {
35+
if err := app.SetRoot(modal, false).SetFocus(modal).Run(); err != nil {
3236
app.Stop()
3337
panic(err)
3438
}
3539
}()
3640

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

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

103105
}
104-
textView.ScrollToBeginning()
105106

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

116+
if err := app.SetRoot(textView, true).SetFocus(textView).Run(); err != nil {
117+
app.Stop()
118+
panic(err)
119+
}
120+
115121
}
116122

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

0 commit comments

Comments
 (0)