albums and artists browsing
This commit is contained in:
parent
c9f75e1d2a
commit
d878854876
@ -44,6 +44,7 @@ type mainModel struct {
|
|||||||
playlist spotify.SimplePlaylist
|
playlist spotify.SimplePlaylist
|
||||||
artist spotify.SimpleArtist
|
artist spotify.SimpleArtist
|
||||||
album spotify.SimpleAlbum
|
album spotify.SimpleAlbum
|
||||||
|
fromArtist bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mainModel) Init() tea.Cmd {
|
func (m mainModel) Init() tea.Cmd {
|
||||||
@ -293,7 +294,51 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.NewStatusMessage("Setting view to devices")
|
m.list.NewStatusMessage("Setting view to devices")
|
||||||
}
|
}
|
||||||
if msg.String() == "backspace" || msg.String() == "esc" || msg.String() == "q" {
|
if msg.String() == "backspace" || msg.String() == "esc" || msg.String() == "q" {
|
||||||
if m.mode != "main" {
|
if m.mode == "album" {
|
||||||
|
if m.fromArtist {
|
||||||
|
m.mode = "albums"
|
||||||
|
m.fromArtist = true
|
||||||
|
m.list.NewStatusMessage("Opening " + m.artist.Name)
|
||||||
|
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
m.list.ResetSelected()
|
||||||
|
} else {
|
||||||
|
m.mode = "albums"
|
||||||
|
m.list.NewStatusMessage("Setting view to albums")
|
||||||
|
new_items, err := AlbumsView(m.ctx, m.client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
m.list.ResetSelected()
|
||||||
|
}
|
||||||
|
} else if m.mode == "albums" {
|
||||||
|
if m.fromArtist {
|
||||||
|
m.mode = "artists"
|
||||||
|
m.fromArtist = false
|
||||||
|
m.list.NewStatusMessage("Setting view to artists")
|
||||||
|
new_items, err := ArtistsView(m.ctx, m.client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
m.list.ResetSelected()
|
||||||
|
} else {
|
||||||
|
m.mode = "main"
|
||||||
|
m.list.NewStatusMessage("Setting view to main")
|
||||||
|
new_items, err := MainView(m.ctx, m.client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
}
|
||||||
|
} else if m.mode != "main" {
|
||||||
m.mode = "main"
|
m.mode = "main"
|
||||||
m.list.NewStatusMessage("Setting view to main")
|
m.list.NewStatusMessage("Setting view to main")
|
||||||
new_items, err := MainView(m.ctx, m.client)
|
new_items, err := MainView(m.ctx, m.client)
|
||||||
@ -371,6 +416,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case "artists":
|
case "artists":
|
||||||
m.mode = "albums"
|
m.mode = "albums"
|
||||||
|
m.fromArtist = true
|
||||||
m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist)
|
m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist)
|
||||||
m.list.NewStatusMessage("Opening " + m.artist.Name)
|
m.list.NewStatusMessage("Opening " + m.artist.Name)
|
||||||
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client)
|
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client)
|
||||||
@ -655,7 +701,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
|
|||||||
SpotifyItem: albums,
|
SpotifyItem: albums,
|
||||||
})
|
})
|
||||||
items = append(items, mainItem{
|
items = append(items, mainItem{
|
||||||
Name: "Albums",
|
Name: "Artists",
|
||||||
Desc: fmt.Sprintf("%d artists", artists.Total),
|
Desc: fmt.Sprintf("%d artists", artists.Total),
|
||||||
SpotifyItem: artists,
|
SpotifyItem: artists,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user