Skip to content

Commit

Permalink
refactor: rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 18, 2022
1 parent 352b06d commit f3e2b7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
39 changes: 16 additions & 23 deletions internal/tui/bubbles/git/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ const (
repoNameMaxWidth = 32
)

type pageState int
type state int

const (
aboutPage pageState = iota
refsPage
logPage
treePage
aboutState state = iota
refsState
logState
treeState
)

type Bubble struct {
state pageState
state state
repo types.Repo
height int
heightMargin int
Expand All @@ -40,7 +40,7 @@ type Bubble struct {
func NewBubble(repo types.Repo, styles *style.Styles, width, wm, height, hm int) *Bubble {
b := &Bubble{
repo: repo,
state: aboutPage,
state: aboutState,
width: width,
widthMargin: wm,
height: height,
Expand All @@ -50,10 +50,10 @@ func NewBubble(repo types.Repo, styles *style.Styles, width, wm, height, hm int)
ref: repo.GetHEAD(),
}
heightMargin := hm + lipgloss.Height(b.headerView())
b.boxes[aboutPage] = about.NewBubble(repo, b.style, b.width, wm, b.height, heightMargin)
b.boxes[refsPage] = refs.NewBubble(repo, b.style, b.width, wm, b.height, heightMargin)
b.boxes[logPage] = log.NewBubble(repo, b.style, width, wm, height, heightMargin)
b.boxes[treePage] = tree.NewBubble(repo, b.style, width, wm, height, heightMargin)
b.boxes[aboutState] = about.NewBubble(repo, b.style, b.width, wm, b.height, heightMargin)
b.boxes[refsState] = refs.NewBubble(repo, b.style, b.width, wm, b.height, heightMargin)
b.boxes[logState] = log.NewBubble(repo, b.style, width, wm, height, heightMargin)
b.boxes[treeState] = tree.NewBubble(repo, b.style, width, wm, height, heightMargin)
return b
}

Expand All @@ -68,27 +68,20 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if b.repo.Name() != "config" {
switch msg.String() {
case "R":
b.state = aboutPage
b.state = aboutState
case "B":
b.state = refsPage
b.state = refsState
case "C":
b.state = logPage
b.state = logState
case "F":
b.state = treePage
b.state = treeState
}
}
case tea.WindowSizeMsg:
b.width = msg.Width
b.height = msg.Height
for i, bx := range b.boxes {
m, cmd := bx.Update(msg)
b.boxes[i] = m
if cmd != nil {
cmds = append(cmds, cmd)
}
}
case refs.RefMsg:
b.state = treePage
b.state = treeState
b.ref = msg
for i, bx := range b.boxes {
m, cmd := bx.Update(msg)
Expand Down
6 changes: 3 additions & 3 deletions internal/tui/bubbles/repo/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ type Bubble struct {
Active bool
}

func NewBubble(name, host string, port int, repo gittypes.Repo, styles *style.Styles, width, wm, height, hm int) *Bubble {
func NewBubble(repo gittypes.Repo, host string, port int, styles *style.Styles, width, wm, height, hm int) *Bubble {
b := &Bubble{
name: name,
name: repo.Name(),
host: host,
port: port,
repo: repo,
width: width,
widthMargin: wm,
height: height,
heightMargin: hm,
styles: styles,
}
b.repo = repo
b.box = gitui.NewBubble(repo, styles, width, wm+styles.RepoBody.GetHorizontalBorderSize(), height, hm+lipgloss.Height(b.headerView())-styles.RepoBody.GetVerticalBorderSize())
return b
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (b *Bubble) newMenuEntry(name string, rn string) (MenuEntry, error) {
lipgloss.Height(b.footerView()) +
b.styles.RepoBody.GetVerticalFrameSize() +
b.styles.App.GetVerticalMargins()
rb := repo.NewBubble(rn, b.config.Host, b.config.Port, r, b.styles, b.width, boxLeftWidth, b.height, heightMargin)
rb := repo.NewBubble(r, b.config.Host, b.config.Port, b.styles, b.width, boxLeftWidth, b.height, heightMargin)
initCmd := rb.Init()
msg := initCmd()
switch msg := msg.(type) {
Expand Down

0 comments on commit f3e2b7f

Please sign in to comment.