Skip to content

Commit

Permalink
tweaked list layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd committed Feb 14, 2024
1 parent 6fc55df commit 8d45aef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
15 changes: 12 additions & 3 deletions internal/lnd/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package lnd
import "github.com/charmbracelet/bubbles/list"

type NodeData struct {
NodeInfo Node
Channels []Channel
NodeInfo Node
Channels []Channel
PendingChannels []PendingChannel
Payments []Payment
Payments []Payment
}

func (n NodeData) GetChannelsAsListItems(onlyOffline bool) []list.Item {
Expand All @@ -20,6 +20,15 @@ func (n NodeData) GetChannelsAsListItems(onlyOffline bool) []list.Item {
return channelItems
}

func (n NodeData) GetPendingChannelsAsListItems() []list.Item {
var pendingChannelItems []list.Item
for _, pendingChannel := range n.PendingChannels {
pendingChannelItems = append(pendingChannelItems, pendingChannel)
}

return pendingChannelItems
}

func (n NodeData) GetPaymentsAsListItems() []list.Item {
var paymentItems []list.Item
for _, payment := range n.Payments {
Expand Down
44 changes: 30 additions & 14 deletions internal/tui/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type dashboardComponent int
const (
channels dashboardComponent = iota
payments
pendingChannels
nodeinfo
messageTools
channelTools
Expand All @@ -34,8 +35,9 @@ func InitDashboard(service *lndclient.GrpcLndServices, nodeData lnd.NodeData) *D
func (m *DashboardModel) initData(width, height int) {

adjustedHeight := height + height/3
defaultList := list.New([]list.Item{}, list.NewDefaultDelegate(), width, adjustedHeight / 2)
compressedList := list.New([]list.Item{}, list.NewDefaultDelegate(), width, adjustedHeight / 4)
adjustedCompressedHeight := height + height/2
defaultList := list.New([]list.Item{}, list.NewDefaultDelegate(), width, adjustedHeight/2)
compressedList := list.New([]list.Item{}, list.NewDefaultDelegate(), width, adjustedCompressedHeight/5)
defaultList.SetShowHelp(true)

m.lists = []list.Model{defaultList, compressedList, compressedList}
Expand All @@ -52,6 +54,9 @@ func (m *DashboardModel) initData(width, height int) {
m.lists[payments].Title = "Latest Payments"
m.lists[payments].SetItems(m.nodeData.GetPaymentsAsListItems())

m.lists[pendingChannels].Title = "Pending Channels"
m.lists[pendingChannels].SetItems(m.nodeData.GetPendingChannelsAsListItems())

m.base = *NewBaseModel(m)
}

Expand Down Expand Up @@ -124,12 +129,30 @@ func (m DashboardModel) Init() tea.Cmd {
return nil
}

func (m DashboardModel) getCompressedListViews() string {
s := m.styles
switch m.focused {
case payments:
return lipgloss.JoinVertical(lipgloss.Center,
s.FocusedStyle.Render(m.lists[payments].View()),
s.BorderedStyle.Render(m.lists[pendingChannels].View()))
case pendingChannels:
return lipgloss.JoinVertical(lipgloss.Center,
s.BorderedStyle.Render(m.lists[payments].View()),
s.FocusedStyle.Render(m.lists[pendingChannels].View()))
default:
return lipgloss.JoinVertical(lipgloss.Center,
s.BorderedStyle.Render(m.lists[payments].View()),
s.BorderedStyle.Render(m.lists[pendingChannels].View()))
}

}

func (m DashboardModel) View() string {
s := m.styles

if m.loaded {
channelsView := m.lists[channels].View()
paymentsView := m.lists[payments].View()

var listsView string
switch m.focused {
Expand All @@ -138,21 +161,14 @@ func (m DashboardModel) View() string {
listsView = lipgloss.JoinHorizontal(
lipgloss.Center,
s.FocusedStyle.Render(channelsView),
s.BorderedStyle.Render(paymentsView),
)

case payments:
listsView = lipgloss.JoinHorizontal(
lipgloss.Center,
s.BorderedStyle.Render(channelsView),
s.FocusedStyle.Render(paymentsView),
m.getCompressedListViews(),
)

default:
listsView = lipgloss.JoinHorizontal(
lipgloss.Center,
s.BorderedStyle.Render(channelsView),
s.BorderedStyle.Render(paymentsView),
m.getCompressedListViews(),
)
}

Expand Down Expand Up @@ -266,10 +282,10 @@ func (m *DashboardModel) handleFormClick(component dashboardComponent) (tea.Mode
m.forms[0] = m.generatePaymentToolsForm()
case messageTools:
if m.forms[2].GetString("messages") == OPTION_MESSAGE_SIGN {

i = newSignMessageModel(m.lndService, &m.base)
} else {

i = newVerifyMessageModel(m.lndService, &m.base)
}
m.forms[2] = m.generateMessageToolsForm()
Expand Down

0 comments on commit 8d45aef

Please sign in to comment.