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 {
|
||||
feedbackChan chan ValidationFeedback
|
||||
quitChan chan bool
|
||||
submitChan chan<- struct{}
|
||||
}
|
||||
|
||||
func New() *Tui {
|
||||
@@ -29,7 +30,7 @@ func (t *Tui) Run(ctx context.Context, config Config) error {
|
||||
|
||||
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())
|
||||
|
||||
if t.quitChan != nil {
|
||||
@@ -50,3 +51,7 @@ func (t *Tui) SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bo
|
||||
t.feedbackChan = feedbackChan
|
||||
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 {
|
||||
keys := []string{
|
||||
styles.HighlightKey("tab") + " switch",
|
||||
styles.HighlightKey("↑/k") + " up",
|
||||
styles.HighlightKey("↓/j") + " down",
|
||||
styles.HighlightKey("pgup/pgdn") + " page",
|
||||
styles.HighlightKey("a") + " add",
|
||||
styles.HighlightKey("e/d/s/p/t/c") + " edit",
|
||||
styles.HighlightKey("x") + " delete",
|
||||
styles.HighlightKey("q") + " quit",
|
||||
styles.HighlightKey("?") + " help",
|
||||
styles.HighlightKey("tab") + "switch ",
|
||||
styles.HighlightKey("↑/k") + "up ",
|
||||
styles.HighlightKey("↓/j") + "down ",
|
||||
styles.HighlightKey("pgup/pgdn") + "page ",
|
||||
styles.HighlightKey("a") + "add ",
|
||||
styles.HighlightKey("e/d/s/p/t/c") + "edit ",
|
||||
styles.HighlightKey("x") + "delete ",
|
||||
styles.HighlightKey("q") + "quit ",
|
||||
styles.HighlightKey("S") + "submit ",
|
||||
styles.HighlightKey("?") + "help ",
|
||||
}
|
||||
content := lipgloss.JoinHorizontal(lipgloss.Left, keys...)
|
||||
return lipgloss.NewStyle().
|
||||
|
||||
@@ -6,21 +6,22 @@ import (
|
||||
)
|
||||
|
||||
type DashboardKeyMap struct {
|
||||
Help key.Binding
|
||||
Quit key.Binding
|
||||
SelectIssue key.Binding
|
||||
BackToList key.Binding
|
||||
ScrollUp key.Binding
|
||||
ScrollDown key.Binding
|
||||
SwitchWindow key.Binding
|
||||
EditTitle key.Binding
|
||||
EditDescription key.Binding
|
||||
ChangeStatus key.Binding
|
||||
ChangePriority key.Binding
|
||||
ChangeType key.Binding
|
||||
AddComment key.Binding
|
||||
AddIssue key.Binding
|
||||
DeleteIssue key.Binding
|
||||
Help key.Binding
|
||||
Quit key.Binding
|
||||
SelectIssue key.Binding
|
||||
BackToList key.Binding
|
||||
ScrollUp key.Binding
|
||||
ScrollDown key.Binding
|
||||
SwitchWindow key.Binding
|
||||
EditTitle key.Binding
|
||||
EditDescription key.Binding
|
||||
ChangeStatus key.Binding
|
||||
ChangePriority key.Binding
|
||||
ChangeType key.Binding
|
||||
AddComment key.Binding
|
||||
AddIssue key.Binding
|
||||
DeleteIssue key.Binding
|
||||
SubmitValidation key.Binding
|
||||
}
|
||||
|
||||
var defaultDashboardKeyMap = DashboardKeyMap{
|
||||
@@ -84,6 +85,10 @@ var defaultDashboardKeyMap = DashboardKeyMap{
|
||||
key.WithKeys("x"),
|
||||
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 {
|
||||
@@ -153,6 +158,14 @@ func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
|
||||
d.startConfirmDelete(selected.ID, fl.Index())
|
||||
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
|
||||
|
||||
@@ -54,9 +54,10 @@ type Model struct {
|
||||
quitChan chan bool
|
||||
currentFeedback models.ValidationFeedback
|
||||
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{
|
||||
header: NewHeader("Project Manager Dashboard"),
|
||||
keyMap: defaultDashboardKeyMap,
|
||||
@@ -68,6 +69,7 @@ func NewDashboard(app *app.App, feedbackChan chan models.ValidationFeedback, qui
|
||||
focusedPaneClosed: 0,
|
||||
feedbackChan: feedbackChan,
|
||||
quitChan: quitChan,
|
||||
submitChan: submitChan,
|
||||
}
|
||||
|
||||
allIssues, _ := app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||
|
||||
@@ -6,6 +6,6 @@ import (
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard"
|
||||
)
|
||||
|
||||
func NewDashboardView(app *app.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool) *dashboard.Model {
|
||||
return dashboard.NewDashboard(app, feedbackChan, quitChan)
|
||||
func NewDashboardView(app *app.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool, submitChan chan<- struct{}) *dashboard.Model {
|
||||
return dashboard.NewDashboard(app, feedbackChan, quitChan, submitChan)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user