adds visual indication for queue + no duplication in queue

This commit is contained in:
eyjhb 2025-02-08 23:49:57 +01:00
parent 5b88c53165
commit 6e4419dd61
Signed by: eyjhb
GPG key ID: 609F508E3239F920
2 changed files with 16 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"slices"
"strings"
"time"
"github.com/charmbracelet/bubbles/list"
@ -29,7 +30,6 @@ func (fe feedEntry) FilterValue() string { return fmt.Sprintf("%s - %s", fe.Name
type feedEntriesModel struct {
minifluxClient *miniflux.Client
entries list.Model
selectedEntry *feedEntry
}
type MsgFetchedEntries []feedEntry
@ -71,10 +71,11 @@ func (m *feedEntriesModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "enter":
fnGetSelected := func() tea.Msg {
i, ok := m.entries.SelectedItem().(feedEntry)
if ok {
m.selectedEntry = &i
i, _ := m.entries.SelectedItem().(feedEntry)
if strings.HasPrefix(i.Name, "[QUEUE]") == false {
i.Name = "[QUEUE] " + i.Name
}
m.entries.SetItem(m.entries.Index(), i)
return MsgPlayEntry(i)
}

View file

@ -1,8 +1,10 @@
package cmd
import (
"errors"
"fmt"
"regexp"
"strings"
"sync"
"time"
@ -80,6 +82,7 @@ func (m *playerModel) View() string {
// truncate name if needed
// name := m.entry.Name
name := m.currentlyPlaying.Name
name = strings.TrimPrefix(name, "[QUEUE] ")
if len(name) > playerMaxTitleLength {
name = name[0:playerMaxTitleLength] + "..."
}
@ -98,6 +101,14 @@ func (m *playerModel) View() string {
// other functions
func (m *playerModel) queue(f feedEntry) error {
// check if already exists
// TODO: handle actually showing errros?
for _, e := range m.playQueue {
if e.ID == f.ID {
return errors.New("already exists")
}
}
m.playQueue = append(m.playQueue, f)
if len(m.playQueue) == 1 && m.mpv.IsPlaying() == false {