Skip to content

Commit

Permalink
(bugfix): only update table rows in update loop
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Palmer <everettraven@gmail.com>
  • Loading branch information
everettraven committed Nov 15, 2023
1 parent 2a0ba60 commit 3285a59
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pkg/charm/models/panels/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
// Table is a tea.Model implementation
// that represents a table panel
type Table struct {
table tbl.Model
name string
mutex *sync.Mutex
rows map[types.UID]tbl.Row
columns []buoytypes.Column
err error
table tbl.Model
name string
mutex *sync.Mutex
rows map[types.UID]tbl.Row
columns []buoytypes.Column
err error
tempRows []tbl.Row
}

func NewTable(name string, table tbl.Model, columns []buoytypes.Column) *Table {
Expand All @@ -38,6 +39,12 @@ func (m *Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
m.table.SetSize(msg.Width, msg.Height/2)
}

if len(m.tempRows) > 0 {
m.table.SetRows(m.tempRows)
m.tempRows = []tbl.Row{}
}

m.table, cmd = m.table.Update(msg)
return m, cmd
}
Expand Down Expand Up @@ -68,7 +75,7 @@ func (m *Table) updateRows() {
for _, row := range m.rows {
rows = append(rows, row)
}
m.table.SetRows(rows)
m.tempRows = rows
}

func (m *Table) Columns() []buoytypes.Column {
Expand Down

0 comments on commit 3285a59

Please sign in to comment.