From 7c33a100565653402aeb2648917348672067486a Mon Sep 17 00:00:00 2001 From: Edi Piqoni Date: Fri, 7 Jun 2024 22:59:20 +0200 Subject: [PATCH] adds basic refresh functionality --- ui.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ui.go b/ui.go index a00e415..7a8122e 100644 --- a/ui.go +++ b/ui.go @@ -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() { @@ -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() } }