Skip to content

Commit 6657dff

Browse files
committed
chore(tui): enable filtering in collections view
1 parent 25d47fd commit 6657dff

4 files changed

Lines changed: 56 additions & 37 deletions

File tree

internal/tui/app/model.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,23 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4040

4141
switch msg := msg.(type) {
4242
case tea.KeyMsg:
43-
switch msg.String() {
44-
case "ctrl+c", "q":
45-
if m.mode == CollectionsViewMode {
46-
return m, tea.Quit
47-
}
48-
// For other views, 'q' goes back to collections
49-
m.mode = CollectionsViewMode
50-
return m, nil
51-
case "a":
52-
if m.mode == CollectionsViewMode {
53-
m.mode = AddCollectionViewMode
43+
// Handle global keybinds only when not in filtering mode
44+
isFiltering := m.mode == CollectionsViewMode && m.collectionsView.IsFiltering()
45+
46+
if !isFiltering {
47+
switch msg.String() {
48+
case "ctrl+c", "q":
49+
if m.mode == CollectionsViewMode {
50+
return m, tea.Quit
51+
}
52+
// For other views, 'q' goes back to collections
53+
m.mode = CollectionsViewMode
5454
return m, nil
55+
case "a":
56+
if m.mode == CollectionsViewMode {
57+
m.mode = AddCollectionViewMode
58+
return m, nil
59+
}
5560
}
5661
}
5762
case tea.WindowSizeMsg:

internal/tui/components/layout.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ func (l Layout) Content(content string, headerHeight, footerHeight int) string {
4646
func (l Layout) FullView(title, content, instructions string) string {
4747
header := l.Header(title)
4848
footer := l.Footer(instructions)
49-
49+
5050
headerHeight := lipgloss.Height(header)
5151
footerHeight := lipgloss.Height(footer)
52-
52+
5353
contentArea := l.Content(content, headerHeight, footerHeight)
54-
54+
5555
return lipgloss.JoinVertical(
5656
lipgloss.Left,
5757
header,
5858
contentArea,
5959
footer,
6060
)
61-
}
61+
}
62+

internal/tui/components/paginated_list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewPaginatedList(items []ListItem, title string) PaginatedList {
3434
l := list.New(listItems, paginatedItemDelegate{}, defaultWidth, defaultHeight)
3535
l.Title = title
3636
l.SetShowStatusBar(false)
37-
l.SetFilteringEnabled(false)
37+
l.SetFilteringEnabled(true) // Enable filtering
3838
l.SetShowHelp(false) // Disable built-in help text
3939
l.Styles.Title = styles.TitleStyle
4040

@@ -81,6 +81,10 @@ func (pl PaginatedList) SelectedIndex() int {
8181
return pl.list.Index()
8282
}
8383

84+
func (pl PaginatedList) IsFiltering() bool {
85+
return pl.list.FilterState() == list.Filtering
86+
}
87+
8488
type paginatedItemDelegate struct{}
8589

8690
func (d paginatedItemDelegate) Height() int { return 1 }

internal/tui/views/collections.go

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,31 @@ func (v CollectionsView) Update(msg tea.Msg) (CollectionsView, tea.Cmd) {
109109
break
110110
}
111111

112-
// Handle pagination keys first, before the list can consume them
113-
switch msg.String() {
114-
case "n", "right":
115-
// Next page
116-
if v.currentPage < v.pagination.TotalPages {
117-
return v, func() tea.Msg {
118-
return v.loadCollectionsPage(v.currentPage+1, v.pageSize)
112+
// Handle pagination keys only when not filtering
113+
if !v.list.IsFiltering() {
114+
switch msg.String() {
115+
case "n", "right":
116+
// Next page
117+
if v.currentPage < v.pagination.TotalPages {
118+
return v, func() tea.Msg {
119+
return v.loadCollectionsPage(v.currentPage+1, v.pageSize)
120+
}
119121
}
120-
}
121-
return v, nil
122-
case "p", "left":
123-
// Previous page
124-
if v.currentPage > 1 {
125-
return v, func() tea.Msg {
126-
return v.loadCollectionsPage(v.currentPage-1, v.pageSize)
122+
return v, nil
123+
case "p", "left":
124+
// Previous page
125+
if v.currentPage > 1 {
126+
return v, func() tea.Msg {
127+
return v.loadCollectionsPage(v.currentPage-1, v.pageSize)
128+
}
127129
}
130+
return v, nil
128131
}
129-
return v, nil
130-
default:
131-
// Forward other keys to the list
132-
v.list, cmd = v.list.Update(msg)
133132
}
134133

134+
// Always forward keys to the list (handles filtering and navigation)
135+
v.list, cmd = v.list.Update(msg)
136+
135137
default:
136138
if v.initialized {
137139
v.list, cmd = v.list.Update(msg)
@@ -141,6 +143,10 @@ func (v CollectionsView) Update(msg tea.Msg) (CollectionsView, tea.Cmd) {
141143
return v, cmd
142144
}
143145

146+
func (v CollectionsView) IsFiltering() bool {
147+
return v.initialized && v.list.IsFiltering()
148+
}
149+
144150
func (v CollectionsView) View() string {
145151
if !v.initialized {
146152
return v.layout.FullView(
@@ -152,9 +158,12 @@ func (v CollectionsView) View() string {
152158

153159
content := v.list.View()
154160

155-
// Build instructions with pagination info
156-
instructions := "↑↓: navigate • a: add • enter: edit • d: delete • q: quit"
157-
if v.pagination.TotalPages > 1 {
161+
// Build instructions with pagination and filter info
162+
instructions := "↑↓: navigate • /: filter • enter: edit • d: delete • q: quit"
163+
if !v.list.IsFiltering() {
164+
instructions = "↑↓: navigate • a: add • /: filter • enter: edit • d: delete • q: quit"
165+
}
166+
if v.pagination.TotalPages > 1 && !v.list.IsFiltering() {
158167
instructions += fmt.Sprintf(" • p/n: prev/next page (%d/%d)", v.currentPage, v.pagination.TotalPages)
159168
}
160169

0 commit comments

Comments
 (0)