add dashboard
This commit is contained in:
@@ -1,60 +1,34 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
func (d Model) Update(m tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := m.(type) {
|
||||
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
if d.issueList.FilterState() == list.Filtering {
|
||||
break
|
||||
if m.issueList.FilterState() == 1 {
|
||||
cmd, _ := m.issueList.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
cmd := d.handleKeyMsg(msg)
|
||||
|
||||
cmd := m.handleKeyMsg(msg)
|
||||
if cmd != nil {
|
||||
return d, cmd
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
case tea.WindowSizeMsg:
|
||||
d.updateSizes(msg.Width, msg.Height)
|
||||
m.width = msg.Width
|
||||
m.height = msg.Height
|
||||
return m, nil
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
oldIndex := d.issueList.Index()
|
||||
d.issueList, cmd = d.issueList.Update(m)
|
||||
|
||||
if d.issueList.Index() != oldIndex {
|
||||
d.updateIssueView()
|
||||
cmd, changed := m.issueList.Update(msg)
|
||||
if changed {
|
||||
if selected := m.issueList.SelectedItem(); selected.ID != "" {
|
||||
m.issueDetail.SetIssue(selected.Issue)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user