change tui and status command to use callback.
add keybind to submit
This commit is contained in:
@@ -15,6 +15,7 @@ type ValidationFeedback = models.ValidationFeedback
|
|||||||
type Tui struct {
|
type Tui struct {
|
||||||
feedbackChan chan ValidationFeedback
|
feedbackChan chan ValidationFeedback
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
|
submitChan chan<- struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Tui {
|
func New() *Tui {
|
||||||
@@ -29,7 +30,7 @@ func (t *Tui) Run(ctx context.Context, config Config) error {
|
|||||||
|
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
p := tea.NewProgram(views.NewDashboardView(app, t.feedbackChan, t.quitChan),
|
p := tea.NewProgram(views.NewDashboardView(app, t.feedbackChan, t.quitChan, t.submitChan),
|
||||||
tea.WithAltScreen(), tea.WithMouseAllMotion())
|
tea.WithAltScreen(), tea.WithMouseAllMotion())
|
||||||
|
|
||||||
if t.quitChan != nil {
|
if t.quitChan != nil {
|
||||||
@@ -50,3 +51,7 @@ func (t *Tui) SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bo
|
|||||||
t.feedbackChan = feedbackChan
|
t.feedbackChan = feedbackChan
|
||||||
t.quitChan = quitChan
|
t.quitChan = quitChan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tui) SetSubmitChan(submitChan chan<- struct{}) {
|
||||||
|
t.submitChan = submitChan
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,15 +31,16 @@ func (h HelpBar) View() string {
|
|||||||
|
|
||||||
func (h HelpBar) shortHelp() string {
|
func (h HelpBar) shortHelp() string {
|
||||||
keys := []string{
|
keys := []string{
|
||||||
styles.HighlightKey("tab") + " switch",
|
styles.HighlightKey("tab") + "switch ",
|
||||||
styles.HighlightKey("↑/k") + " up",
|
styles.HighlightKey("↑/k") + "up ",
|
||||||
styles.HighlightKey("↓/j") + " down",
|
styles.HighlightKey("↓/j") + "down ",
|
||||||
styles.HighlightKey("pgup/pgdn") + " page",
|
styles.HighlightKey("pgup/pgdn") + "page ",
|
||||||
styles.HighlightKey("a") + " add",
|
styles.HighlightKey("a") + "add ",
|
||||||
styles.HighlightKey("e/d/s/p/t/c") + " edit",
|
styles.HighlightKey("e/d/s/p/t/c") + "edit ",
|
||||||
styles.HighlightKey("x") + " delete",
|
styles.HighlightKey("x") + "delete ",
|
||||||
styles.HighlightKey("q") + " quit",
|
styles.HighlightKey("q") + "quit ",
|
||||||
styles.HighlightKey("?") + " help",
|
styles.HighlightKey("S") + "submit ",
|
||||||
|
styles.HighlightKey("?") + "help ",
|
||||||
}
|
}
|
||||||
content := lipgloss.JoinHorizontal(lipgloss.Left, keys...)
|
content := lipgloss.JoinHorizontal(lipgloss.Left, keys...)
|
||||||
return lipgloss.NewStyle().
|
return lipgloss.NewStyle().
|
||||||
|
|||||||
@@ -6,21 +6,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DashboardKeyMap struct {
|
type DashboardKeyMap struct {
|
||||||
Help key.Binding
|
Help key.Binding
|
||||||
Quit key.Binding
|
Quit key.Binding
|
||||||
SelectIssue key.Binding
|
SelectIssue key.Binding
|
||||||
BackToList key.Binding
|
BackToList key.Binding
|
||||||
ScrollUp key.Binding
|
ScrollUp key.Binding
|
||||||
ScrollDown key.Binding
|
ScrollDown key.Binding
|
||||||
SwitchWindow key.Binding
|
SwitchWindow key.Binding
|
||||||
EditTitle key.Binding
|
EditTitle key.Binding
|
||||||
EditDescription key.Binding
|
EditDescription key.Binding
|
||||||
ChangeStatus key.Binding
|
ChangeStatus key.Binding
|
||||||
ChangePriority key.Binding
|
ChangePriority key.Binding
|
||||||
ChangeType key.Binding
|
ChangeType key.Binding
|
||||||
AddComment key.Binding
|
AddComment key.Binding
|
||||||
AddIssue key.Binding
|
AddIssue key.Binding
|
||||||
DeleteIssue key.Binding
|
DeleteIssue key.Binding
|
||||||
|
SubmitValidation key.Binding
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultDashboardKeyMap = DashboardKeyMap{
|
var defaultDashboardKeyMap = DashboardKeyMap{
|
||||||
@@ -84,6 +85,10 @@ var defaultDashboardKeyMap = DashboardKeyMap{
|
|||||||
key.WithKeys("x"),
|
key.WithKeys("x"),
|
||||||
key.WithHelp("x", "delete issue"),
|
key.WithHelp("x", "delete issue"),
|
||||||
),
|
),
|
||||||
|
SubmitValidation: key.NewBinding(
|
||||||
|
key.WithKeys("S"),
|
||||||
|
key.WithHelp("S", "submit validation"),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
|
func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
|
||||||
@@ -153,6 +158,14 @@ func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
|
|||||||
d.startConfirmDelete(selected.ID, fl.Index())
|
d.startConfirmDelete(selected.ID, fl.Index())
|
||||||
d.logAction("tui opened delete confirmation")
|
d.logAction("tui opened delete confirmation")
|
||||||
}
|
}
|
||||||
|
case key.Matches(msg, d.keyMap.SubmitValidation):
|
||||||
|
if d.submitChan != nil {
|
||||||
|
select {
|
||||||
|
case d.submitChan <- struct{}{}:
|
||||||
|
d.logAction("tui submitted validation")
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
@@ -54,9 +54,10 @@ type Model struct {
|
|||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
currentFeedback models.ValidationFeedback
|
currentFeedback models.ValidationFeedback
|
||||||
showComplete bool
|
showComplete bool
|
||||||
|
submitChan chan<- struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDashboard(app *app.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool) *Model {
|
func NewDashboard(app *app.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool, submitChan chan<- struct{}) *Model {
|
||||||
m := &Model{
|
m := &Model{
|
||||||
header: NewHeader("Project Manager Dashboard"),
|
header: NewHeader("Project Manager Dashboard"),
|
||||||
keyMap: defaultDashboardKeyMap,
|
keyMap: defaultDashboardKeyMap,
|
||||||
@@ -68,6 +69,7 @@ func NewDashboard(app *app.App, feedbackChan chan models.ValidationFeedback, qui
|
|||||||
focusedPaneClosed: 0,
|
focusedPaneClosed: 0,
|
||||||
feedbackChan: feedbackChan,
|
feedbackChan: feedbackChan,
|
||||||
quitChan: quitChan,
|
quitChan: quitChan,
|
||||||
|
submitChan: submitChan,
|
||||||
}
|
}
|
||||||
|
|
||||||
allIssues, _ := app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
allIssues, _ := app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ import (
|
|||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard"
|
"github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewDashboardView(app *app.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool) *dashboard.Model {
|
func NewDashboardView(app *app.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool, submitChan chan<- struct{}) *dashboard.Model {
|
||||||
return dashboard.NewDashboard(app, feedbackChan, quitChan)
|
return dashboard.NewDashboard(app, feedbackChan, quitChan, submitChan)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user