Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
change dot to arabic paging format
Browse files Browse the repository at this point in the history
Signed-off-by: zychen5186 <brianchen5197@gmail.com>

change dot to arabic paging format

Signed-off-by: zychen5186 <brianchen5197@gmail.com>

change var names

Signed-off-by: zychen5186 <brianchen5197@gmail.com>
  • Loading branch information
zychen5186 committed Apr 23, 2024
1 parent 2bb1095 commit 99c9b49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 3 additions & 5 deletions pkg/bubbletea/bubbletea_pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand Down Expand Up @@ -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()
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/bubbletea/bubbletea_pagination_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 99c9b49

Please sign in to comment.