Files
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

67 lines
1.7 KiB
Go

package model
import (
tea "charm.land/bubbletea/v2"
"github.com/bjarneo/cliamp/provider"
)
// maybeLoadCatalogBatch triggers a catalog batch fetch when the cursor is near the
// bottom of the provider list and more entries are available.
func (m *Model) maybeLoadCatalogBatch() tea.Cmd {
loader, ok := m.provider.(provider.CatalogLoader)
if !ok {
return nil
}
if m.catalogBatch.loading || m.catalogBatch.done {
return nil
}
if cs, ok := m.provider.(provider.CatalogSearcher); ok && cs.IsSearching() {
return nil
}
if m.provCursor >= len(m.providerLists)-10 {
m.catalogBatch.loading = true
return fetchCatalogBatchCmd(loader, m.catalogBatch.offset, catalogBatchSize)
}
return nil
}
// toggleProviderFavorite toggles favorite status for the current entry in the
// provider list (only works for providers implementing FavoriteToggler + SectionedList).
func (m *Model) toggleProviderFavorite() tea.Cmd {
ft, ok := m.provider.(provider.FavoriteToggler)
if !ok || len(m.providerLists) == 0 {
return nil
}
id := m.providerLists[m.provCursor].ID
if sl, ok := m.provider.(provider.SectionedList); ok {
if !sl.IsFavoritableID(id) {
return nil
}
}
added, name, err := ft.ToggleFavorite(id)
if err != nil {
return nil
}
if added {
m.status.Showf(statusTTLMedium, "Favorited: %s", name)
} else {
m.status.Showf(statusTTLMedium, "Removed: %s", name)
}
prevID := id
if lists, err := m.provider.Playlists(); err == nil {
m.providerLists = lists
for i, p := range m.providerLists {
if p.ID == prevID {
m.provCursor = i
return nil
}
}
if m.provCursor >= len(m.providerLists) {
m.provCursor = max(0, len(m.providerLists)-1)
}
}
return nil
}