-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(branches): sidebar skeleton (#451)
* feat(branches): sidebar skeleton * fix: spacing and always use last commit msg in ui
- Loading branch information
Showing
5 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package branch | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/dlvhdr/gh-dash/v4/data" | ||
"github.com/dlvhdr/gh-dash/v4/git" | ||
) | ||
|
||
type BranchData struct { | ||
Data git.Branch | ||
PR *data.PullRequestData | ||
} | ||
|
||
func (b BranchData) GetRepoNameWithOwner() string { | ||
return b.Data.Remotes[0] | ||
} | ||
|
||
func (b BranchData) GetTitle() string { | ||
return b.Data.Name | ||
} | ||
|
||
func (b BranchData) GetNumber() int { | ||
if b.PR == nil { | ||
return 0 | ||
} | ||
return b.PR.Number | ||
} | ||
|
||
func (b BranchData) GetUrl() string { | ||
if b.PR == nil { | ||
return "" | ||
} | ||
return b.PR.Url | ||
} | ||
|
||
func (b BranchData) GetUpdatedAt() time.Time { | ||
return *b.Data.LastUpdatedAt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package branchsidebar | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
|
||
"github.com/dlvhdr/gh-dash/v4/ui/components/branch" | ||
"github.com/dlvhdr/gh-dash/v4/ui/context" | ||
) | ||
|
||
type Model struct { | ||
ctx *context.ProgramContext | ||
branch *branch.BranchData | ||
} | ||
|
||
func NewModel(ctx context.ProgramContext) Model { | ||
return Model{ | ||
branch: nil, | ||
} | ||
} | ||
|
||
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { | ||
return m, nil | ||
} | ||
|
||
func (m Model) View() string { | ||
s := strings.Builder{} | ||
|
||
if m.branch == nil { | ||
return "No branch selected" | ||
} | ||
|
||
s.WriteString(m.branch.Data.Name) | ||
if m.branch.PR != nil { | ||
s.WriteString("\n") | ||
s.WriteString(fmt.Sprintf("#%d %s", m.branch.PR.GetNumber(), m.branch.PR.Title)) | ||
} | ||
|
||
return s.String() | ||
} | ||
|
||
func (m *Model) SetRow(b *branch.BranchData) { | ||
m.branch = b | ||
} | ||
|
||
func (m *Model) UpdateProgramContext(ctx *context.ProgramContext) { | ||
m.ctx = ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters