diff options
author | T <t@tjp.lol> | 2025-08-13 14:47:24 -0600 |
---|---|---|
committer | T <t@tjp.lol> | 2025-08-13 14:47:55 -0600 |
commit | d6781f3e5b431057c23b2deaa943f273699e37f5 (patch) | |
tree | 269ef61bc44750881068ebd94d643a9b3a57c20c /internal/tui/form.go | |
parent | 389b72e55b04ccfc02b04eb81cb8f7bb7a5c8b59 (diff) |
client and project modal field suggestions, ctrl+n to accept
Diffstat (limited to 'internal/tui/form.go')
-rw-r--r-- | internal/tui/form.go | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/internal/tui/form.go b/internal/tui/form.go index 7dae012..3a1e5f6 100644 --- a/internal/tui/form.go +++ b/internal/tui/form.go @@ -13,9 +13,18 @@ import ( "github.com/charmbracelet/lipgloss" ) +type suggestionType int + +const ( + noSuggestions suggestionType = iota + suggestClients + suggestProjects +) + type FormField struct { textinput.Model - label string + label string + suggestions suggestionType } func (ff FormField) Update(msg tea.Msg) (FormField, tea.Cmd) { @@ -117,8 +126,8 @@ func NewEntryEditorForm() Form { form := NewForm([]FormField{ newTimestampField("Start time"), newOptionalTimestampField("End time"), - {Model: textinput.New(), label: "Client"}, - {Model: textinput.New(), label: "Project"}, + {Model: textinput.New(), label: "Client", suggestions: suggestClients}, + {Model: textinput.New(), label: "Project", suggestions: suggestProjects}, {Model: textinput.New(), label: "Description"}, newOptionalFloatField("Hourly Rate"), }) @@ -141,7 +150,7 @@ func NewClientForm() Form { func NewProjectForm() Form { form := NewForm([]FormField{ {Model: textinput.New(), label: "Name"}, - {Model: textinput.New(), label: "Client"}, + {Model: textinput.New(), label: "Client", suggestions: suggestClients}, newOptionalFloatField("Hourly Rate"), }) form.SelectedStyle = &modalFocusedInputStyle @@ -152,8 +161,8 @@ func NewProjectForm() Form { func NewHistoryFilterForm() Form { form := NewForm([]FormField{ newDateRangeField("Date Range"), - {Model: textinput.New(), label: "Client (optional)"}, - {Model: textinput.New(), label: "Project (optional)"}, + {Model: textinput.New(), label: "Client (optional)", suggestions: suggestClients}, + {Model: textinput.New(), label: "Project (optional)", suggestions: suggestProjects}, }) form.SelectedStyle = &modalFocusedInputStyle form.UnselectedStyle = &modalBlurredInputStyle @@ -212,6 +221,30 @@ func (ff Form) View() string { return content } +func (f *Form) SetSuggestions(m AppModel) { + for i := range f.fields { + ff := &f.fields[i] + switch ff.suggestions { + case suggestClients: + clients := make([]string, len(m.projectsBox.clients)) + for i, cl := range m.projectsBox.clients { + clients[i] = cl.Name + } + ff.SetSuggestions(clients) + ff.ShowSuggestions = true + case suggestProjects: + projNames := make([]string, 0, 10) + for _, cl := range m.projectsBox.clients { + for _, proj := range m.projectsBox.projects[cl.ID] { + projNames = append(projNames, proj.Name) + } + } + ff.SetSuggestions(projNames) + ff.ShowSuggestions = true + } + } +} + var ( modalFocusedInputStyle = lipgloss.NewStyle(). Border(lipgloss.DoubleBorder()). |