clean
This commit is contained in:
parent
c3ebf8a792
commit
7066d6970a
@ -1,52 +0,0 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/zmb3/spotify"
|
||||
)
|
||||
|
||||
var (
|
||||
P *tea.Program
|
||||
|
||||
Client *spotify.Client
|
||||
|
||||
WindowSize tea.WindowSizeMsg
|
||||
)
|
||||
|
||||
var DocStyle = lipgloss.NewStyle().Margin(0, 2)
|
||||
|
||||
var HelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render
|
||||
|
||||
var ErrStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#bd534b")).Render
|
||||
|
||||
var AlertStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("62")).Render
|
||||
|
||||
type keymap struct {
|
||||
Radio key.Binding
|
||||
Enter key.Binding
|
||||
Rename key.Binding
|
||||
Delete key.Binding
|
||||
Back key.Binding
|
||||
Quit key.Binding
|
||||
}
|
||||
|
||||
var Keymap = keymap{
|
||||
Radio: key.NewBinding(
|
||||
key.WithKeys("ctrl+r"),
|
||||
key.WithHelp("ctrl+r", "start radio"),
|
||||
),
|
||||
Enter: key.NewBinding(
|
||||
key.WithKeys("enter"),
|
||||
key.WithHelp("enter", "select"),
|
||||
),
|
||||
Back: key.NewBinding(
|
||||
key.WithKeys("esc"),
|
||||
key.WithHelp("esc", "back"),
|
||||
),
|
||||
Quit: key.NewBinding(
|
||||
key.WithKeys("ctrl+c", "q"),
|
||||
key.WithHelp("ctrl+c/q", "quit"),
|
||||
),
|
||||
}
|
@ -15,11 +15,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
P *tea.Program
|
||||
DocStyle = lipgloss.NewStyle().Margin(0, 2)
|
||||
currentlyPlaying string
|
||||
main_updates chan *mainModel
|
||||
page = 1
|
||||
|
||||
docStyle = lipgloss.NewStyle().Margin(1, 2)
|
||||
)
|
||||
|
||||
type mainItem struct {
|
||||
@ -29,8 +29,6 @@ type mainItem struct {
|
||||
ID spotify.ID
|
||||
Desc string
|
||||
SpotifyItem any
|
||||
Device spotify.PlayerDevice
|
||||
spotify.SavedTrack
|
||||
}
|
||||
|
||||
func (i mainItem) Title() string { return i.Name }
|
||||
@ -99,6 +97,24 @@ func HandleLibraryRadio(ctx *gctx.Context, client *spotify.Client) {
|
||||
}
|
||||
}
|
||||
|
||||
func HandlePlayLikedSong(ctx *gctx.Context, client *spotify.Client, position int) {
|
||||
err := commands.PlayLikedSongs(ctx, client, position)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func HandleSetDevice(ctx *gctx.Context, client *spotify.Client, player spotify.PlayerDevice) {
|
||||
fmt.Println("WHOA")
|
||||
var err error
|
||||
err = commands.SetDevice(ctx, client, player)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mainModel) LoadMoreItems() {
|
||||
switch m.mode {
|
||||
case "main":
|
||||
@ -166,14 +182,6 @@ func (m *mainModel) LoadMoreItems() {
|
||||
}
|
||||
}
|
||||
|
||||
func HandlePlayLikedSong(ctx *gctx.Context, client *spotify.Client, position int) {
|
||||
err := commands.PlayLikedSongs(ctx, client, position)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.list.NewStatusMessage(currentlyPlaying)
|
||||
select {
|
||||
@ -254,7 +262,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.list.NewStatusMessage("Playing " + currentlyPlaying)
|
||||
go HandlePlayLikedSong(m.ctx, m.client, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
|
||||
case "devices":
|
||||
go HandleSetDevice(m.ctx, m.client, m.list.SelectedItem().(mainItem).Device)
|
||||
go HandleSetDevice(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.PlayerDevice))
|
||||
m.list.NewStatusMessage("Setting device to " + m.list.SelectedItem().FilterValue())
|
||||
m.mode = "main"
|
||||
m.list.NewStatusMessage("Setting view to main")
|
||||
@ -296,7 +304,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.list.CursorDown()
|
||||
}
|
||||
case tea.WindowSizeMsg:
|
||||
h, v := docStyle.GetFrameSize()
|
||||
h, v := DocStyle.GetFrameSize()
|
||||
m.list.SetSize(msg.Width-h, msg.Height-v)
|
||||
}
|
||||
|
||||
@ -306,7 +314,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
func (m mainModel) View() string {
|
||||
return docStyle.Render(m.list.View())
|
||||
return DocStyle.Render(m.list.View())
|
||||
}
|
||||
|
||||
func DisplayMain(ctx *gctx.Context, client *spotify.Client) error {
|
||||
@ -379,7 +387,6 @@ func SavedTracksView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, er
|
||||
Desc: track.Artists[0].Name + " - " + track.TimeDuration().Round(time.Second).String(),
|
||||
})
|
||||
}
|
||||
|
||||
return items, err
|
||||
}
|
||||
|
||||
@ -467,18 +474,8 @@ func DeviceView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error)
|
||||
items = append(items, mainItem{
|
||||
Name: device.Name,
|
||||
Desc: fmt.Sprintf("%s - active: %t", device.ID, device.Active),
|
||||
Device: device,
|
||||
SpotifyItem: device,
|
||||
})
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func HandleSetDevice(ctx *gctx.Context, client *spotify.Client, player spotify.PlayerDevice) {
|
||||
fmt.Println("WHOA")
|
||||
var err error
|
||||
err = commands.SetDevice(ctx, client, player)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user