Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate record display on rapid consecutive refreshes #360

Merged
merged 2 commits into from
May 12, 2024
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
23 changes: 14 additions & 9 deletions ui/components/issuessection/issuessection.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,18 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {
}

case SectionIssuesFetchedMsg:
if m.PageInfo != nil {
m.Issues = append(m.Issues, msg.Issues...)
} else {
m.Issues = msg.Issues
if m.LastFetchTaskId == msg.TaskId {
if m.PageInfo != nil {
m.Issues = append(m.Issues, msg.Issues...)
} else {
m.Issues = msg.Issues
}
m.TotalCount = msg.TotalCount
m.PageInfo = &msg.PageInfo
m.Table.SetRows(m.BuildRows())
m.UpdateLastUpdated(time.Now())
m.UpdateTotalItemsCount(m.TotalCount)
}
m.TotalCount = msg.TotalCount
m.PageInfo = &msg.PageInfo
m.Table.SetRows(m.BuildRows())
m.UpdateLastUpdated(time.Now())
m.UpdateTotalItemsCount(m.TotalCount)
}

search, searchCmd := m.SearchBar.Update(msg)
Expand Down Expand Up @@ -259,6 +261,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
startCursor = m.PageInfo.StartCursor
}
taskId := fmt.Sprintf("fetching_issues_%d_%s", m.Id, startCursor)
m.LastFetchTaskId = taskId
task := context.Task{
Id: taskId,
StartText: fmt.Sprintf(`Fetching issues for "%s"`, m.Config.Title),
Expand Down Expand Up @@ -295,6 +298,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
Issues: res.Issues,
TotalCount: res.TotalCount,
PageInfo: res.PageInfo,
TaskId: taskId,
},
}

Expand Down Expand Up @@ -340,6 +344,7 @@ type SectionIssuesFetchedMsg struct {
Issues []data.IssueData
TotalCount int
PageInfo data.PageInfo
TaskId string
}

type UpdateIssueMsg struct {
Expand Down
23 changes: 14 additions & 9 deletions ui/components/prssection/prssection.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,18 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {
}

case SectionPullRequestsFetchedMsg:
if m.PageInfo != nil {
m.Prs = append(m.Prs, msg.Prs...)
} else {
m.Prs = msg.Prs
if m.LastFetchTaskId == msg.TaskId {
if m.PageInfo != nil {
m.Prs = append(m.Prs, msg.Prs...)
} else {
m.Prs = msg.Prs
}
m.TotalCount = msg.TotalCount
m.PageInfo = &msg.PageInfo
m.Table.SetRows(m.BuildRows())
m.UpdateLastUpdated(time.Now())
m.UpdateTotalItemsCount(m.TotalCount)
}
m.TotalCount = msg.TotalCount
m.PageInfo = &msg.PageInfo
m.Table.SetRows(m.BuildRows())
m.UpdateLastUpdated(time.Now())
m.UpdateTotalItemsCount(m.TotalCount)
}

search, searchCmd := m.SearchBar.Update(msg)
Expand Down Expand Up @@ -285,6 +287,7 @@ type SectionPullRequestsFetchedMsg struct {
Prs []data.PullRequestData
TotalCount int
PageInfo data.PageInfo
TaskId string
}

func (m *Model) GetCurrRow() data.RowData {
Expand All @@ -311,6 +314,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
startCursor = m.PageInfo.StartCursor
}
taskId := fmt.Sprintf("fetching_prs_%d_%s", m.Id, startCursor)
m.LastFetchTaskId = taskId
task := context.Task{
Id: taskId,
StartText: fmt.Sprintf(`Fetching PRs for "%s"`, m.Config.Title),
Expand Down Expand Up @@ -347,6 +351,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
Prs: res.Prs,
TotalCount: res.TotalCount,
PageInfo: res.PageInfo,
TaskId: taskId,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions ui/components/section/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Model struct {
PromptConfirmationBox prompt.Model
IsPromptConfirmationShown bool
PromptConfirmationAction string
LastFetchTaskId string
}

func NewModel(
Expand Down
Loading