Load README on repo menu entry active

Toby Padilla created

Change summary

tui/bubble.go                   |  3 +++
tui/bubbles/selection/bubble.go | 21 +++++++++++++++++++--
tui/bubbles/selection/style.go  |  4 ++--
tui/commands.go                 |  5 +++--
tui/defaults.go                 |  3 +--
5 files changed, 28 insertions(+), 8 deletions(-)

Detailed changes

tui/bubble.go 🔗

@@ -105,6 +105,9 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		b.width = msg.Width
 		b.height = msg.Height
 	case selection.SelectedMsg:
+		b.activeBox = 1
+		cmds = append(cmds, b.getRepoCmd(b.repoMenu[msg.Index].Repo))
+	case selection.ActiveMsg:
 		cmds = append(cmds, b.getRepoCmd(b.repoMenu[msg.Index].Repo))
 	}
 	if b.state == loadedState {

tui/bubbles/selection/bubble.go 🔗

@@ -10,6 +10,11 @@ type SelectedMsg struct {
 	Index int
 }
 
+type ActiveMsg struct {
+	Name  string
+	Index int
+}
+
 type Bubble struct {
 	NormalStyle   lipgloss.Style
 	SelectedStyle lipgloss.Style
@@ -49,19 +54,31 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		case "k", "up":
 			if b.selectedItem > 0 {
 				b.selectedItem--
+				cmds = append(cmds, b.sendActiveMessage)
 			}
 		case "j", "down":
 			if b.selectedItem < len(b.Items)-1 {
 				b.selectedItem++
+				cmds = append(cmds, b.sendActiveMessage)
 			}
 		case "enter":
-			cmds = append(cmds, b.sendMessage)
+			cmds = append(cmds, b.sendSelectedMessage)
 		}
 	}
 	return b, tea.Batch(cmds...)
 }
 
-func (b *Bubble) sendMessage() tea.Msg {
+func (b *Bubble) sendActiveMessage() tea.Msg {
+	if b.selectedItem >= 0 && b.selectedItem < len(b.Items) {
+		return ActiveMsg{
+			Name:  b.Items[b.selectedItem],
+			Index: b.selectedItem,
+		}
+	}
+	return nil
+}
+
+func (b *Bubble) sendSelectedMessage() tea.Msg {
 	if b.selectedItem >= 0 && b.selectedItem < len(b.Items) {
 		return SelectedMsg{
 			Name:  b.Items[b.selectedItem],

tui/bubbles/selection/style.go 🔗

@@ -5,7 +5,7 @@ import (
 )
 
 var normalStyle = lipgloss.NewStyle().
-	Foreground(lipgloss.Color("#FFFFFF"))
+	Foreground(lipgloss.Color("#707070"))
 
 var selectedStyle = lipgloss.NewStyle().
-	Foreground(lipgloss.Color("#714C7B"))
+	Foreground(lipgloss.Color("#FFFFFF"))

tui/commands.go 🔗

@@ -50,8 +50,10 @@ func (b *Bubble) loadGitCmd() tea.Msg {
 		boxRightWidth-horizontalPadding-2,
 		b.repoSource.GetCommits(200),
 	)
+	msg := b.getRepoCmd("config")()
+	b.activeBox = 0
 	b.state = loadedState
-	return b.getRepoCmd("config")()
+	return msg
 }
 
 func (b *Bubble) getRepoCmd(name string) tea.Cmd {
@@ -65,7 +67,6 @@ func (b *Bubble) getRepoCmd(name string) tea.Cmd {
 		b.readmeViewport.Viewport.Width = boxLeftWidth - 2
 		b.readmeViewport.Viewport.SetContent(r.Readme)
 		b.boxes[1] = b.readmeViewport
-		b.activeBox = 1
 		return nil
 	}
 }

tui/defaults.go 🔗

@@ -17,8 +17,7 @@ const defaultConfig = `{
 	"menu": [
 	  {
 			"name": "Home",
-			"repo": "config",
-			"note": ""
+			"repo": "config"
 		}
 	]
 }`