add dashboard

This commit is contained in:
Robin Olsen
2026-02-10 20:11:36 +01:00
parent ee3e64a883
commit 19b32dca1b
5 changed files with 106 additions and 138 deletions

View File

@@ -41,34 +41,22 @@ var defaultDashboardKeyMap = DashboardKeyMap{
), ),
} }
func (m DashboardKeyMap) ShortHelp() []key.Binding {
return []key.Binding{m.ScrollDown, m.ScrollUp, m.Quit, m.Help}
}
func (m DashboardKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{m.SelectIssue, m.BackToList},
{m.ScrollUp, m.ScrollDown},
{m.Help, m.Quit},
}
}
func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd { func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
var cmd tea.Cmd var cmd tea.Cmd
switch { switch {
case key.Matches(msg, d.keyMap.Help): case key.Matches(msg, d.keyMap.Help):
d.help.ShowAll = !d.help.ShowAll d.helpBar.ToggleHelp()
case key.Matches(msg, d.keyMap.Quit): case key.Matches(msg, d.keyMap.Quit):
return tea.Quit return tea.Quit
case !d.focusedOnIssue && key.Matches(msg, d.keyMap.SelectIssue): case d.IsFocusedOnList() && key.Matches(msg, d.keyMap.SelectIssue):
d.focusedOnIssue = true d.FocusDetail()
case d.focusedOnIssue && key.Matches(msg, d.keyMap.BackToList): case d.IsFocusedOnDetail() && key.Matches(msg, d.keyMap.BackToList):
d.focusedOnIssue = false d.FocusList()
case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollUp): case d.IsFocusedOnDetail() && key.Matches(msg, d.keyMap.ScrollUp):
d.issueView.Viewport.ScrollUp(1) d.issueDetail.ScrollUp(1)
case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollDown): case d.IsFocusedOnDetail() && key.Matches(msg, d.keyMap.ScrollDown):
d.issueView.Viewport.ScrollDown(1) d.issueDetail.ScrollDown(1)
} }
return cmd return cmd

View File

@@ -1,26 +1,69 @@
package dashboard package dashboard
import ( import (
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/service" "github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/tui/views/issue" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/list"
) )
type Model struct { type Model struct {
help help.Model header Header
issueView issue.Model issueList IssueList
issueList list.Model issueDetail IssueDetail
helpBar HelpBar
keyMap DashboardKeyMap keyMap DashboardKeyMap
svc *service.Services svc *service.Services
focusedOnIssue bool width int
height int
focusedPane int // 0 = list, 1 = detail
} }
type ListIssue struct { func NewDashboard(svc *service.Services) *Model {
models.Issue m := &Model{
header: NewHeader("Project Manager Dashboard"),
keyMap: defaultDashboardKeyMap,
svc: svc,
width: 80,
height: 24,
focusedPane: 0,
} }
func (i ListIssue) Title() string { return i.Issue.Title } m.issueList = NewIssueList(svc, 0, 0)
func (i ListIssue) Description() string { return i.Issue.Description } m.issueDetail = NewIssueDetail()
func (i ListIssue) FilterValue() string { return i.Issue.ID + " " + i.Issue.Title } m.helpBar = NewHelpBar(m.keyMap)
if selected := m.issueList.SelectedItem(); selected.ID != "" {
m.issueDetail.SetIssue(selected.Issue)
}
return m
}
func (m *Model) Init() tea.Cmd {
return nil
}
func (m *Model) IsFocusedOnList() bool {
return m.focusedPane == 0
}
func (m *Model) IsFocusedOnDetail() bool {
return m.focusedPane == 1
}
func (m *Model) FocusList() {
m.focusedPane = 0
m.issueDetail.SetFocused(false)
}
func (m *Model) FocusDetail() {
m.focusedPane = 1
m.issueDetail.SetFocused(true)
}
func (m *Model) ToggleFocus() {
if m.focusedPane == 0 {
m.FocusDetail()
} else {
m.FocusList()
}
}

View File

@@ -1,60 +1,34 @@
package dashboard package dashboard
import ( import (
"fmt"
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
) )
func (d Model) Update(m tea.Msg) (tea.Model, tea.Cmd) { func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := m.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
if d.issueList.FilterState() == list.Filtering { if m.issueList.FilterState() == 1 {
break cmd, _ := m.issueList.Update(msg)
return m, cmd
} }
cmd := d.handleKeyMsg(msg)
cmd := m.handleKeyMsg(msg)
if cmd != nil { if cmd != nil {
return d, cmd return m, cmd
} }
case tea.WindowSizeMsg: case tea.WindowSizeMsg:
d.updateSizes(msg.Width, msg.Height) m.width = msg.Width
m.height = msg.Height
return m, nil
} }
var cmd tea.Cmd cmd, changed := m.issueList.Update(msg)
oldIndex := d.issueList.Index() if changed {
d.issueList, cmd = d.issueList.Update(m) if selected := m.issueList.SelectedItem(); selected.ID != "" {
m.issueDetail.SetIssue(selected.Issue)
if d.issueList.Index() != oldIndex {
d.updateIssueView()
}
return d, cmd
}
func (d *Model) updateIssueView() {
if item, ok := d.issueList.SelectedItem().(ListIssue); ok {
d.issueView.ID = item.ID
d.issueView.Title = item.Issue.Title
d.issueView.Description = item.Issue.Description
d.issueView.Status = string(item.Issue.Status)
d.issueView.IssueType = string(item.Issue.IssueType)
content := fmt.Sprintf("ID: %s\nTitle: %s\nDescription: %s\nStatus: %s\nType: %s",
d.issueView.ID, d.issueView.Title, d.issueView.Description, d.issueView.Status, d.issueView.IssueType)
d.issueView.Viewport.SetContent(content)
} }
} }
func (d *Model) updateSizes(width, height int) { return m, cmd
listWidth := width / 2
issueWidth := width - listWidth
w, h := styles.AppStyle.GetFrameSize()
d.issueList.SetSize(listWidth-w, height-h)
d.issueView.SetSize(issueWidth, height-h)
d.issueView.Viewport.Width = issueWidth
d.issueView.Viewport.Height = height - h
} }

View File

@@ -1,73 +1,36 @@
package dashboard package dashboard
import ( 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/styles"
"github.com/LazyBachelor/LazyPM/pkg/tui/views/issue" "github.com/charmbracelet/lipgloss"
) )
func NewDashboard(svc *service.Services) Model { func (m *Model) View() string {
if m.width == 0 || m.height == 0 {
issues, err := svc.Beads.AllIssues(context.Background()) return "Loading..."
listIssues := []ListIssue{}
for _, issue := range issues {
listIssues = append(listIssues, ListIssue{Issue: issue})
} }
if err != nil { m.helpBar.SetWidth(m.width)
listIssues = []ListIssue{}
} header := m.header.View(m.width)
headerHeight := m.header.Height()
items := make([]list.Item, len(listIssues))
for i, issue := range listIssues { bottomView := m.helpBar.View()
items[i] = issue bottomHeight := m.helpBar.Height()
}
contentHeight := m.height - headerHeight - bottomHeight
issueList := list.New(items, IssueListDelegate{}, 0, 0)
totalContentWidth := m.width - 1
issueList.Title = "Issues" listWidth := totalContentWidth * styles.ListViewRatio / 100
issueList.Styles.Title = styles.TitleStyle detailWidth := totalContentWidth - listWidth
issueList.SetShowHelp(false)
m.issueList.SetSize(listWidth, contentHeight)
issueView := issue.NewIssueView(issue.Model{}) m.issueDetail.SetSize(detailWidth, contentHeight)
m := Model{ listView := m.issueList.View()
help: help.New(), detailView := m.issueDetail.View()
issueView: issueView,
issueList: issueList, content := lipgloss.JoinHorizontal(lipgloss.Left, listView, detailView)
keyMap: defaultDashboardKeyMap,
svc: svc, return lipgloss.JoinVertical(lipgloss.Left, header, content, bottomView)
}
m.updateIssueView()
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
} }

View File

@@ -5,6 +5,6 @@ import (
"github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard" "github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard"
) )
func NewDashboardView(svc *service.Services) dashboard.Model { func NewDashboardView(svc *service.Services) *dashboard.Model {
return dashboard.NewDashboard(svc) return dashboard.NewDashboard(svc)
} }