Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions internal/site/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ import (
"io"
"net/http"
"net/url"
"time"

"github.com/PuerkitoBio/goquery"
"golang.org/x/net/html/charset"
)

const defaultBaseURL = "http://www.90minut.pl"

type Client struct {
baseURL *url.URL
http *http.Client
}

func NewClient() *Client {
base, _ := url.Parse(defaultBaseURL)
base, _ := url.Parse(BaseURL)

return &Client{
baseURL: base,
http: &http.Client{
Timeout: 15 * time.Second,
Timeout: HTTPTimeout,
},
}
}
Expand Down
12 changes: 12 additions & 0 deletions internal/site/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package site

import "time"

const (
BaseURL = "http://www.90minut.pl"
ArchiveURL = BaseURL + "/archsezon.php"

// HTTPTimeout caps individual HTTP round-trips; kept short to surface
// connectivity failures quickly without blocking the TUI.
HTTPTimeout = 15 * time.Second
)
13 changes: 8 additions & 5 deletions internal/ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
"github.com/adrunkhuman/90minuTUI/internal/site"
)

// cmdTimeout is generous enough for slow archive pages without blocking the TUI indefinitely.
const cmdTimeout = 20 * time.Second

func (m Model) loadArchiveCmd(url string) tea.Cmd {
return func() tea.Msg {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
seasons, selectedIdx, competitions, err := m.service.LoadArchive(ctx, url)
return archiveLoadedMsg{seasons: seasons, selectedIdx: selectedIdx, competitions: competitions, err: err}
Expand All @@ -21,7 +24,7 @@ func (m Model) loadArchiveCmd(url string) tea.Cmd {

func (m Model) loadSeasonCompetitionsCmd(url, seasonKey string) tea.Cmd {
return func() tea.Msg {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
_, _, competitions, err := m.service.LoadArchive(ctx, url)
return competitionsLoadedMsg{seasonKey: seasonKey, competitions: competitions, err: err}
Expand All @@ -30,7 +33,7 @@ func (m Model) loadSeasonCompetitionsCmd(url, seasonKey string) tea.Cmd {

func (m Model) loadCompetitionCmd(url, competitionKey string) tea.Cmd {
return func() tea.Msg {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
menu, league, err := m.service.LoadCompetition(ctx, url)
return competitionMenuLoadedMsg{competitionKey: competitionKey, menu: menu, league: league, err: err}
Expand All @@ -39,7 +42,7 @@ func (m Model) loadCompetitionCmd(url, competitionKey string) tea.Cmd {

func (m Model) loadLeagueCmd(url, competitionKey string) tea.Cmd {
return func() tea.Msg {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
league, err := m.service.LoadLeague(ctx, url)
return leagueLoadedMsg{competitionKey: competitionKey, league: league, err: err}
Expand All @@ -48,7 +51,7 @@ func (m Model) loadLeagueCmd(url, competitionKey string) tea.Cmd {

func (m Model) loadMatchCmd(url, fixtureKey string) tea.Cmd {
return func() tea.Msg {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
match, err := m.service.LoadMatch(ctx, url)
return matchLoadedMsg{fixtureKey: fixtureKey, match: match, err: err}
Expand Down
6 changes: 4 additions & 2 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"time"

tea "github.com/charmbracelet/bubbletea"

"github.com/adrunkhuman/90minuTUI/internal/site"
)

func (m Model) Init() tea.Cmd {
return m.loadArchiveCmd("http://www.90minut.pl/archsezon.php")
return m.loadArchiveCmd(site.ArchiveURL)
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Expand Down Expand Up @@ -391,7 +393,7 @@ func (m *Model) handleReload() tea.Cmd {

m.match = nil
if len(m.seasons) == 0 {
return m.loadArchiveCmd("http://www.90minut.pl/archsezon.php")
return m.loadArchiveCmd(site.ArchiveURL)
}

if m.selectorActive() && m.focus == focusSeasons {
Expand Down