Skip to content

Commit

Permalink
Fix some linting of filterapi example (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evertras authored Oct 9, 2023
1 parent c8ef5b8 commit e85560b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/filterapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewModel() Model {
table.NewColumn(columnKeyAuthor, "Author", 13).WithFiltered(true),
table.NewColumn(columnKeyDescription, "Description", 50),
}

return Model{
table: table.
New(columns).
Expand Down Expand Up @@ -74,16 +75,18 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// global
if msg.String() == "ctrl+c" {
cmds = append(cmds, tea.Quit)

return m, tea.Batch(cmds...)
}
// event to filter
if m.filterTextInput.Focused() {
if msg.String() == "enter" {
m.filterTextInput.Blur()
} else {
m.filterTextInput, cmd = m.filterTextInput.Update(msg)
m.filterTextInput, _ = m.filterTextInput.Update(msg)
}
m.table = m.table.WithFilterInput(m.filterTextInput)

return m, tea.Batch(cmds...)
}

Expand All @@ -98,7 +101,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.table, cmd = m.table.Update(msg)
cmds = append(cmds, cmd)
}

}

return m, tea.Batch(cmds...)
Expand All @@ -108,7 +110,8 @@ func (m Model) View() string {
body := strings.Builder{}

body.WriteString("A filtered simple default table\n" +
"Currently filter by Title and Author, press / + letters to start filtering, and escape to clear filter.\nPress q or ctrl+c to quit\n\n")
"Currently filter by Title and Author, press / + letters to start filtering, and escape to clear filter.\n" +
"Press q or ctrl+c to quit\n\n")

body.WriteString(m.filterTextInput.View() + "\n")
body.WriteString(m.table.View())
Expand Down

0 comments on commit e85560b

Please sign in to comment.