caret

[ACTIVE] a command line tool for browsing Lobsters in your terminal
git clone git://git.figbert.com/caret.git
Log | Files | Refs | README | LICENSE

commit ecefaa6c180930ffe10c71bcf633bcf19df53875
parent da39c5877ec49f7e203f5de886087986fc37eb53
Author: FIGBERT <figbert@figbert.com>
Date:   Mon,  4 Sep 2023 22:52:45 -0700

Fetch additional pages when the end is reached

Diffstat:
Mmain.go | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/main.go b/main.go @@ -22,6 +22,8 @@ func (m model) Init() tea.Cmd { } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + var cmds []tea.Cmd + if dimension, ok := msg.(tea.WindowSizeMsg); ok { m.width = dimension.Width m.height = dimension.Height @@ -31,17 +33,24 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch key.String() { case "ctrl+c": return m, tea.Quit + case "j": + if m.posts.Index() == len(m.posts.Items())-1 { + m.page++ + cmds = append(cmds, api.FetchPage(m.page)) + } + fallthrough default: var cmd tea.Cmd m.posts, cmd = m.posts.Update(msg) - return m, cmd + cmds = append(cmds, cmd) } } else if psts, ok := msg.(api.PageMsg); ok { for _, pst := range []api.Post(psts) { m.posts.SetItems(append(m.posts.Items(), item{post: pst})) } } - return m, nil + + return m, tea.Batch(cmds...) } func (m model) View() string {