Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions internal/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func sortList(m model) func() tea.Msg {
}
}

type refreshDone struct {
items []list.Item
errors []string
}

func refreshList(m model) func() tea.Msg {
return func() tea.Msg {
var errorItems []ErrorItem
Expand Down Expand Up @@ -141,10 +146,9 @@ func refreshList(m model) func() tea.Msg {
es = append(es, fmt.Sprintf("Error fetching %s: %s", e.FeedURL, e.Err))
}

m.errors = es
return listUpdate{
return refreshDone{
items: convertItems(items),
status: "Refreshed.",
errors: es,
}
}
}
Expand All @@ -167,6 +171,15 @@ func updateList(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case statusUpdate:
cmds = append(cmds, m.list.NewStatusMessage(msg.status))
case refreshDone:
m.refreshing = false
m.list.Title = defaultTitle
m.list.Styles.Title = m.list.Styles.Title.Width(lipgloss.Width(defaultTitle) + 2)
if !m.list.SettingFilter() {
m.list.SetItems(msg.items)
}
m.errors = msg.errors
cmds = append(cmds, m.list.NewStatusMessage("Refreshed."))
case listUpdate:
if m.list.SettingFilter() {
break
Expand All @@ -192,6 +205,13 @@ func updateList(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
break
}

if m.refreshing {
break
}

m.refreshing = true
m.list.Title = "Refreshing..."
m.list.Styles.Title = m.list.Styles.Title.Width(lipgloss.Width("Refreshing...") + 2)
cmds = append(cmds, refreshList(m))

case key.Matches(msg, ListKeyMap.Read):
Expand Down
1 change: 1 addition & 0 deletions internal/commands/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type model struct {
viewport viewport.Model
lastRead *list.Item
lastReadIndex int
refreshing bool
}

func (m model) Init() tea.Cmd {
Expand Down
Loading