Refactor sidebar component to use struct
This commit refactors the sidebar component to use a struct for better organization and maintainability. The `data` and `sindex` fields are now exported as `Data` and `Sindex` respectively, allowing for easier access and modification. Additionally, the styling for the selected sidebar item has been updated for improved visual clarity.
This commit is contained in:
11
main.go
11
main.go
@@ -14,7 +14,7 @@ type model struct {
|
||||
textInput textinput.Model
|
||||
width int
|
||||
height int
|
||||
sidebarContent string
|
||||
sidebarContent components.Sidebar
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
@@ -24,9 +24,14 @@ func initialModel() model {
|
||||
ti.CharLimit = 30
|
||||
ti.Prompt = ""
|
||||
ti.Focus()
|
||||
sidebarcon := components.Sidebar{
|
||||
Data: []string{"Library", "Playlist1", "Playlist2", "Favorites"},
|
||||
Sindex: 0,
|
||||
}
|
||||
|
||||
return model{
|
||||
textInput: ti,
|
||||
sidebarContent: "Library\n\nPlaylist 1\nPlaylist 2\nFavorites",
|
||||
sidebarContent: sidebarcon,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +72,7 @@ func (m model) View() string {
|
||||
// sidebar := lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).Padding(1, 2).Render(m.sidebarContent)
|
||||
|
||||
// Combine search and sidebar vertically
|
||||
content := lipgloss.JoinVertical(lipgloss.Left, searchBox, "\n", components.Sidebar(m.sidebarContent))
|
||||
content := lipgloss.JoinVertical(lipgloss.Left, searchBox, "\n", m.sidebarContent.View())
|
||||
|
||||
return lipgloss.Place(
|
||||
m.width,
|
||||
|
||||
Reference in New Issue
Block a user