Skip to content

Commit 45c3ac7

Browse files
committed
feat(tui): clear add collection form on success
Clears the collection name from the form only after a collection is successfully added. The name persists if the user cancels.
1 parent 8d50947 commit 45c3ac7

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

internal/tui/components/form.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ func (f Form) GetValues() []string {
6464
return values
6565
}
6666

67+
func (f *Form) Clear() {
68+
for i := range f.inputs {
69+
f.inputs[i].Clear()
70+
}
71+
}
72+
6773
func (f Form) Update(msg tea.Msg) (Form, tea.Cmd) {
6874
var cmd tea.Cmd
6975
var cmds []tea.Cmd

internal/tui/components/text_input.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func (t *TextInput) Blur() {
4848
t.textInput.Blur()
4949
}
5050

51+
func (t *TextInput) Clear() {
52+
t.textInput.SetValue("")
53+
}
54+
5155
func (t TextInput) Focused() bool {
5256
return t.textInput.Focused()
5357
}

internal/tui/views/add_collection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (v AddCollectionView) Update(msg tea.Msg) (AddCollectionView, tea.Cmd) {
6262

6363
case CollectionCreatedMsg:
6464
// Collection was created successfully
65+
v.form.Clear()
6566
return v, func() tea.Msg { return BackToCollectionsMsg{} }
6667

6768
case CollectionCreateErrorMsg:

0 commit comments

Comments
 (0)