mirror of
https://github.com/taigrr/gico.git
synced 2026-04-01 18:58:59 -07:00
repo commits are sorted by default, stub out paginator
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/paginator"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
@@ -40,6 +41,7 @@ type (
|
||||
Selected int
|
||||
Authors []string
|
||||
Repos []string
|
||||
Paginator paginator.Model
|
||||
}
|
||||
Settings struct{}
|
||||
Graph struct {
|
||||
@@ -114,7 +116,19 @@ func (m CommitLog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
var cmd tea.Cmd
|
||||
m.Paginator, cmd = m.Paginator.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func newPaginator() paginator.Model {
|
||||
p := paginator.New()
|
||||
p.Type = paginator.Dots
|
||||
p.PerPage = 8
|
||||
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(1)
|
||||
return p
|
||||
}
|
||||
|
||||
func (m CommitLog) Init() tea.Cmd {
|
||||
@@ -125,6 +139,11 @@ func (m CommitLog) View() string {
|
||||
if len(m.Commits) == 0 {
|
||||
return "No commits to display"
|
||||
}
|
||||
|
||||
if len(m.Commits[m.YearDay]) == 0 {
|
||||
return "No commits to display"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v", m.Commits[m.YearDay])
|
||||
// return fmt.Sprintf("This is the Commit Log, selected %v", "sd")
|
||||
}
|
||||
@@ -202,7 +221,11 @@ func NewCommitLog() (CommitLog, error) {
|
||||
m.Repos = mr
|
||||
m.Year = year
|
||||
m.Selected = today
|
||||
m.Paginator = newPaginator()
|
||||
m.Commits, err = mr.GetRepoCommits(m.Year, m.Authors)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,11 @@ func (paths RepoSet) GetRepoCommits(year int, authors []string) ([][]types.Commi
|
||||
d := commit.TimeStamp.YearDay() - 1
|
||||
commits[d] = append(commits[d], commit)
|
||||
}
|
||||
for i := 0; i < len(commits); i++ {
|
||||
sort.Slice(commits[i], func(w, j int) bool {
|
||||
return commits[i][w].TimeStamp.Before(commits[i][j].TimeStamp)
|
||||
})
|
||||
}
|
||||
CacheRepos(year, authors, paths, commits)
|
||||
return commits, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user