fix loadmoreitems being called a billion times
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
abs3nt 2023-04-14 19:45:59 -07:00
parent ec60177128
commit c124ec4eb9
Signed by: abs3nt
GPG Key ID: FDC6662313FA9386
2 changed files with 6 additions and 8 deletions

View File

@ -8,10 +8,13 @@ import (
) )
func (m *mainModel) LoadMoreItems() { func (m *mainModel) LoadMoreItems() {
loading = true
defer func() {
loading = false
}()
switch m.mode { switch m.mode {
case "artist": case "artist":
albums, err := m.commands.ArtistAlbums(m.ctx, m.artist.ID, (page + 1)) albums, err := m.commands.ArtistAlbums(m.ctx, m.artist.ID, (page + 1))
page++
if err != nil { if err != nil {
return return
} }
@ -31,7 +34,6 @@ func (m *mainModel) LoadMoreItems() {
return return
case "artists": case "artists":
artists, err := m.commands.UserArtists(m.ctx, (page + 1)) artists, err := m.commands.UserArtists(m.ctx, (page + 1))
page++
if err != nil { if err != nil {
return return
} }
@ -51,7 +53,6 @@ func (m *mainModel) LoadMoreItems() {
return return
case "album": case "album":
tracks, err := m.commands.AlbumTracks(m.ctx, m.album.ID, (page + 1)) tracks, err := m.commands.AlbumTracks(m.ctx, m.album.ID, (page + 1))
page++
if err != nil { if err != nil {
return return
} }
@ -72,7 +73,6 @@ func (m *mainModel) LoadMoreItems() {
return return
case "albums": case "albums":
albums, err := m.commands.UserAlbums(m.ctx, (page + 1)) albums, err := m.commands.UserAlbums(m.ctx, (page + 1))
page++
if err != nil { if err != nil {
return return
} }
@ -92,7 +92,6 @@ func (m *mainModel) LoadMoreItems() {
return return
case "main": case "main":
playlists, err := m.commands.Playlists(m.ctx, (page + 1)) playlists, err := m.commands.Playlists(m.ctx, (page + 1))
page++
if err != nil { if err != nil {
return return
} }
@ -111,7 +110,6 @@ func (m *mainModel) LoadMoreItems() {
return return
case "playlist": case "playlist":
tracks, err := m.commands.PlaylistTracks(m.ctx, m.playlist.ID, (page + 1)) tracks, err := m.commands.PlaylistTracks(m.ctx, m.playlist.ID, (page + 1))
page++
if err != nil { if err != nil {
return return
} }
@ -132,7 +130,6 @@ func (m *mainModel) LoadMoreItems() {
return return
case "tracks": case "tracks":
tracks, err := m.commands.TrackList(m.ctx, (page + 1)) tracks, err := m.commands.TrackList(m.ctx, (page + 1))
page++
if err != nil { if err != nil {
return return
} }

View File

@ -25,6 +25,7 @@ var (
playbackContext string playbackContext string
main_updates chan *mainModel main_updates chan *mainModel
page = 1 page = 1
loading = false
) )
type Mode string type Mode string
@ -512,7 +513,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
default: default:
} }
// Call for more items if needed // Call for more items if needed
if m.list.Paginator.Page == m.list.Paginator.TotalPages-1 && m.list.Cursor() == 0 { if m.list.Paginator.Page == m.list.Paginator.TotalPages-1 && m.list.Cursor() == 0 && !loading {
// if last request was still full request more // if last request was still full request more
if len(m.list.Items())%50 == 0 { if len(m.list.Items())%50 == 0 {
go m.LoadMoreItems() go m.LoadMoreItems()