From 1773b91c4ee40117de3942975c87fb17bde9575a Mon Sep 17 00:00:00 2001 From: Edi Piqoni Date: Wed, 5 Jun 2024 00:08:55 +0200 Subject: [PATCH] Show something on comments page, when there are no comments. --- parser.go | 1 - ui.go | 10 ++++++++-- web.go | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/parser.go b/parser.go index 945c3f6..c3200e6 100644 --- a/parser.go +++ b/parser.go @@ -48,7 +48,6 @@ func parseArticles(htmlContent string) ([]Article, error) { } func extractCommentsCountFromString(input string) (int, error) { - input = strings.TrimSpace(input) re := regexp.MustCompile(`\d+`) matches := re.FindString(input) diff --git a/ui.go b/ui.go index 97192e0..a00e415 100644 --- a/ui.go +++ b/ui.go @@ -14,11 +14,13 @@ import ( "github.com/rivo/tview" ) +const fireEmojiNrOfComments = 50 // TODO maybe configurable + func createArticleList(articles []Article) *tview.List { list := tview.NewList().ShowSecondaryText(true).SetSecondaryTextColor(tcell.ColorGray) for _, article := range articles { title := article.Title - if article.Comments > 50 { // TODO: configurable + if article.Comments > fireEmojiNrOfComments { title = "🔥 " + title } @@ -38,7 +40,6 @@ func extractDomain(link string) string { } 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() { case tcell.KeyCtrlC: @@ -112,6 +113,11 @@ func openComments(app *tview.Application, commentsLink string, pages *tview.Page for _, articleString := range articleStringList { commentsText += articleString + "\n" } + + if commentsText == "" { + commentsText = "Story has no comments yet. Press RIGHT ARROW or letter 'l' to continue with the article." + } + displayComments(app, pages, commentsText) } diff --git a/web.go b/web.go index 322c23d..29db1ec 100644 --- a/web.go +++ b/web.go @@ -60,7 +60,6 @@ func fetchComments(storyID string) []string { } var lines []string - lines = append(lines, " ") if children, ok := comments["children"].([]interface{}); ok { for _, child := range children {