Skip to content

Commit

Permalink
Fix counters not updated after reloading all feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
giulianopz committed Feb 22, 2024
1 parent c314bbb commit bbb6c7e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
15 changes: 8 additions & 7 deletions internal/display/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,26 @@ func (d *display) whileReading(input byte, quitC chan bool) {

case 'r':
if d.currentSection == URLS_LIST {
f, err := d.fetchFeed(string(d.raw[d.currentRow()]))
parsedFeed, err := d.fetchFeed(string(d.raw[d.currentRow()]))
if err != nil {
log.Default().Println(err)
d.setTmpBottomMessage(2*time.Second, "cannot parse feed!")
return
}
f.CountUnread()
parsedFeed.CountUnread()
// TODO rewrite single line with d.writeLineAt
d.rendered[d.currentRow()] = fromString(util.RenderFeedRow(f.UnreadCount, len(f.Items), f.Name))
d.rendered[d.currentRow()] = fromString(util.RenderFeedRow(parsedFeed.UnreadCount, len(parsedFeed.Items), parsedFeed.Name))
}

case 'a':
case 'R':
if d.currentSection == URLS_LIST {
d.enterEditingMode()
d.fetchAllFeeds()
d.renderFeedList()
}

case 'R':
case 'a':
if d.currentSection == URLS_LIST {
d.fetchAllFeeds()
d.enterEditingMode()
}

case 'o':
Expand Down
20 changes: 12 additions & 8 deletions internal/display/loading.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"log"
"log/slog"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -68,6 +69,7 @@ func (d *display) fetchFeed(url string) (*feed.Feed, error) {
log.Default().Println(err.Error())
}
}()

return parsedFeed, nil
}

Expand Down Expand Up @@ -112,16 +114,18 @@ func (d *display) fetchAllFeeds() {
}

if err := g.Wait(); err != nil {
slog.Error("reload failed", "err", err)
d.setTmpBottomMessage(2*time.Second, "cannot reload all feeds!")
} else {
go func() {
if err := d.cache.Encode(); err != nil {
log.Default().Println(err.Error())
}
}()

log.Default().Println("reloaded all feeds in: ", time.Since(start))
return
}

go func() {
if err := d.cache.Encode(); err != nil {
log.Default().Println(err.Error())
}
}()

log.Default().Println("reloaded all feeds in: ", time.Since(start))
}

func (d *display) loadArticleList(url string) error {
Expand Down
2 changes: 2 additions & 0 deletions internal/feed/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"log/slog"
"strings"
"time"

Expand Down Expand Up @@ -37,6 +38,7 @@ func (p *Parser) Parse(url string) (*Feed, error) {
defer cancel()
parsedFeed, err := p.ParseURLWithContext(url, ctx)
if err != nil {
slog.Error("cannot parse feed", "url", url, "err", err)
return nil, err
}
return NewFeedFrom(parsedFeed, url), nil
Expand Down

0 comments on commit bbb6c7e

Please sign in to comment.