Skip to content

Commit cd91f58

Browse files
committed
chore(tui): update footer, remove unused code
1 parent eeeb5eb commit cd91f58

13 files changed

Lines changed: 78 additions & 112 deletions

File tree

internal/tui/app/context.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ func NewContext(
2727
History: history,
2828
}
2929
}
30-

internal/tui/app/model.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func NewModel(ctx *Context) Model {
3333
mode: CollectionsViewMode,
3434
collectionsView: views.NewCollectionsView(ctx.Collections),
3535
addCollectionView: views.NewAddCollectionView(ctx.Collections),
36-
// editCollectionView will be created on demand
3736
}
3837
}
3938

@@ -46,7 +45,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4645

4746
switch msg := msg.(type) {
4847
case tea.KeyMsg:
49-
// Handle global keybinds only when not in filtering mode
5048
isFiltering := m.mode == CollectionsViewMode && m.collectionsView.IsFiltering()
5149

5250
if !isFiltering {
@@ -55,7 +53,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5553
if m.mode == CollectionsViewMode {
5654
return m, tea.Quit
5755
}
58-
// For other views, 'q' goes back to collections
5956
m.mode = CollectionsViewMode
6057
return m, nil
6158
case "a":
@@ -66,7 +63,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6663
}
6764
case "e":
6865
if m.mode == CollectionsViewMode {
69-
// Get selected collection and switch to edit mode
7066
if selectedItem := m.collectionsView.GetSelectedItem(); selectedItem != nil {
7167
m.selectedIndex = m.collectionsView.GetSelectedIndex()
7268
m.mode = EditCollectionViewMode
@@ -78,7 +74,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7874
}
7975
case "x":
8076
if m.mode == CollectionsViewMode {
81-
// Delete selected collection
8277
if selectedItem := m.collectionsView.GetSelectedItem(); selectedItem != nil {
8378
return m, func() tea.Msg {
8479
err := m.ctx.Collections.Delete(context.Background(), selectedItem.ID)
@@ -96,29 +91,24 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9691
m.height = msg.Height
9792
case views.BackToCollectionsMsg:
9893
m.mode = CollectionsViewMode
99-
// Reload collections to show any changes
10094
m.collectionsView.SetSelectedIndex(m.selectedIndex)
10195
return m, m.collectionsView.Init()
10296
case views.EditCollectionMsg:
10397
m.mode = EditCollectionViewMode
10498
m.editCollectionView = views.NewEditCollectionView(m.ctx.Collections, msg.Collection)
10599
return m, nil
106100
case views.CollectionDeletedMsg:
107-
// Collection deleted, reload collections view
108101
return m, m.collectionsView.Init()
109102
case views.CollectionDeleteErrorMsg:
110-
// Delete failed, just continue
111103
return m, nil
112104
case views.CollectionCreatedMsg:
113-
// Collection created successfully, clear form and go to first page with first item selected
114105
m.addCollectionView.ClearForm()
115106
m.mode = CollectionsViewMode
116-
m.selectedIndex = 0 // Reset to first item
107+
m.selectedIndex = 0
117108
m.collectionsView.SetSelectedIndex(m.selectedIndex)
118109
return m, m.collectionsView.Init()
119110
}
120111

121-
// Forward messages to the appropriate view
122112
switch m.mode {
123113
case CollectionsViewMode:
124114
m.collectionsView, cmd = m.collectionsView.Update(msg)

internal/tui/components/collection_item.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ func (i CollectionItem) GetDescription() string {
3333

3434
func (i CollectionItem) GetCollection() collections.CollectionEntity {
3535
return i.collection
36-
}
36+
}

internal/tui/components/form.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ import (
77
)
88

99
type Form struct {
10-
inputs []TextInput
11-
focusIndex int
12-
width int
13-
height int
14-
title string
15-
submitText string
16-
cancelText string
10+
inputs []TextInput
11+
focusIndex int
12+
width int
13+
height int
14+
title string
15+
submitText string
16+
cancelText string
1717
}
1818

1919
func NewForm(title string, inputs []TextInput) Form {
20-
// Focus the first input by default
2120
if len(inputs) > 0 {
2221
inputs[0].Focus()
2322
}
24-
23+
2524
return Form{
2625
inputs: inputs,
2726
focusIndex: 0,
@@ -34,10 +33,9 @@ func NewForm(title string, inputs []TextInput) Form {
3433
func (f *Form) SetSize(width, height int) {
3534
f.width = width
3635
f.height = height
37-
38-
// Set width for all inputs
36+
3937
for i := range f.inputs {
40-
f.inputs[i].SetWidth(width - 4) // Account for padding
38+
f.inputs[i].SetWidth(width - 4)
4139
}
4240
}
4341

@@ -99,7 +97,7 @@ func (f *Form) nextInput() {
9997
if len(f.inputs) == 0 {
10098
return
10199
}
102-
100+
103101
f.inputs[f.focusIndex].Blur()
104102
f.focusIndex = (f.focusIndex + 1) % len(f.inputs)
105103
f.inputs[f.focusIndex].Focus()
@@ -109,7 +107,7 @@ func (f *Form) prevInput() {
109107
if len(f.inputs) == 0 {
110108
return
111109
}
112-
110+
113111
f.inputs[f.focusIndex].Blur()
114112
f.focusIndex--
115113
if f.focusIndex < 0 {
@@ -120,22 +118,22 @@ func (f *Form) prevInput() {
120118

121119
func (f Form) View() string {
122120
var content []string
123-
121+
124122
// Add form inputs
125123
for _, input := range f.inputs {
126124
content = append(content, input.View())
127125
}
128-
126+
129127
// Add spacing
130128
content = append(content, "")
131-
129+
132130
// Add action buttons
133131
buttonStyle := styles.ListItemStyle.Copy().
134132
Padding(0, 2).
135133
Background(styles.Primary).
136134
Foreground(styles.TextPrimary).
137135
Bold(true)
138-
136+
139137
buttons := lipgloss.JoinHorizontal(
140138
lipgloss.Top,
141139
buttonStyle.Render(f.submitText+" (enter)"),
@@ -145,6 +143,6 @@ func (f Form) View() string {
145143
Render(f.cancelText+" (esc)"),
146144
)
147145
content = append(content, buttons)
148-
146+
149147
return lipgloss.JoinVertical(lipgloss.Left, content...)
150-
}
148+
}

internal/tui/components/layout.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ func (l Layout) FullView(title, content, instructions string) string {
5959
footer,
6060
)
6161
}
62-

internal/tui/components/paginated_list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewPaginatedList(items []ListItem, title string) PaginatedList {
3535
l.Title = title
3636
l.SetShowStatusBar(false)
3737
l.SetFilteringEnabled(true) // Enable filtering
38-
l.SetShowHelp(false) // Disable built-in help text
38+
l.SetShowHelp(false) // Disable built-in help text
3939
l.Styles.Title = styles.TitleStyle
4040

4141
return PaginatedList{
@@ -46,7 +46,7 @@ func NewPaginatedList(items []ListItem, title string) PaginatedList {
4646
func (pl *PaginatedList) SetSize(width, height int) {
4747
pl.width = width
4848
pl.height = height
49-
49+
5050
// Safety check to prevent nil pointer dereference
5151
if width > 0 && height > 0 {
5252
pl.list.SetWidth(width)
@@ -107,4 +107,4 @@ func (d paginatedItemDelegate) Render(w io.Writer, m list.Model, index int, item
107107

108108
fmt.Fprint(w, fn(str))
109109
}
110-
}
110+
}

internal/tui/components/text_input.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ func (t TextInput) View() string {
6666
labelStyle := styles.TitleStyle.Copy().
6767
Width(12).
6868
Align(lipgloss.Right)
69-
69+
7070
return lipgloss.JoinHorizontal(
7171
lipgloss.Top,
7272
labelStyle.Render(t.label+":"),
7373
" ",
7474
t.textInput.View(),
7575
)
76-
}
76+
}

internal/tui/styles/colors.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import "github.com/charmbracelet/lipgloss"
44

55
var (
66
// Primary colors
7-
Primary = lipgloss.Color("62") // Blue
8-
Secondary = lipgloss.Color("170") // Purple
9-
Success = lipgloss.Color("40") // Green
10-
Warning = lipgloss.Color("220") // Yellow
11-
Error = lipgloss.Color("196") // Red
12-
7+
Primary = lipgloss.Color("62") // Blue
8+
Secondary = lipgloss.Color("170") // Purple
9+
Success = lipgloss.Color("40") // Green
10+
Warning = lipgloss.Color("220") // Yellow
11+
Error = lipgloss.Color("196") // Red
12+
1313
// Text colors
1414
TextPrimary = lipgloss.Color("230") // Light
1515
TextSecondary = lipgloss.Color("241") // Dim
1616
TextMuted = lipgloss.Color("238") // Very dim
17-
17+
1818
// Background colors
1919
BackgroundPrimary = lipgloss.Color("0") // Black
2020
BackgroundSecondary = lipgloss.Color("234") // Dark gray
21-
)
21+
)

internal/tui/styles/layout.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ import "github.com/charmbracelet/lipgloss"
44

55
var (
66
HeaderStyle = lipgloss.NewStyle().
7-
Padding(1, 2).
8-
Background(Primary).
9-
Foreground(TextPrimary).
10-
Bold(true).
11-
Align(lipgloss.Center)
7+
Padding(1, 2).
8+
Background(Primary).
9+
Foreground(TextPrimary).
10+
Bold(true).
11+
Align(lipgloss.Center)
1212

1313
FooterStyle = lipgloss.NewStyle().
14-
Padding(0, 2).
15-
Foreground(TextSecondary).
16-
Align(lipgloss.Center)
14+
Padding(0, 2).
15+
Foreground(TextSecondary).
16+
Align(lipgloss.Center)
1717

1818
ContentStyle = lipgloss.NewStyle().
19-
Padding(1, 2)
19+
Padding(1, 2)
2020

2121
ListItemStyle = lipgloss.NewStyle().
22-
PaddingLeft(4)
22+
PaddingLeft(4)
2323

2424
SelectedListItemStyle = lipgloss.NewStyle().
25-
PaddingLeft(2).
26-
Foreground(Secondary)
25+
PaddingLeft(2).
26+
Foreground(Secondary)
2727

2828
TitleStyle = lipgloss.NewStyle().
29-
MarginLeft(2).
30-
MarginBottom(1).
31-
Foreground(Primary).
32-
Bold(true)
33-
)
29+
MarginLeft(2).
30+
MarginBottom(1).
31+
Foreground(Primary).
32+
Bold(true)
33+
)

internal/tui/views/add_collection.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ func NewAddCollectionView(collectionsManager *collections.CollectionsManager) Ad
2222
inputs := []components.TextInput{
2323
components.NewTextInput("Name", "Enter collection name"),
2424
}
25-
25+
2626
form := components.NewForm("Add Collection", inputs)
2727
form.SetSubmitText("Create")
28-
28+
2929
return AddCollectionView{
3030
layout: components.NewLayout(),
3131
form: form,
@@ -45,39 +45,36 @@ func (v AddCollectionView) Update(msg tea.Msg) (AddCollectionView, tea.Cmd) {
4545
v.width = msg.Width
4646
v.height = msg.Height
4747
v.layout.SetSize(v.width, v.height)
48-
v.form.SetSize(v.width-4, v.height-8) // Account for layout padding
49-
48+
v.form.SetSize(v.width-4, v.height-8)
49+
5050
case tea.KeyMsg:
5151
if v.submitting {
52-
// Don't handle keys while submitting
5352
return v, nil
5453
}
55-
54+
5655
switch msg.String() {
5756
case "enter":
5857
return v, func() tea.Msg { return v.submitForm() }
5958
case "esc":
6059
return v, func() tea.Msg { return BackToCollectionsMsg{} }
6160
}
62-
61+
6362
case CollectionCreateErrorMsg:
64-
// Handle error - for now just stop submitting
6563
v.submitting = false
6664
}
67-
68-
// Update form
65+
6966
v.form, cmd = v.form.Update(msg)
7067
return v, cmd
7168
}
7269

7370
func (v *AddCollectionView) submitForm() tea.Msg {
7471
v.submitting = true
7572
values := v.form.GetValues()
76-
73+
7774
if len(values) == 0 || values[0] == "" {
7875
return CollectionCreateErrorMsg{err: crud.ErrInvalidInput}
7976
}
80-
77+
8178
return v.createCollection(values[0])
8279
}
8380

@@ -104,15 +101,14 @@ func (v AddCollectionView) View() string {
104101

105102
content := v.form.View()
106103
instructions := "tab/↑↓: navigate • enter: create • esc: cancel"
107-
104+
108105
return v.layout.FullView(
109106
"Add Collection",
110107
content,
111108
instructions,
112109
)
113110
}
114111

115-
// Messages for collection operations
116112
type CollectionCreatedMsg struct {
117113
collection collections.CollectionEntity
118114
}
@@ -141,4 +137,4 @@ type BackToCollectionsMsg struct{}
141137

142138
type EditCollectionMsg struct {
143139
Collection collections.CollectionEntity
144-
}
140+
}

0 commit comments

Comments
 (0)