Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate repo model, better looking styling #23

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions models/organisationModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type OrganisationModel struct {

repoList list.Model
repoModel RepositoryModel
activeTab int

loaded bool
width int
Expand All @@ -39,13 +38,11 @@ func (m *OrganisationModel) init() {
m.repoList = list.New(
[]list.Item{},
list.NewDefaultDelegate(),
// m.width,
// m.height,
0,
0,
m.panelWidth(),
m.height,
)

m.repoModel = NewRepositoryModel(m.panelWidth(), m.height)
m.repoModel = NewRepositoryModel(m.panelWidth(), m.height)
}

func (m OrganisationModel) Init() tea.Cmd {
Expand All @@ -60,6 +57,8 @@ func (m OrganisationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
m.height = msg.Height
m.width = msg.Width
m.repoModel.width = m.panelWidth()
m.repoModel.height = m.height

if !m.loaded {
m.init()
Expand All @@ -70,7 +69,7 @@ func (m OrganisationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case messages.RepoListMsg:
m.repoList = buildRepoListModel(msg.OrganizationQuery, m.width, m.height)
m.RepoQuery = msg.OrganizationQuery
m.repoModel.SelectRepo(m.getSelectedRepo())
m.repoModel.SelectRepo(m.getSelectedRepo(), m.panelWidth(), m.height)
return m, nil

case tea.KeyMsg:
Expand All @@ -85,13 +84,14 @@ func (m OrganisationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyLeft:
m.repoModel.PreviousTab()
}
_, cmd = m.repoModel.Update(msg)
} else {
switch msg.Type {
case tea.KeyDown, tea.KeyUp:
m.repoModel.SelectRepo(m.getSelectedRepo())
m.repoModel.SelectRepo(m.getSelectedRepo(), m.panelWidth(), m.height)
case tea.KeyEnter:
m.tabsHaveFocus = true
m.repoModel.SelectRepo(m.getSelectedRepo())
m.repoModel.SelectRepo(m.getSelectedRepo(), m.panelWidth(), m.height)
case tea.KeyEsc:
return MainModel[UserModelName], nil
}
Expand All @@ -103,15 +103,14 @@ func (m OrganisationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

// m.buildSettingListModel(m.repositorySettingsTabs[m.activeTab], m.width, m.height)

return m, cmd
}

// View implements tea.Model
func (m OrganisationModel) View() string {
var repoList = appStyle.Width((m.width / 2) - 4).Render(m.repoList.View())
var settings = appStyle.Width(m.width / 2).Render(m.repoModel.View())
var repoList = appStyle.Width(m.panelWidth() - 4).Render(m.repoList.View())
var settings = appStyle.Width(m.panelWidth()).Render(m.repoModel.View())

var views = []string{repoList, settings}

return lipgloss.JoinHorizontal(lipgloss.Top, views...)
Expand Down
32 changes: 16 additions & 16 deletions models/repositoryModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ func (m RepositoryModel) Init() tea.Cmd {
return nil
}

func (m *RepositoryModel) SelectRepo(RepositoryQuery structs.RepositoryQuery) {
func (m *RepositoryModel) SelectRepo(RepositoryQuery structs.RepositoryQuery, width, height int) {
m.repositorySettingsTabs = structs.BuildRepositorySettings(RepositoryQuery)

m.buildSettingListModel(m.repositorySettingsTabs[m.activeTab], m.width, m.height)
m.width = width
m.height = height
m.buildSettingsTable(m.repositorySettingsTabs[m.activeTab])
}

func (m *RepositoryModel) NextTab() {
Expand All @@ -47,12 +49,8 @@ func (m *RepositoryModel) PreviousTab() {
func (m RepositoryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd

switch msg := msg.(type) {

switch msg.(type) {
case tea.WindowSizeMsg:
m.height = msg.Height
m.width = msg.Width

if !m.loaded {
m.loaded = true
}
Expand All @@ -64,13 +62,14 @@ func (m RepositoryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (m RepositoryModel) View() string {
var tabs = m.RenderTabs()
var settings = settingsStyle.Render(m.settingsTable.View())
var settings = settingsStyle.Padding(0).Width(m.width - 6).Render(m.settingsTable.View())

return lipgloss.JoinVertical(lipgloss.Left, tabs, settings)
}

func (m *RepositoryModel) buildSettingListModel(tabSettings structs.RepositorySettingsTab, width, height int) {
columns := []table.Column{{Title: "Name", Width: 30}, {Title: "Value", Width: 10}}
func (m *RepositoryModel) buildSettingsTable(tabSettings structs.RepositorySettingsTab) {

columns := []table.Column{{Title: "", Width: 20}, {Title: "", Width: 11}}

rows := make([]table.Row, len(tabSettings.Settings))
for i, setting := range tabSettings.Settings {
Expand All @@ -79,11 +78,7 @@ func (m *RepositoryModel) buildSettingListModel(tabSettings structs.RepositorySe

m.settingsTable = table.New(
table.WithColumns(columns),
table.WithRows(rows),
table.WithWidth(width),
table.WithHeight(20))
// table.WithHeight(height-titleHeight-4))

table.WithRows(rows))
}

func (m RepositoryModel) RenderTabs() string {
Expand Down Expand Up @@ -113,7 +108,12 @@ func (m RepositoryModel) RenderTabs() string {
border.BottomRight = "┤"
}
// TODO: Calculate width of tabs correctly so they match m.width
style = style.Border(border) //.Width((m.width / len(Tabs)) - 1)
if isLast {
style = style.Border(border).Width((m.width / len(Tabs)) - 4)
} else {
style = style.Border(border).Width((m.width / len(Tabs)) - 3)
}

renderedTabs = append(renderedTabs, style.Render(t))
}

Expand Down
10 changes: 5 additions & 5 deletions models/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
inactiveTabStyle = lipgloss.NewStyle().Border(inactiveTabBorder, true).BorderForeground(borderColor).Padding(0, 1)
activeTabStyle = inactiveTabStyle.Copy().Border(activeTabBorder, true)

settingsStyle = appStyle.Copy().Border(listSettingsBorder()).
settingsStyle = appStyle.Copy().Border(settingsBorder()).
BorderForeground(borderColor).Padding(0, 1, 1, 1)
)

Expand All @@ -47,10 +47,10 @@ func tabBorderWithBottom(left, middle, right string) lipgloss.Border {
return border
}

func listSettingsBorder() lipgloss.Border {
func settingsBorder() lipgloss.Border {
border := lipgloss.RoundedBorder()
border.Top = ""
border.TopLeft = ""
border.TopRight = ""
border.Top = ""
border.TopLeft = ""
border.TopRight = ""
return border
}