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