From d49e31a26736dbb94e0dfa42fc30e3c598c5459d Mon Sep 17 00:00:00 2001 From: szktkfm Date: Sat, 4 May 2024 23:54:14 +0900 Subject: [PATCH 1/2] fix: duplicate record display on rapid consecutive refreshes --- ui/components/issuessection/issuessection.go | 23 ++++++++++++-------- ui/components/prssection/prssection.go | 23 ++++++++++++-------- ui/components/section/section.go | 1 + 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ui/components/issuessection/issuessection.go b/ui/components/issuessection/issuessection.go index c2894fa3..abdb2724 100644 --- a/ui/components/issuessection/issuessection.go +++ b/ui/components/issuessection/issuessection.go @@ -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.LastTaskId == 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) @@ -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.LastTaskId = taskId task := context.Task{ Id: taskId, StartText: fmt.Sprintf(`Fetching issues for "%s"`, m.Config.Title), @@ -295,6 +298,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd { Issues: res.Issues, TotalCount: res.TotalCount, PageInfo: res.PageInfo, + TaskId: taskId, }, } @@ -340,6 +344,7 @@ type SectionIssuesFetchedMsg struct { Issues []data.IssueData TotalCount int PageInfo data.PageInfo + TaskId string } type UpdateIssueMsg struct { diff --git a/ui/components/prssection/prssection.go b/ui/components/prssection/prssection.go index 1ed52262..000b43dc 100644 --- a/ui/components/prssection/prssection.go +++ b/ui/components/prssection/prssection.go @@ -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.LastTaskId == 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) @@ -285,6 +287,7 @@ type SectionPullRequestsFetchedMsg struct { Prs []data.PullRequestData TotalCount int PageInfo data.PageInfo + TaskId string } func (m *Model) GetCurrRow() data.RowData { @@ -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.LastTaskId = taskId task := context.Task{ Id: taskId, StartText: fmt.Sprintf(`Fetching PRs for "%s"`, m.Config.Title), @@ -347,6 +351,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd { Prs: res.Prs, TotalCount: res.TotalCount, PageInfo: res.PageInfo, + TaskId: taskId, }, } } diff --git a/ui/components/section/section.go b/ui/components/section/section.go index 0a8129c4..5e4db292 100644 --- a/ui/components/section/section.go +++ b/ui/components/section/section.go @@ -37,6 +37,7 @@ type Model struct { PromptConfirmationBox prompt.Model IsPromptConfirmationShown bool PromptConfirmationAction string + LastTaskId string } func NewModel( From 770fdfb11c279eec77968555109b5c7d4bdf0376 Mon Sep 17 00:00:00 2001 From: szktkfm Date: Sun, 12 May 2024 14:41:58 +0900 Subject: [PATCH 2/2] rename field --- ui/components/issuessection/issuessection.go | 4 ++-- ui/components/prssection/prssection.go | 4 ++-- ui/components/section/section.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/components/issuessection/issuessection.go b/ui/components/issuessection/issuessection.go index abdb2724..5b6c6748 100644 --- a/ui/components/issuessection/issuessection.go +++ b/ui/components/issuessection/issuessection.go @@ -125,7 +125,7 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) { } case SectionIssuesFetchedMsg: - if m.LastTaskId == msg.TaskId { + if m.LastFetchTaskId == msg.TaskId { if m.PageInfo != nil { m.Issues = append(m.Issues, msg.Issues...) } else { @@ -261,7 +261,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd { startCursor = m.PageInfo.StartCursor } taskId := fmt.Sprintf("fetching_issues_%d_%s", m.Id, startCursor) - m.LastTaskId = taskId + m.LastFetchTaskId = taskId task := context.Task{ Id: taskId, StartText: fmt.Sprintf(`Fetching issues for "%s"`, m.Config.Title), diff --git a/ui/components/prssection/prssection.go b/ui/components/prssection/prssection.go index 000b43dc..a1fb1155 100644 --- a/ui/components/prssection/prssection.go +++ b/ui/components/prssection/prssection.go @@ -156,7 +156,7 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) { } case SectionPullRequestsFetchedMsg: - if m.LastTaskId == msg.TaskId { + if m.LastFetchTaskId == msg.TaskId { if m.PageInfo != nil { m.Prs = append(m.Prs, msg.Prs...) } else { @@ -314,7 +314,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd { startCursor = m.PageInfo.StartCursor } taskId := fmt.Sprintf("fetching_prs_%d_%s", m.Id, startCursor) - m.LastTaskId = taskId + m.LastFetchTaskId = taskId task := context.Task{ Id: taskId, StartText: fmt.Sprintf(`Fetching PRs for "%s"`, m.Config.Title), diff --git a/ui/components/section/section.go b/ui/components/section/section.go index 5e4db292..5c6e0d29 100644 --- a/ui/components/section/section.go +++ b/ui/components/section/section.go @@ -37,7 +37,7 @@ type Model struct { PromptConfirmationBox prompt.Model IsPromptConfirmationShown bool PromptConfirmationAction string - LastTaskId string + LastFetchTaskId string } func NewModel(