@@ -5,29 +5,37 @@ import (
55 "github.com/charmbracelet/lipgloss"
66 "github.com/maniac-en/req/internal/backend/collections"
77 "github.com/maniac-en/req/internal/backend/endpoints"
8+ "github.com/maniac-en/req/internal/backend/http"
89 "github.com/maniac-en/req/internal/tui/components"
910 "github.com/maniac-en/req/internal/tui/styles"
1011)
1112
1213type SelectedCollectionView struct {
1314 layout components.Layout
1415 endpointsManager * endpoints.EndpointsManager
16+ httpManager * http.HTTPManager
1517 collection collections.CollectionEntity
1618 sidebar EndpointSidebarView
19+ selectedEndpoint * endpoints.EndpointEntity
1720 width int
1821 height int
1922}
2023
21- func NewSelectedCollectionView (endpointsManager * endpoints.EndpointsManager , collection collections.CollectionEntity ) SelectedCollectionView {
24+ func NewSelectedCollectionView (endpointsManager * endpoints.EndpointsManager , httpManager * http.HTTPManager , collection collections.CollectionEntity ) SelectedCollectionView {
25+ sidebar := NewEndpointSidebarView (endpointsManager , collection )
26+ sidebar .Focus () // Make sure sidebar starts focused
27+
2228 return SelectedCollectionView {
2329 layout : components .NewLayout (),
2430 endpointsManager : endpointsManager ,
31+ httpManager : httpManager ,
2532 collection : collection ,
26- sidebar : NewEndpointSidebarView (endpointsManager , collection ),
33+ sidebar : sidebar ,
34+ selectedEndpoint : nil ,
2735 }
2836}
2937
30- func NewSelectedCollectionViewWithSize (endpointsManager * endpoints.EndpointsManager , collection collections.CollectionEntity , width , height int ) SelectedCollectionView {
38+ func NewSelectedCollectionViewWithSize (endpointsManager * endpoints.EndpointsManager , httpManager * http. HTTPManager , collection collections.CollectionEntity , width , height int ) SelectedCollectionView {
3139 layout := components .NewLayout ()
3240 layout .SetSize (width , height )
3341
@@ -40,12 +48,15 @@ func NewSelectedCollectionViewWithSize(endpointsManager *endpoints.EndpointsMana
4048 sidebar := NewEndpointSidebarView (endpointsManager , collection )
4149 sidebar .width = sidebarWidth
4250 sidebar .height = innerHeight
51+ sidebar .Focus () // Make sure sidebar starts focused
4352
4453 return SelectedCollectionView {
4554 layout : layout ,
4655 endpointsManager : endpointsManager ,
56+ httpManager : httpManager ,
4757 collection : collection ,
4858 sidebar : sidebar ,
59+ selectedEndpoint : nil ,
4960 width : width ,
5061 height : height ,
5162 }
@@ -78,18 +89,62 @@ func (v SelectedCollectionView) Update(msg tea.Msg) (SelectedCollectionView, tea
7889 case "esc" , "q" :
7990 return v , func () tea.Msg { return BackToCollectionsMsg {} }
8091 }
92+
93+ case EndpointSelectedMsg :
94+ // Store the selected endpoint for display
95+ v .selectedEndpoint = & msg .Endpoint
8196 }
8297
98+ // Always forward messages to sidebar for now, but it only handles them when focused
8399 v .sidebar , cmd = v .sidebar .Update (msg )
84100
85101 return v , cmd
86102}
87103
104+
88105func (v SelectedCollectionView ) View () string {
89106 title := "Collection: " + v .collection .Name
107+ if v .selectedEndpoint != nil {
108+ title += " > " + v .selectedEndpoint .Name
109+ }
90110
91111 sidebarContent := v .sidebar .View ()
92- mainContent := "Endpoint details will be displayed here"
112+
113+ // Simple endpoint information display
114+ var mainContent string
115+ if v .selectedEndpoint != nil {
116+ var lines []string
117+ lines = append (lines , "Selected Endpoint:" )
118+ lines = append (lines , "" )
119+ lines = append (lines , "Name: " + v .selectedEndpoint .Name )
120+ lines = append (lines , "Method: " + v .selectedEndpoint .Method )
121+ lines = append (lines , "URL: " + v .selectedEndpoint .Url )
122+
123+ if v .selectedEndpoint .Headers != "" {
124+ lines = append (lines , "" )
125+ lines = append (lines , "Headers: " + v .selectedEndpoint .Headers )
126+ }
127+
128+ if v .selectedEndpoint .QueryParams != "" {
129+ lines = append (lines , "" )
130+ lines = append (lines , "Query Params: " + v .selectedEndpoint .QueryParams )
131+ }
132+
133+ if v .selectedEndpoint .RequestBody != "" {
134+ lines = append (lines , "" )
135+ lines = append (lines , "Request Body:" )
136+ lines = append (lines , v .selectedEndpoint .RequestBody )
137+ }
138+
139+ mainContent = lipgloss .JoinVertical (lipgloss .Left , lines ... )
140+ } else {
141+ // Check if there are no endpoints at all
142+ if len (v .sidebar .endpoints ) == 0 {
143+ mainContent = "Create an endpoint to get started"
144+ } else {
145+ mainContent = "Select an endpoint from the sidebar to view details"
146+ }
147+ }
93148
94149 if v .width < 10 || v .height < 10 {
95150 return v .layout .FullView (title , sidebarContent , "esc/q: back to collections" )
@@ -103,26 +158,32 @@ func (v SelectedCollectionView) View() string {
103158 sidebarWidth := innerWidth / 4
104159 mainWidth := innerWidth - sidebarWidth - 1
105160
161+ // Sidebar styling
106162 sidebarStyle := styles .SidebarStyle .Copy ().
107163 Width (sidebarWidth ).
108- Height (innerHeight )
164+ Height (innerHeight ).
165+ BorderForeground (styles .Primary )
109166
110167 mainStyle := styles .MainContentStyle .Copy ().
111168 Width (mainWidth ).
112- Height (innerHeight ).
113- Align (lipgloss .Center , lipgloss .Center )
169+ Height (innerHeight )
114170
115171 content := lipgloss .JoinHorizontal (
116172 lipgloss .Top ,
117173 sidebarStyle .Render (sidebarContent ),
118174 mainStyle .Render (mainContent ),
119175 )
120176
121- instructions := "↑↓: navigate endpoints • esc/q: back to collections "
177+ instructions := "↑↓: navigate endpoints • esc/q: back"
122178
123179 return v .layout .FullView (
124180 title ,
125181 content ,
126182 instructions ,
127183 )
128184}
185+
186+ // Message types for selected collection view
187+ type EndpointSelectedMsg struct {
188+ Endpoint endpoints.EndpointEntity
189+ }
0 commit comments