Show popular match viewer counts

This commit is contained in:
Salastil
2025-11-23 01:06:12 -05:00
parent 45d0979b01
commit 1f57c556a0
2 changed files with 72 additions and 6 deletions

View File

@@ -201,7 +201,13 @@ func New(debug bool) Model {
if mt.Teams != nil && mt.Teams.Home != nil && mt.Teams.Away != nil {
title = fmt.Sprintf("%s vs %s", mt.Teams.Home.Name, mt.Teams.Away.Name)
}
return fmt.Sprintf("%s %s (%s)", when, title, mt.Category)
viewers := ""
if mt.Viewers > 0 {
viewers = fmt.Sprintf(" (%s viewers)", formatViewerCount(mt.Viewers))
}
return fmt.Sprintf("%s %s%s (%s)", when, title, viewers, mt.Category)
})
m.matches.SetSeparator(func(prev, curr Match) (string, bool) {
currDay := time.UnixMilli(curr.Date).Local().Format("Jan 2")
@@ -513,9 +519,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
case sportsLoadedMsg:
m.sports.SetItems(msg)
sports := prependPopularSport(msg)
m.sports.SetItems(sports)
m.lastError = nil
m.status = fmt.Sprintf("Loaded %d sports pick one with Enter or stay on Popular Matches", len(msg))
m.status = fmt.Sprintf("Loaded %d sports pick one with Enter or stay on Popular Matches", len(sports))
return m, nil
case matchesLoadedMsg:
@@ -571,14 +578,35 @@ func (m Model) fetchPopularMatches() tea.Cmd {
func (m Model) fetchMatchesForSport(s Sport) tea.Cmd {
return func() tea.Msg {
matches, err := m.apiClient.GetMatchesBySport(context.Background(), s.ID)
get := func() ([]Match, error) {
if strings.EqualFold(s.ID, "popular") {
return m.apiClient.GetPopularMatches(context.Background())
}
return m.apiClient.GetMatchesBySport(context.Background(), s.ID)
}
matches, err := get()
if err != nil {
return errorMsg(err)
}
return matchesLoadedMsg{Matches: matches, Title: fmt.Sprintf("Matches (%s)", s.Name)}
title := fmt.Sprintf("Matches (%s)", s.Name)
if strings.EqualFold(s.ID, "popular") {
title = "Popular Matches"
}
return matchesLoadedMsg{Matches: matches, Title: title}
}
}
func prependPopularSport(sports []Sport) []Sport {
for _, s := range sports {
if strings.EqualFold(s.ID, "popular") || strings.EqualFold(s.Name, "popular") {
return sports
}
}
popular := Sport{ID: "popular", Name: "Popular"}
return append([]Sport{popular}, sports...)
}
func (m Model) fetchStreamsForMatch(mt Match) tea.Cmd {
return func() tea.Msg {
streams, err := m.apiClient.GetStreamsForMatch(context.Background(), mt)