better state handling
This commit is contained in:
parent
c52bbd3d48
commit
1c7249cbca
@ -22,6 +22,29 @@ var (
|
|||||||
page = 1
|
page = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Mode string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Album Mode = "album"
|
||||||
|
ArtistAlbum = "artistalbum"
|
||||||
|
Artist = "artist"
|
||||||
|
Artists = "artists"
|
||||||
|
Tracks = "tracks"
|
||||||
|
Albums = "albums"
|
||||||
|
Main = "main"
|
||||||
|
Playlists = "playlists"
|
||||||
|
Playlist = "playlist"
|
||||||
|
Devices = "devices"
|
||||||
|
Search = "search"
|
||||||
|
SearchAlbums = "searchalbums"
|
||||||
|
SearchArtists = "searchartists"
|
||||||
|
SearchTracks = "searchtracks"
|
||||||
|
SearchPlaylists = "searchplaylsits"
|
||||||
|
SearchArtist = "searchartist"
|
||||||
|
SearchPlaylist = "searchplaylist"
|
||||||
|
SearchAlbum = "searchalbum"
|
||||||
|
)
|
||||||
|
|
||||||
type mainItem struct {
|
type mainItem struct {
|
||||||
Name string
|
Name string
|
||||||
Duration string
|
Duration string
|
||||||
@ -40,7 +63,7 @@ type mainModel struct {
|
|||||||
input textinput.Model
|
input textinput.Model
|
||||||
ctx *gctx.Context
|
ctx *gctx.Context
|
||||||
client *spotify.Client
|
client *spotify.Client
|
||||||
mode string
|
mode Mode
|
||||||
playlist spotify.SimplePlaylist
|
playlist spotify.SimplePlaylist
|
||||||
artist spotify.SimpleArtist
|
artist spotify.SimpleArtist
|
||||||
album spotify.SimpleAlbum
|
album spotify.SimpleAlbum
|
||||||
@ -48,6 +71,76 @@ type mainModel struct {
|
|||||||
fromArtist bool
|
fromArtist bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mainModel) GoBack() (tea.Cmd, error) {
|
||||||
|
switch m.mode {
|
||||||
|
case Main:
|
||||||
|
return tea.Quit, nil
|
||||||
|
case Albums, Artists, Tracks, Playlist, Devices, Search:
|
||||||
|
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)
|
||||||
|
|
||||||
|
case Album:
|
||||||
|
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 nil, err
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
m.list.ResetSelected()
|
||||||
|
|
||||||
|
case Artist:
|
||||||
|
m.mode = Artists
|
||||||
|
m.fromArtist = false
|
||||||
|
m.list.NewStatusMessage("Setting view to artists")
|
||||||
|
new_items, err := ArtistsView(m.ctx, m.client)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
m.list.ResetSelected()
|
||||||
|
|
||||||
|
case ArtistAlbum:
|
||||||
|
m.mode = Artist
|
||||||
|
m.fromArtist = true
|
||||||
|
m.list.NewStatusMessage("Opening " + m.artist.Name)
|
||||||
|
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
m.list.ResetSelected()
|
||||||
|
|
||||||
|
case SearchArtists, SearchTracks, SearchAlbums, SearchPlaylists:
|
||||||
|
m.mode = Search
|
||||||
|
m.list.NewStatusMessage("Setting view to search for " + m.input.Value())
|
||||||
|
items, err := SearchView(m.ctx, m.client, m.search)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m.list.SetItems(items)
|
||||||
|
case SearchArtist:
|
||||||
|
m.mode = SearchArtists
|
||||||
|
|
||||||
|
case SearchAlbum:
|
||||||
|
m.mode = SearchAlbums
|
||||||
|
|
||||||
|
case SearchPlaylist:
|
||||||
|
m.mode = SearchPlaylists
|
||||||
|
|
||||||
|
default:
|
||||||
|
m.list.ResetSelected()
|
||||||
|
page = 0
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m mainModel) Init() tea.Cmd {
|
func (m mainModel) Init() tea.Cmd {
|
||||||
main_updates = make(chan *mainModel)
|
main_updates = make(chan *mainModel)
|
||||||
return nil
|
return nil
|
||||||
@ -133,7 +226,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
if msg.String() == "d" {
|
if msg.String() == "d" {
|
||||||
if !m.input.Focused() {
|
if !m.input.Focused() {
|
||||||
m.mode = "devices"
|
m.mode = Devices
|
||||||
new_items, err := DeviceView(m.ctx, m.client)
|
new_items, err := DeviceView(m.ctx, m.client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
@ -145,68 +238,17 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msg.String() == "backspace" || msg.String() == "esc" || msg.String() == "q" {
|
if msg.String() == "backspace" || msg.String() == "esc" || msg.String() == "q" {
|
||||||
if m.mode == "album" {
|
msg, err := m.GoBack()
|
||||||
if m.fromArtist {
|
if err != nil {
|
||||||
m.mode = "albums"
|
fmt.Println(err)
|
||||||
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.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 {
|
|
||||||
return m, tea.Quit
|
|
||||||
}
|
}
|
||||||
m.list.ResetSelected()
|
return m, msg
|
||||||
page = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.String() == "enter" || msg.String() == "spacebar" {
|
if msg.String() == "enter" || msg.String() == "spacebar" {
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case "searchartists":
|
case SearchArtists:
|
||||||
m.mode = "albums"
|
m.mode = SearchArtist
|
||||||
m.fromArtist = true
|
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)
|
||||||
@ -217,8 +259,8 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case "searchalbums":
|
case SearchAlbums:
|
||||||
m.mode = "album"
|
m.mode = SearchAlbum
|
||||||
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
||||||
m.list.NewStatusMessage("Opening " + m.album.Name)
|
m.list.NewStatusMessage("Opening " + m.album.Name)
|
||||||
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client)
|
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client)
|
||||||
@ -228,8 +270,8 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case "searchplaylists":
|
case SearchPlaylists:
|
||||||
m.mode = "playlist"
|
m.mode = SearchPlaylist
|
||||||
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
||||||
m.playlist = playlist
|
m.playlist = playlist
|
||||||
m.list.NewStatusMessage("Setting view to playlist " + playlist.Name)
|
m.list.NewStatusMessage("Setting view to playlist " + playlist.Name)
|
||||||
@ -240,14 +282,10 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case "searchtracks":
|
case Search:
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
|
||||||
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
|
||||||
go HandleRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).ID)
|
|
||||||
case "search":
|
|
||||||
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
||||||
case *spotify.FullArtistPage:
|
case *spotify.FullArtistPage:
|
||||||
m.mode = "searchartists"
|
m.mode = SearchArtists
|
||||||
m.list.NewStatusMessage("Setting view to artists")
|
m.list.NewStatusMessage("Setting view to artists")
|
||||||
new_items, err := SearchArtistsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullArtistPage))
|
new_items, err := SearchArtistsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullArtistPage))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -257,7 +295,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.SimpleAlbumPage:
|
case *spotify.SimpleAlbumPage:
|
||||||
m.mode = "searchalbums"
|
m.mode = SearchAlbums
|
||||||
m.list.NewStatusMessage("Setting view to albums")
|
m.list.NewStatusMessage("Setting view to albums")
|
||||||
new_items, err := SearchAlbumsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimpleAlbumPage))
|
new_items, err := SearchAlbumsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimpleAlbumPage))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -267,7 +305,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.SimplePlaylistPage:
|
case *spotify.SimplePlaylistPage:
|
||||||
m.mode = "searchplaylists"
|
m.mode = SearchPlaylists
|
||||||
playlists := m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimplePlaylistPage)
|
playlists := m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimplePlaylistPage)
|
||||||
m.list.NewStatusMessage("Setting view to playlist")
|
m.list.NewStatusMessage("Setting view to playlist")
|
||||||
new_items, err := SearchPlaylistsView(m.ctx, m.client, playlists)
|
new_items, err := SearchPlaylistsView(m.ctx, m.client, playlists)
|
||||||
@ -278,7 +316,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.FullTrackPage:
|
case *spotify.FullTrackPage:
|
||||||
m.mode = "searchtracks"
|
m.mode = SearchTracks
|
||||||
m.list.NewStatusMessage("Setting view to tracks")
|
m.list.NewStatusMessage("Setting view to tracks")
|
||||||
new_items, err := SearchTracksView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullTrackPage))
|
new_items, err := SearchTracksView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullTrackPage))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -292,7 +330,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case "main":
|
case "main":
|
||||||
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
||||||
case *spotify.FullArtistCursorPage:
|
case *spotify.FullArtistCursorPage:
|
||||||
m.mode = "artists"
|
m.mode = Artists
|
||||||
m.list.NewStatusMessage("Setting view to artists")
|
m.list.NewStatusMessage("Setting view to artists")
|
||||||
new_items, err := ArtistsView(m.ctx, m.client)
|
new_items, err := ArtistsView(m.ctx, m.client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -302,7 +340,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.SavedAlbumPage:
|
case *spotify.SavedAlbumPage:
|
||||||
m.mode = "albums"
|
m.mode = Albums
|
||||||
m.list.NewStatusMessage("Setting view to albums")
|
m.list.NewStatusMessage("Setting view to albums")
|
||||||
new_items, err := AlbumsView(m.ctx, m.client)
|
new_items, err := AlbumsView(m.ctx, m.client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -312,7 +350,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case spotify.SimplePlaylist:
|
case spotify.SimplePlaylist:
|
||||||
m.mode = "playlist"
|
m.mode = Playlist
|
||||||
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
|
||||||
m.playlist = playlist
|
m.playlist = playlist
|
||||||
m.list.NewStatusMessage("Setting view to playlist " + playlist.Name)
|
m.list.NewStatusMessage("Setting view to playlist " + playlist.Name)
|
||||||
@ -324,7 +362,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case *spotify.SavedTrackPage:
|
case *spotify.SavedTrackPage:
|
||||||
m.mode = "tracks"
|
m.mode = Tracks
|
||||||
m.list.NewStatusMessage("Setting view to saved tracks")
|
m.list.NewStatusMessage("Setting view to saved tracks")
|
||||||
new_items, err := SavedTracksView(m.ctx, m.client)
|
new_items, err := SavedTracksView(m.ctx, m.client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -335,8 +373,8 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
m.list.NewStatusMessage("Setting view to tracks")
|
m.list.NewStatusMessage("Setting view to tracks")
|
||||||
}
|
}
|
||||||
case "albums":
|
case Albums:
|
||||||
m.mode = "album"
|
m.mode = Album
|
||||||
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
||||||
m.list.NewStatusMessage("Opening " + m.album.Name)
|
m.list.NewStatusMessage("Opening " + m.album.Name)
|
||||||
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client)
|
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client)
|
||||||
@ -346,8 +384,19 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case "artists":
|
case Artist:
|
||||||
m.mode = "albums"
|
m.mode = ArtistAlbum
|
||||||
|
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
|
||||||
|
m.list.NewStatusMessage("Opening " + m.album.Name)
|
||||||
|
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
|
m.list.SetItems(new_items)
|
||||||
|
m.list.ResetSelected()
|
||||||
|
case Artists:
|
||||||
|
m.mode = Artist
|
||||||
m.fromArtist = true
|
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)
|
||||||
@ -358,19 +407,19 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.list.SetItems(new_items)
|
m.list.SetItems(new_items)
|
||||||
m.list.ResetSelected()
|
m.list.ResetSelected()
|
||||||
case "album":
|
case Album, ArtistAlbum:
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
||||||
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
||||||
go HandlePlay(m.ctx, m.client, &m.album.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.TotalPages))
|
go HandlePlay(m.ctx, m.client, &m.album.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.TotalPages))
|
||||||
case "playlist":
|
case Playlist, SearchPlaylist:
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
||||||
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
||||||
go HandlePlay(m.ctx, m.client, &m.playlist.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
|
go HandlePlay(m.ctx, m.client, &m.playlist.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
|
||||||
case "tracks":
|
case Tracks, SearchTracks:
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
||||||
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
||||||
go HandlePlayLikedSong(m.ctx, m.client, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
|
go HandlePlayLikedSong(m.ctx, m.client, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
|
||||||
case "devices":
|
case Devices:
|
||||||
go HandleSetDevice(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.PlayerDevice))
|
go HandleSetDevice(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.PlayerDevice))
|
||||||
m.list.NewStatusMessage("Setting device to " + m.list.SelectedItem().FilterValue())
|
m.list.NewStatusMessage("Setting device to " + m.list.SelectedItem().FilterValue())
|
||||||
m.mode = "main"
|
m.mode = "main"
|
||||||
@ -383,31 +432,20 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msg.String() == "ctrl+r" {
|
if msg.String() == "ctrl+r" {
|
||||||
switch m.mode {
|
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
||||||
case "main":
|
case spotify.SimplePlaylist:
|
||||||
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
|
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
||||||
case spotify.SimplePlaylist:
|
m.list.NewStatusMessage("Starting radio for " + currentlyPlaying)
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
go HandlePlaylistRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist))
|
||||||
m.list.NewStatusMessage("Starting radio for " + currentlyPlaying)
|
case *spotify.SavedTrackPage:
|
||||||
go HandlePlaylistRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist))
|
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
||||||
case *spotify.SavedTrackPage:
|
m.list.NewStatusMessage("Starting radio for " + currentlyPlaying)
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
go HandleLibraryRadio(m.ctx, m.client)
|
||||||
m.list.NewStatusMessage("Starting radio for " + currentlyPlaying)
|
case *spotify.SimpleAlbum, *spotify.FullAlbum:
|
||||||
go HandleLibraryRadio(m.ctx, m.client)
|
|
||||||
}
|
|
||||||
case "albums":
|
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
||||||
m.list.NewStatusMessage("Stating radio for" + currentlyPlaying)
|
m.list.NewStatusMessage("Stating radio for" + currentlyPlaying)
|
||||||
go HandleAlbumRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum).ID)
|
go HandleAlbumRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum).ID)
|
||||||
case "album":
|
default:
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
|
||||||
m.list.NewStatusMessage("Stating radio for" + currentlyPlaying)
|
|
||||||
go HandleRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).ID)
|
|
||||||
case "playlist":
|
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
|
||||||
m.list.NewStatusMessage("Starting radio for " + currentlyPlaying)
|
|
||||||
go HandleRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).ID)
|
|
||||||
case "tracks":
|
|
||||||
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
currentlyPlaying = m.list.SelectedItem().FilterValue()
|
||||||
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
||||||
go HandleRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).ID)
|
go HandleRadio(m.ctx, m.client, m.list.SelectedItem().(mainItem).ID)
|
||||||
@ -429,7 +467,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitMain(ctx *gctx.Context, client *spotify.Client, mode string) (tea.Model, error) {
|
func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model, error) {
|
||||||
playing, _ := client.PlayerCurrentlyPlaying(ctx)
|
playing, _ := client.PlayerCurrentlyPlaying(ctx)
|
||||||
if playing.Playing {
|
if playing.Playing {
|
||||||
currentlyPlaying = "Now playing " + playing.Item.Name + " by " + playing.Item.Artists[0].Name
|
currentlyPlaying = "Now playing " + playing.Item.Name + " by " + playing.Item.Artists[0].Name
|
||||||
@ -437,17 +475,17 @@ func InitMain(ctx *gctx.Context, client *spotify.Client, mode string) (tea.Model
|
|||||||
items := []list.Item{}
|
items := []list.Item{}
|
||||||
var err error
|
var err error
|
||||||
switch mode {
|
switch mode {
|
||||||
case "main":
|
case Main:
|
||||||
items, err = MainView(ctx, client)
|
items, err = MainView(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case "devices":
|
case Devices:
|
||||||
items, err = DeviceView(ctx, client)
|
items, err = DeviceView(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case "tracks":
|
case Tracks:
|
||||||
items, err = SavedTracksView(ctx, client)
|
items, err = SavedTracksView(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// StartTea the entry point for the UI. Initializes the model.
|
// StartTea the entry point for the UI. Initializes the model.
|
||||||
func StartTea(ctx *gctx.Context, client *spotify.Client, mode string) error {
|
func StartTea(ctx *gctx.Context, client *spotify.Client, mode string) error {
|
||||||
m, err := InitMain(ctx, client, mode)
|
m, err := InitMain(ctx, client, Mode(mode))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("UH OH")
|
fmt.Println("UH OH")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user