add feedback to tui
This commit is contained in:
@@ -4,13 +4,17 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type TUIConfig = service.Config
|
||||
|
||||
type Tui struct{}
|
||||
type Tui struct {
|
||||
feedbackChan chan task.ValidationFeedback
|
||||
quitChan chan bool
|
||||
}
|
||||
|
||||
func NewTui() *Tui {
|
||||
return &Tui{}
|
||||
@@ -24,10 +28,24 @@ func (t *Tui) Run(ctx context.Context, config TUIConfig) error {
|
||||
|
||||
defer cleanup()
|
||||
|
||||
if _, err := tea.NewProgram(views.NewDashboardView(svc),
|
||||
tea.WithAltScreen(), tea.WithMouseAllMotion()).Run(); err != nil {
|
||||
p := tea.NewProgram(views.NewDashboardView(svc, t.feedbackChan, t.quitChan),
|
||||
tea.WithAltScreen(), tea.WithMouseAllMotion())
|
||||
|
||||
if t.quitChan != nil {
|
||||
go func() {
|
||||
<-t.quitChan
|
||||
p.Quit()
|
||||
}()
|
||||
}
|
||||
|
||||
if _, err := p.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Tui) SetChannels(feedbackChan chan task.ValidationFeedback, quitChan chan bool) {
|
||||
t.feedbackChan = feedbackChan
|
||||
t.quitChan = quitChan
|
||||
}
|
||||
|
||||
@@ -2,29 +2,40 @@ package dashboard
|
||||
|
||||
import (
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
header Header
|
||||
issueList IssueList
|
||||
issueDetail IssueDetail
|
||||
helpBar HelpBar
|
||||
keyMap DashboardKeyMap
|
||||
svc *service.Services
|
||||
width int
|
||||
height int
|
||||
focusedPane int // 0 = list, 1 = detail
|
||||
type ValidationFeedbackMsg struct {
|
||||
Feedback task.ValidationFeedback
|
||||
}
|
||||
|
||||
func NewDashboard(svc *service.Services) *Model {
|
||||
type Model struct {
|
||||
header Header
|
||||
issueList IssueList
|
||||
issueDetail IssueDetail
|
||||
helpBar HelpBar
|
||||
keyMap DashboardKeyMap
|
||||
svc *service.Services
|
||||
width int
|
||||
height int
|
||||
focusedPane int // 0 = list, 1 = detail
|
||||
feedbackChan chan task.ValidationFeedback
|
||||
quitChan chan bool
|
||||
currentFeedback task.ValidationFeedback
|
||||
showComplete bool
|
||||
}
|
||||
|
||||
func NewDashboard(svc *service.Services, feedbackChan chan task.ValidationFeedback, quitChan chan bool) *Model {
|
||||
m := &Model{
|
||||
header: NewHeader("Project Manager Dashboard"),
|
||||
keyMap: defaultDashboardKeyMap,
|
||||
svc: svc,
|
||||
width: 80,
|
||||
height: 24,
|
||||
focusedPane: 0,
|
||||
header: NewHeader("Project Manager Dashboard"),
|
||||
keyMap: defaultDashboardKeyMap,
|
||||
svc: svc,
|
||||
width: 80,
|
||||
height: 24,
|
||||
focusedPane: 0,
|
||||
feedbackChan: feedbackChan,
|
||||
quitChan: quitChan,
|
||||
}
|
||||
|
||||
m.issueList = NewIssueList(svc, 0, 0)
|
||||
@@ -39,7 +50,14 @@ func NewDashboard(svc *service.Services) *Model {
|
||||
}
|
||||
|
||||
func (m *Model) Init() tea.Cmd {
|
||||
return nil
|
||||
return m.listenForValidation()
|
||||
}
|
||||
|
||||
func (m *Model) listenForValidation() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
feedback := <-m.feedbackChan
|
||||
return ValidationFeedbackMsg{Feedback: feedback}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) IsFocusedOnList() bool {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
@@ -22,6 +22,17 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.width = msg.Width
|
||||
m.height = msg.Height
|
||||
return m, nil
|
||||
|
||||
case ValidationFeedbackMsg:
|
||||
m.currentFeedback = msg.Feedback
|
||||
if msg.Feedback.Success {
|
||||
m.showComplete = true
|
||||
if m.quitChan != nil {
|
||||
close(m.quitChan)
|
||||
}
|
||||
return m, tea.Quit
|
||||
}
|
||||
return m, m.listenForValidation()
|
||||
}
|
||||
|
||||
cmd, changed := m.issueList.Update(msg)
|
||||
|
||||
@@ -15,10 +15,10 @@ func (m *Model) View() string {
|
||||
header := m.header.View(m.width)
|
||||
headerHeight := m.header.Height()
|
||||
|
||||
bottomView := m.helpBar.View()
|
||||
bottomHeight := m.helpBar.Height()
|
||||
footer := m.footer()
|
||||
footerHeight := lipgloss.Height(footer)
|
||||
|
||||
contentHeight := m.height - headerHeight - bottomHeight
|
||||
contentHeight := m.height - headerHeight - footerHeight
|
||||
|
||||
totalContentWidth := m.width - 1
|
||||
listWidth := totalContentWidth * styles.ListViewRatio / 100
|
||||
@@ -32,5 +32,16 @@ func (m *Model) View() string {
|
||||
|
||||
content := lipgloss.JoinHorizontal(lipgloss.Left, listView, detailView)
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Left, header, content, bottomView)
|
||||
return lipgloss.JoinVertical(lipgloss.Left, header, content, footer)
|
||||
}
|
||||
|
||||
func (m *Model) footer() string {
|
||||
feedbackStatus := m.currentFeedback.Message
|
||||
|
||||
if feedbackStatus == "" {
|
||||
return m.helpBar.View()
|
||||
}
|
||||
|
||||
m.helpBar.SetWidth(m.width - lipgloss.Width(feedbackStatus))
|
||||
return lipgloss.JoinHorizontal(lipgloss.Left, m.helpBar.View(), feedbackStatus)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package views
|
||||
|
||||
import (
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard"
|
||||
)
|
||||
|
||||
func NewDashboardView(svc *service.Services) *dashboard.Model {
|
||||
return dashboard.NewDashboard(svc)
|
||||
func NewDashboardView(svc *service.Services, feedbackChan chan task.ValidationFeedback, quitChan chan bool) *dashboard.Model {
|
||||
return dashboard.NewDashboard(svc, feedbackChan, quitChan)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user