Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm/delete #51

Merged
merged 9 commits into from
Aug 13, 2024
39 changes: 33 additions & 6 deletions pkg/model/savedFilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ import (
const (
applyFilterButton = "a"
deleteFilterButton = "d"
confirmDelete = "y"
cancelDelete = "n"
)

var docStyle = lipgloss.NewStyle().Margin(1, 2)
var (
docStyle = lipgloss.NewStyle().Margin(1, 2)
deleteFilterState = false
)

// FilterDetails represents the structure of filter data
type FilterDetails struct {
Expand All @@ -52,11 +57,11 @@ type Item struct {
}

var (
titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9"))
queryStyle = lipgloss.NewStyle().PaddingLeft(0).Foreground(lipgloss.Color("7"))
itemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("8"))
// selectedItemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("170"))
titleStyles = lipgloss.NewStyle().PaddingLeft(0).Bold(true).Foreground(lipgloss.Color("9"))
queryStyle = lipgloss.NewStyle().PaddingLeft(0).Foreground(lipgloss.Color("7"))
itemStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(lipgloss.Color("8"))
selectedItemStyle = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.AdaptiveColor{Light: "16", Dark: "226"})
confirmModal = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.AdaptiveColor{Light: "16", Dark: "226"})
)

type itemDelegate struct{}
Expand Down Expand Up @@ -90,6 +95,18 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
}

func (d itemDelegate) ShortHelp() []key.Binding {
if deleteFilterState {
return []key.Binding{
key.NewBinding(
key.WithKeys(confirmDelete),
key.WithHelp(confirmDelete, confirmModal.Render("confirm delete")),
),
key.NewBinding(
key.WithKeys(cancelDelete),
key.WithHelp(cancelDelete, confirmModal.Render("cancel delete")),
),
}
}
return []key.Binding{
key.NewBinding(
key.WithKeys(applyFilterButton),
Expand Down Expand Up @@ -157,9 +174,19 @@ func (m modelFilter) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
}
if msg.String() == "d" {
deleteFilterState = true
return m, nil
}
if msg.String() != "d" {
deleteFilterState = false
}
if msg.String() == "y" {
selectedFilterDelete = m.list.SelectedItem().(Item)
return m, tea.Quit

}
if msg.String() == "n" {
deleteFilterState = false
return m, nil
}
case tea.WindowSizeMsg:
h, v := docStyle.GetFrameSize()
Expand Down
Loading