Skip to content

Commit

Permalink
fix(ui): list ui issues when filtered (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
eremid authored Jan 19, 2023
1 parent 7d232cb commit 2768b97
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tui/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func (m *ListKeyMap) YamlHelp() {
{m.UpDown, m.LeftRight, m.Back},
{m.ForwardSlash, m.Enter},
{m.Help, m.Quit},
{m.Apply, m.Delete, m.Print, m.Get},
{m.ShowDependanciesFiles},
{m.Apply, m.Delete, m.Print},
{m.Get, m.ShowDependanciesFiles},
}
}

Expand Down
22 changes: 18 additions & 4 deletions tui/pages/examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func New(e tui.LoadedExamples, width, height int, c config.Provider) model {
list := list.New(e.Examples["-"],
delegate,
width,
int(float64(height)*0.6),
height,
)
list.Title = "Choose an example"
list.DisableQuitKeybindings()
Expand All @@ -134,6 +134,10 @@ func New(e tui.LoadedExamples, width, height int, c config.Provider) model {

footer := footer.New(width, listKeys)

// we have header and footer, we need to reduce list height
list.SetWidth(width - tui.AppStyle.GetHorizontalPadding())
list.SetHeight(height - header.Height() - footer.Height() - tui.AppStyle.GetVerticalPadding())

k8sCmdList = make(map[string]*k8sCmd)

// default activated keys
Expand Down Expand Up @@ -244,6 +248,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
title := m.currentList.SelectedItem().(*tui.Example).Title()
if m.currentList.FilterState() == list.FilterApplied {
m.currentList.ResetFilter()
}

m.keys.Apply.SetEnabled(true)
m.keys.Delete.SetEnabled(true)
Expand Down Expand Up @@ -366,19 +373,21 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

case tea.WindowSizeMsg:
m.header.Notification = "resizing"
top, right, bottom, left := tui.AppStyle.GetPadding()
m.width, m.height = msg.Width-left-right, msg.Height-top-bottom
centerH := m.height - lipgloss.Height(m.header.View()) - lipgloss.Height(m.footer.View())
centerH := m.height - m.header.Height() - m.footer.Height()

m.header.Width = msg.Width
m.footer.Width = msg.Width
m.header.SetWidth(msg.Width)
m.footer.SetWidth(msg.Width)

m.markdown.Width = m.width
m.markdown.Viewport.Width = m.width - right - left
m.markdown.Viewport.Height = centerH

m.currentList.SetSize(m.width, centerH)
m.errorPanel.Resize(m.width, centerH)
m.header.NotificationOK = tui.CheckMark

case tui.LoadedExamples:
m.exampleList = msg.Examples
Expand Down Expand Up @@ -674,6 +683,11 @@ func (m model) rootView() (model, tea.Cmd) {
m.keys.Print.SetEnabled(false)

m.currentList.NewStatusMessage("back to home !")

if m.currentList.FilterState() == list.FilterApplied {
m.currentList.ResetFilter()
}

m, cmd := m.showExamples()

return m, cmd
Expand Down
29 changes: 22 additions & 7 deletions tui/pages/footer/footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
type Model struct {
tea.Model
Message string
Width int
width int
Help help.Model
Keymap *tui.ListKeyMap
}
Expand All @@ -40,7 +40,7 @@ func New(w int, km *tui.ListKeyMap) Model {
help.Styles.FullDesc = tui.HelpFeintText
return Model{
Message: "FrangipaneTeam",
Width: w,
width: w,
Help: help,
Keymap: km,
}
Expand All @@ -60,7 +60,7 @@ func (m Model) View() string {
tui.Divider, strings.Trim(m.Message, "\n"), tui.Divider,
)

wP := m.Width - tui.AppStyle.GetHorizontalPadding()
wP := m.width - tui.AppStyle.GetHorizontalPadding()
f := lipgloss.NewStyle().Height(3).Width(wP)

ui := lipgloss.Place(
Expand All @@ -85,9 +85,24 @@ func (m Model) View() string {
}

// Resize resizes the model
func (m Model) Resize(width, height int) Model {
m.Width = width
m.Help.Width = width
// func (m Model) Resize(width, height int) Model {
// m.width = width
// m.Help.Width = width

return m
// return m
// }

// Height return the height of the view
func (m Model) Height() int {
return lipgloss.Height(m.View())
}

// Width return the width of the view
func (m Model) Width() int {
return lipgloss.Width(m.View())
}

// SetWidth sets the width of the view
func (m Model) SetWidth(w int) {
m.width = w
}
21 changes: 18 additions & 3 deletions tui/pages/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Model struct {
activityFrom interface{}
notifyCrds chan pages.NotifyActivity
notifyExamples chan pages.NotifyActivity
Width int
width int
Notification string
NotificationOK string
// errorPanel errorpanel.Model
Expand Down Expand Up @@ -60,7 +60,7 @@ func New(title string, desc string, w int, c config.Provider) Model {
spinner: s,
notifyCrds: make(chan pages.NotifyActivity),
notifyExamples: make(chan pages.NotifyActivity),
Width: w,
width: w,
config: c,
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func (m Model) View() string {

t := strings.Trim(m.Notification, "\n")
fmt.Fprintf(&notification, "%s %s %s", tui.Divider, t, m.NotificationOK)
wP := m.Width - tui.AppStyle.GetHorizontalPadding()
wP := m.width - tui.AppStyle.GetHorizontalPadding()

header = lipgloss.JoinHorizontal(
lipgloss.Top,
Expand Down Expand Up @@ -180,3 +180,18 @@ func tick() tea.Msg {
time.Sleep(time.Second)
return tickMsg{}
}

// Height return the height of the view
func (m Model) Height() int {
return lipgloss.Height(m.View())
}

// Width return the width of the view
func (m Model) Width() int {
return lipgloss.Width(m.View())
}

// SetWidth set the width of the view
func (m *Model) SetWidth(w int) {
m.width = w
}

0 comments on commit 2768b97

Please sign in to comment.