This commit is contained in:
eyjhb 2025-01-26 22:37:17 +01:00
parent 32c5cae17a
commit 1efe2d08e1
Signed by: eyjhb
GPG key ID: 609F508E3239F920
4 changed files with 42 additions and 30 deletions

View file

@ -2,7 +2,6 @@ package cmd
import (
"context"
"fmt"
"time"
"github.com/charmbracelet/bubbles/list"
@ -29,9 +28,9 @@ const (
)
type MsgChangeView ViewType
type MsgSelectedItem feedEntry
type MsgTickInternal time.Time
type MsgTick uint8
type MsgPlayEntry feedEntry
type MsgWatchedEntry int64
type MsgTick time.Time
type MinifluxPlayer struct {
MinifluxClient *miniflux.Client
@ -59,28 +58,28 @@ func (mp *MinifluxPlayer) Init() tea.Cmd {
}
func (mp *MinifluxPlayer) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
return mp, tea.Quit
}
case MsgTickInternal:
fnSendTick := func() tea.Msg { return MsgTick(0) }
return mp, tea.Batch(tickEvery(), fnSendTick)
case MsgTick:
cmds = append(cmds, tickEvery())
case MsgChangeView:
mp.CurrentView = ViewType(msg)
}
if mp.CurrentView == ViewListFeedEntries {
_, c := mp.feedEntries.Update(msg)
return mp, c
} else if mp.CurrentView == ViewPlayer {
_, c := mp.player.Update(msg)
return mp, c
}
// always update all models
_, cmdFeeds := mp.feedEntries.Update(msg)
_, cmdPlayer := mp.player.Update(msg)
return mp, nil
cmds = append(cmds, cmdFeeds)
cmds = append(cmds, cmdPlayer)
return mp, tea.Batch(cmds...)
}
func (mp *MinifluxPlayer) View() string {
@ -88,15 +87,7 @@ func (mp *MinifluxPlayer) View() string {
return mp.player.View()
}
if mp.player.currentlyPlaying == true {
return lipgloss.JoinVertical(0.2, mp.feedEntries.View(), "", fmt.Sprintf("Currently Playing: %s (%v/%v)",
mp.player.selectedEntry.Name,
mp.player.videoPosition,
mp.player.videoDuration,
))
}
return mp.feedEntries.View()
return lipgloss.JoinVertical(0.2, mp.feedEntries.View(), "", mp.player.View())
}
func (mp *MinifluxPlayer) FetchCategories(ctx context.Context) ([]*miniflux.Category, error) {
@ -105,6 +96,6 @@ func (mp *MinifluxPlayer) FetchCategories(ctx context.Context) ([]*miniflux.Cate
func tickEvery() tea.Cmd {
return tea.Every(time.Second, func(t time.Time) tea.Msg {
return MsgTickInternal(t)
return MsgTick(t)
})
}