Skip to content

Commit

Permalink
adds basic refresh functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
piqoni committed Jun 7, 2024
1 parent cb89c42 commit 7c33a10
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ func extractDomain(link string) string {
return u.Host
}

func fetchAndGenerateList(hackerNewsURL string) (*tview.List, error) {
htmlContent, err := fetchWebpage(hackerNewsURL)
if err != nil {
return nil, err
}

articles, err := parseArticles(htmlContent)
if err != nil {
return nil, err
}

list := createArticleList(articles)
return list, nil
}

func createInputHandler(app *tview.Application, list *tview.List, articles []Article, pages *tview.Pages) func(event *tcell.EventKey) *tcell.EventKey {
return func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
Expand Down Expand Up @@ -72,7 +87,11 @@ func createInputHandler(app *tview.Application, list *tview.List, articles []Art
case 'c':
openURL(hackerNewsURL + articles[list.GetCurrentItem()].CommentsLink)
return nil

case 'r':
list.Clear()
refreshedList, _ := fetchAndGenerateList(hackerNewsURL)
pages.AddPage("homepage", refreshedList, true, false)
app.SetRoot(refreshedList, true).Run()
}
}

Expand Down

0 comments on commit 7c33a10

Please sign in to comment.