Skip to content

Commit

Permalink
add spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 committed May 26, 2024
1 parent 06cfb6b commit 5cd426a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
7 changes: 5 additions & 2 deletions ui/components/issuessection/issuessection.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {

prompt, promptCmd := m.PromptConfirmationBox.Update(msg)
m.PromptConfirmationBox = prompt
return &m, tea.Batch(cmd, searchCmd, promptCmd)

loadingSpinner, loadingSpinnerCmd := m.Table.LoadingSpinner.Update(msg)
m.Table.LoadingSpinner = loadingSpinner

return &m, tea.Batch(cmd, searchCmd, promptCmd, loadingSpinnerCmd)
}

func GetSectionColumns(
Expand Down Expand Up @@ -303,7 +307,6 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
TaskId: taskId,
},
}

}
cmds = append(cmds, fetchCmd)

Expand Down
8 changes: 7 additions & 1 deletion ui/components/prssection/prssection.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {

prompt, promptCmd := m.PromptConfirmationBox.Update(msg)
m.PromptConfirmationBox = prompt
return &m, tea.Batch(cmd, searchCmd, promptCmd)

loadingSpinner, loadingSpinnerCmd := m.Table.LoadingSpinner.Update(msg)
m.Table.LoadingSpinner = loadingSpinner

return &m, tea.Batch(cmd, searchCmd, promptCmd, loadingSpinnerCmd)
}

func GetSectionColumns(
Expand Down Expand Up @@ -359,6 +363,8 @@ func (m *Model) FetchNextPageSectionRows() []tea.Cmd {
cmds = append(cmds, fetchCmd)

m.Table.SetIsLoading(true)
cmds = append(cmds, m.Table.StartLoadingSpinner())

return cmds
}

Expand Down
16 changes: 15 additions & 1 deletion ui/components/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package table
import (
"time"

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"

"github.com/dlvhdr/gh-dash/ui/common"
Expand All @@ -18,6 +20,7 @@ type Model struct {
EmptyState *string
loadingMessage string
isLoading bool
LoadingSpinner spinner.Model
dimensions constants.Dimensions
rowsViewport listviewport.Model
}
Expand Down Expand Up @@ -46,13 +49,19 @@ func NewModel(
if ctx.Config.Theme.Ui.Table.ShowSeparator {
itemHeight = 2
}

loadingSpinner := spinner.New()
loadingSpinner.Spinner = spinner.Dot
loadingSpinner.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))

return Model{
ctx: ctx,
Columns: columns,
Rows: rows,
EmptyState: emptyState,
loadingMessage: loadingMessage,
isLoading: isLoading,
LoadingSpinner: loadingSpinner,
dimensions: dimensions,
rowsViewport: listviewport.NewModel(
ctx,
Expand All @@ -65,6 +74,10 @@ func NewModel(
}
}

func (m Model) StartLoadingSpinner() tea.Cmd {
return m.LoadingSpinner.Tick
}

func (m Model) View() string {
header := m.renderHeader()
body := m.renderBody()
Expand Down Expand Up @@ -220,7 +233,8 @@ func (m *Model) renderBody() string {
MaxWidth(m.dimensions.Width)

if m.isLoading {
return bodyStyle.Render(m.loadingMessage)
// TODO: center
return bodyStyle.Render(m.LoadingSpinner.View(), m.loadingMessage)
}

if len(m.Rows) == 0 && m.EmptyState != nil {
Expand Down

0 comments on commit 5cd426a

Please sign in to comment.