browse: loading and refreshing

This commit is contained in:
aoife cassidy 2026-01-22 16:33:34 +01:00
parent 30ace2df9b
commit faa120bd99
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
4 changed files with 54 additions and 3 deletions

View File

@ -0,0 +1,2 @@
patch type="added" "loading indicator on browse"
patch type="added" "refresh button on browse"

View File

@ -36,7 +36,7 @@ func NewBrowse() *Browse {
return &Browse{ return &Browse{
title, title,
ui.NewList(list, 0), ui.NewList(list, 0),
"↑↓/kj move ↵ enter q return", "↑↓/kj move ↵ enter r refresh q return",
posts, posts,
} }
} }
@ -57,6 +57,16 @@ func (browse *Browse) Event(state *ui.State, event vaxis.Event) (processed bool)
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9": case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
i, _ := strconv.Atoi(key.String()) i, _ := strconv.Atoi(key.String())
browse.list.SetIndex(i) browse.list.SetIndex(i)
case "r":
ready := false
go func() {
b := NewBrowse()
ready = true
ui.ViewChange <- b
}()
if !ready {
ui.ViewChange <- NewLoading("refreshing entries…")
}
case "q", "h", "Left": case "q", "h", "Left":
ui.ViewChange <- NewMainMenu(3) ui.ViewChange <- NewMainMenu(3)
case "Enter", "l", "Right": case "Enter", "l", "Right":
@ -79,5 +89,5 @@ func (browse *Browse) Draw(state *ui.State) {
Width: 50, Width: 50,
Height: 10, Height: 10,
}) })
win.New(win.Width/2-15, win.Height/2+9, 30, 1).Print(vaxis.Segment{Text: browse.help}) win.New(win.Width/2-20, win.Height/2+9, 41, 1).Print(vaxis.Segment{Text: browse.help})
} }

31
app/loading.go Normal file
View File

@ -0,0 +1,31 @@
package app
import (
"git.sr.ht/~rockorager/vaxis"
"git.tilde.town/nbsp/neofeels/ui"
)
type Loading struct {
title string
text string
}
func NewLoading(text string) *Loading {
return &Loading{title, text}
}
func (loading *Loading) Event(state *ui.State, event vaxis.Event) (processed bool) {
if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
switch key.String() {
case "Ctrl+c", "Ctrl+d":
close(ui.Quit)
case "Enter", "q", "h", "l", "Left", "Right":
ui.ViewChange <- NewMainMenu(3)
}
processed = true
}
win := state.Window()
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: loading.title})
win.New((win.Width-len(loading.text))/2, win.Height/2-2, len(loading.text), 2).Print(vaxis.Segment{Text: loading.text})
return
}

View File

@ -120,7 +120,15 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool)
case 2: case 2:
ui.ViewChange <- NewNeighbors(0) ui.ViewChange <- NewNeighbors(0)
case 3: case 3:
ui.ViewChange <- NewBrowse() ready := false
go func() {
b := NewBrowse()
ready = true
ui.ViewChange <- b
}()
if !ready {
ui.ViewChange <- NewLoading("loading entries…")
}
case 4: case 4:
ui.ViewChange <- NewSubscriptions(0) ui.ViewChange <- NewSubscriptions(0)
case 5: case 5: