|
7 | 7 | "github.com/charmbracelet/bubbles/list" |
8 | 8 | tea "github.com/charmbracelet/bubbletea" |
9 | 9 | "github.com/charmbracelet/lipgloss" |
| 10 | + "github.com/maniac-en/req/internal/log" |
10 | 11 | "github.com/maniac-en/req/internal/tui/keybinds" |
11 | 12 | "github.com/maniac-en/req/internal/tui/messages" |
12 | 13 | ) |
@@ -62,19 +63,16 @@ func (o OptionsProvider[T, U]) Update(msg tea.Msg) (OptionsProvider[T, U], tea.C |
62 | 63 | o.input.OnFocus() |
63 | 64 | o.focused = textComponent |
64 | 65 | return o, tea.Batch(cmds...) |
| 66 | + case key.Matches(msg, keybinds.Keys.Remove): |
| 67 | + return o, func() tea.Msg { return messages.DeleteItem{ItemID: int64(o.GetSelected().ID)} } |
65 | 68 | } |
66 | 69 | } |
67 | 70 | } |
68 | 71 | case messages.ItemAdded: |
69 | 72 | o.input.OnBlur() |
70 | 73 | o.focused = listComponent |
71 | 74 | o.list.SetSize(o.list.Width(), o.height) |
72 | | - newItems, err := o.getItems(context.Background()) |
73 | | - if err != nil { |
74 | | - |
75 | | - } |
76 | | - o.list.SetItems(o.itemMapper(newItems)) |
77 | | - |
| 75 | + o.RefreshItems() |
78 | 76 | } |
79 | 77 | switch o.focused { |
80 | 78 | case listComponent: |
@@ -108,6 +106,15 @@ func (o OptionsProvider[T, U]) IsFiltering() bool { |
108 | 106 | return o.list.FilterState() == list.Filtering |
109 | 107 | } |
110 | 108 |
|
| 109 | +func (o *OptionsProvider[T, U]) RefreshItems() { |
| 110 | + newItems, err := o.getItems(context.Background()) |
| 111 | + if err != nil { |
| 112 | + log.Warn("Fetching items failed") |
| 113 | + return |
| 114 | + } |
| 115 | + o.list.SetItems(o.itemMapper(newItems)) |
| 116 | +} |
| 117 | + |
111 | 118 | func initList[T, U any](config *ListConfig[T, U]) list.Model { |
112 | 119 |
|
113 | 120 | rawItems, err := config.GetItemsFunc(context.Background()) |
|
0 commit comments