mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -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/help"
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
|
"github.com/charmbracelet/bubbles/paginator"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
|
||||||
@@ -34,12 +35,13 @@ type (
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
CommitLog struct {
|
CommitLog struct {
|
||||||
Year int
|
Year int
|
||||||
YearDay int
|
YearDay int
|
||||||
Commits [][]types.Commit
|
Commits [][]types.Commit
|
||||||
Selected int
|
Selected int
|
||||||
Authors []string
|
Authors []string
|
||||||
Repos []string
|
Repos []string
|
||||||
|
Paginator paginator.Model
|
||||||
}
|
}
|
||||||
Settings struct{}
|
Settings struct{}
|
||||||
Graph 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 {
|
func (m CommitLog) Init() tea.Cmd {
|
||||||
@@ -125,6 +139,11 @@ func (m CommitLog) View() string {
|
|||||||
if len(m.Commits) == 0 {
|
if len(m.Commits) == 0 {
|
||||||
return "No commits to display"
|
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("%v", m.Commits[m.YearDay])
|
||||||
// return fmt.Sprintf("This is the Commit Log, selected %v", "sd")
|
// return fmt.Sprintf("This is the Commit Log, selected %v", "sd")
|
||||||
}
|
}
|
||||||
@@ -202,7 +221,11 @@ func NewCommitLog() (CommitLog, error) {
|
|||||||
m.Repos = mr
|
m.Repos = mr
|
||||||
m.Year = year
|
m.Year = year
|
||||||
m.Selected = today
|
m.Selected = today
|
||||||
|
m.Paginator = newPaginator()
|
||||||
m.Commits, err = mr.GetRepoCommits(m.Year, m.Authors)
|
m.Commits, err = mr.GetRepoCommits(m.Year, m.Authors)
|
||||||
|
if err != nil {
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
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
|
d := commit.TimeStamp.YearDay() - 1
|
||||||
commits[d] = append(commits[d], commit)
|
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)
|
CacheRepos(year, authors, paths, commits)
|
||||||
return commits, nil
|
return commits, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user