diff --git a/pkg/bubbletea/bubbletea_pagination.go b/pkg/bubbletea/bubbletea_pagination.go index a15402f0..11a9b6a3 100644 --- a/pkg/bubbletea/bubbletea_pagination.go +++ b/pkg/bubbletea/bubbletea_pagination.go @@ -4,11 +4,11 @@ package bubbletea // component library. import ( + "fmt" "log" "strings" "github.com/charmbracelet/bubbles/paginator" - "github.com/charmbracelet/lipgloss" "github.com/golang/protobuf/proto" tea "github.com/charmbracelet/bubbletea" @@ -21,10 +21,7 @@ type pageModel struct { func newModel(initMsg []proto.Message) pageModel { p := paginator.New() - p.Type = paginator.Dots p.PerPage = defaultMsgPerPage - p.ActiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "235", Dark: "252"}).Render("•") - p.InactiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "250", Dark: "238"}).Render("•") p.SetTotalPages(len(initMsg)) return pageModel{ @@ -59,7 +56,8 @@ func (m pageModel) View() string { return "" } b.WriteString(table) - b.WriteString(" " + m.paginator.View()) + currentPage := int(firstBatchIndex-1)*pagePerBatch + m.paginator.Page + 1 + b.WriteString(fmt.Sprintf(" PAGE - %d\n", currentPage)) b.WriteString("\n\n h/l ←/→ page • q: quit\n") return b.String() } diff --git a/pkg/bubbletea/bubbletea_pagination_util.go b/pkg/bubbletea/bubbletea_pagination_util.go index 11ede5f1..78404241 100644 --- a/pkg/bubbletea/bubbletea_pagination_util.go +++ b/pkg/bubbletea/bubbletea_pagination_util.go @@ -20,8 +20,9 @@ type DataCallback func(filter filters.Filters) []proto.Message type PrintableProto struct{ proto.Message } const ( - defaultLimit = 100 - defaultMsgPerPage = 10 + defaultMsgPerBatch = 100 + defaultMsgPerPage = 10 + pagePerBatch = defaultMsgPerBatch / defaultMsgPerPage ) var ( @@ -124,14 +125,14 @@ func printTable(m *pageModel, start int, end int) (string, error) { return buf.String(), nil } -func getMessageList(batchPage int32) []proto.Message { +func getMessageList(batchIndex int32) []proto.Message { msg := callback(filters.Filters{ - Limit: defaultLimit, - Page: batchPage, + Limit: defaultMsgPerBatch, + Page: batchIndex, SortBy: "created_at", Asc: false, }) - batchLen[batchPage] = len(msg) + batchLen[batchIndex] = len(msg) return msg }