Skip to content

Commit

Permalink
feat: dont show full screen loading on interval refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Dec 20, 2024
1 parent 6f85c20 commit ac5d822
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ui/components/issuessection/issuessection.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ func (m Model) IsLoading() bool {
return m.Table.IsLoading()
}

func (m *Model) SetIsLoading(val bool) {
m.Table.SetIsLoading(val)
}

func (m Model) GetPagerContent() string {
pagerContent := ""
if m.TotalCount > 0 {
Expand Down
27 changes: 22 additions & 5 deletions ui/components/prssection/prssection.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
startCursor = m.PageInfo.StartCursor
}
taskId := fmt.Sprintf("fetching_prs_%d_%s", m.Id, startCursor)
isFirstFetch := m.LastFetchTaskId == ""
m.LastFetchTaskId = taskId
task := context.Task{
Id: taskId,
Expand Down Expand Up @@ -416,7 +417,7 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
}
cmds = append(cmds, fetchCmd)

if m.PageInfo == nil {
if isFirstFetch {
m.Table.SetIsLoading(true)
cmds = append(cmds, m.Table.StartLoadingSpinner())

Expand All @@ -432,16 +433,22 @@ func (m *Model) ResetRows() {

func FetchAllSections(
ctx context.ProgramContext,
prs []section.Section,
) (sections []section.Section, fetchAllCmd tea.Cmd) {
fetchPRsCmds := make([]tea.Cmd, 0, len(ctx.Config.PRSections))
sections = make([]section.Section, 0, len(ctx.Config.PRSections))
for i, sectionConfig := range ctx.Config.PRSections {
sectionModel := NewModel(
i+1,
i+1, // 0 is the search section
&ctx,
sectionConfig,
time.Now(),
) // 0 is the search section
)
if len(prs) > 0 && len(prs) >= i+1 && prs[i+1] != nil {
oldSection := prs[i+1].(*Model)
sectionModel.Prs = oldSection.Prs
sectionModel.LastFetchTaskId = oldSection.LastFetchTaskId
}
sections = append(sections, &sectionModel)
fetchPRsCmds = append(
fetchPRsCmds,
Expand Down Expand Up @@ -502,13 +509,23 @@ func (m Model) IsLoading() bool {
return m.Table.IsLoading()
}

func (m *Model) SetIsLoading(val bool) {
m.Table.SetIsLoading(val)
}

func (m Model) GetPagerContent() string {
pagerContent := ""
timeElapsed := utils.TimeElapsed(m.LastUpdated())
if timeElapsed == "now" {
timeElapsed = "just now"
} else {
timeElapsed = fmt.Sprintf("~%v ago", timeElapsed)
}
if m.TotalCount > 0 {
pagerContent = fmt.Sprintf(
"%v %v • %v %v/%v • Fetched %v",
"%v Updated %v • %v %v/%v (fetched %v)",
constants.WaitingIcon,
m.LastUpdated().Format("01/02 15:04:05"),
timeElapsed,
m.SingularForm,
m.Table.GetCurrItem()+1,
m.TotalCount,
Expand Down
4 changes: 4 additions & 0 deletions ui/components/reposection/reposection.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ func (m *Model) GetTotalCount() *int {
return utils.IntPtr(len(m.Branches))
}

func (m *Model) SetIsLoading(val bool) {
m.Table.SetIsLoading(val)
}

func (m *Model) GetPagerContent() string {
s := lipgloss.NewStyle().Background(m.Ctx.Styles.ListViewPort.PagerStyle.GetBackground())
mod := s.Foreground(lipgloss.Color("#e0af68")).Render(fmt.Sprintf(" %d", len(m.repo.Status.Modified)))
Expand Down
3 changes: 2 additions & 1 deletion ui/components/section/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewModel(
),
)),
"Loading...",
true,
false,
)
return m
}
Expand Down Expand Up @@ -129,6 +129,7 @@ type Table interface {
BuildRows() []table.Row
ResetRows()
IsLoading() bool
SetIsLoading(val bool)
}

type Search interface {
Expand Down
22 changes: 19 additions & 3 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, m.keys.Refresh):
currSection.ResetFilters()
currSection.ResetRows()
currSection.SetIsLoading(true)
cmds = append(cmds, currSection.FetchNextPageSectionRows()...)

case key.Matches(msg, m.keys.RefreshAll):
Expand Down Expand Up @@ -489,7 +490,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.syncMainContentWidth()
newSections, fetchSectionsCmds := m.fetchAllViewSections()
m.setCurrentViewSections(newSections)
cmds = append(cmds, fetchSectionsCmds, fetchUser, m.doRefreshAtInterval())
cmds = append(cmds, fetchSectionsCmds, fetchUser, m.doRefreshAtInterval(), m.doUpdateFooterAtInterval())

case intervalRefresh:
newSections, fetchSectionsCmds := m.fetchAllViewSections()
Expand Down Expand Up @@ -553,6 +554,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
m.onWindowSizeChanged(msg)

case updateFooterMsg:
m.footer, cmd = m.footer.Update(msg)
cmds = append(cmds, cmd, m.doUpdateFooterAtInterval())

case constants.ErrMsg:
m.ctx.Error = msg.Err
}
Expand Down Expand Up @@ -754,7 +759,7 @@ func (m *Model) fetchAllViewSections() ([]section.Section, tea.Cmd) {
m.repo = &s
return nil, cmd
} else if m.ctx.View == config.PRsView {
return prssection.FetchAllSections(m.ctx)
return prssection.FetchAllSections(m.ctx, m.prs)
} else {
return issuessection.FetchAllSections(m.ctx)
}
Expand Down Expand Up @@ -955,9 +960,20 @@ func (m *Model) doRefreshAtInterval() tea.Cmd {
}

return tea.Tick(
time.Minute*time.Duration(m.ctx.Config.Defaults.RefetchIntervalMinutes),
time.Second*30,
func(t time.Time) tea.Msg {
return intervalRefresh(t)
},
)
}

type updateFooterMsg struct{}

func (m *Model) doUpdateFooterAtInterval() tea.Cmd {
return tea.Tick(
time.Second*10,
func(t time.Time) tea.Msg {
return updateFooterMsg{}
},
)
}

0 comments on commit ac5d822

Please sign in to comment.