Skip to content

Commit

Permalink
Show something on comments page, when there are no comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
piqoni committed Jun 4, 2024
1 parent da8982d commit 1773b91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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:
Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1773b91

Please sign in to comment.