add dashboard
This commit is contained in:
@@ -1,73 +1,36 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/issue"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func NewDashboard(svc *service.Services) Model {
|
||||
|
||||
issues, err := svc.Beads.AllIssues(context.Background())
|
||||
|
||||
listIssues := []ListIssue{}
|
||||
for _, issue := range issues {
|
||||
listIssues = append(listIssues, ListIssue{Issue: issue})
|
||||
func (m *Model) View() string {
|
||||
if m.width == 0 || m.height == 0 {
|
||||
return "Loading..."
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
listIssues = []ListIssue{}
|
||||
}
|
||||
m.helpBar.SetWidth(m.width)
|
||||
|
||||
items := make([]list.Item, len(listIssues))
|
||||
for i, issue := range listIssues {
|
||||
items[i] = issue
|
||||
}
|
||||
header := m.header.View(m.width)
|
||||
headerHeight := m.header.Height()
|
||||
|
||||
issueList := list.New(items, IssueListDelegate{}, 0, 0)
|
||||
bottomView := m.helpBar.View()
|
||||
bottomHeight := m.helpBar.Height()
|
||||
|
||||
issueList.Title = "Issues"
|
||||
issueList.Styles.Title = styles.TitleStyle
|
||||
issueList.SetShowHelp(false)
|
||||
contentHeight := m.height - headerHeight - bottomHeight
|
||||
|
||||
issueView := issue.NewIssueView(issue.Model{})
|
||||
totalContentWidth := m.width - 1
|
||||
listWidth := totalContentWidth * styles.ListViewRatio / 100
|
||||
detailWidth := totalContentWidth - listWidth
|
||||
|
||||
m := Model{
|
||||
help: help.New(),
|
||||
issueView: issueView,
|
||||
issueList: issueList,
|
||||
keyMap: defaultDashboardKeyMap,
|
||||
svc: svc,
|
||||
}
|
||||
m.issueList.SetSize(listWidth, contentHeight)
|
||||
m.issueDetail.SetSize(detailWidth, contentHeight)
|
||||
|
||||
m.updateIssueView()
|
||||
listView := m.issueList.View()
|
||||
detailView := m.issueDetail.View()
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (d Model) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Model) View() string {
|
||||
issueView := d.issueView.View()
|
||||
|
||||
if d.focusedOnIssue {
|
||||
issueView = styles.FocusedIssueStyle.Render(issueView)
|
||||
} else {
|
||||
issueView = styles.IssueStyle.Render(issueView)
|
||||
}
|
||||
|
||||
help := d.help.View(d.keyMap)
|
||||
|
||||
str := lipgloss.JoinHorizontal(lipgloss.Left, styles.AppStyle.Render(d.issueList.View()), issueView) + "\n" + help
|
||||
|
||||
return str
|
||||
content := lipgloss.JoinHorizontal(lipgloss.Left, listView, detailView)
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Left, header, content, bottomView)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user