on main help sign in
fix: add update listener
99b6dbeKujtim Hoxha
internal/tui/components/chat/header/header.go+10
@@ -10,7 +10,9 @@ import (
10 "github.com/charmbracelet/crush/internal/llm/models"
10 "github.com/charmbracelet/crush/internal/llm/models"
11 "github.com/charmbracelet/crush/internal/lsp"
11 "github.com/charmbracelet/crush/internal/lsp"
12 "github.com/charmbracelet/crush/internal/lsp/protocol"
12 "github.com/charmbracelet/crush/internal/lsp/protocol"
13+ "github.com/charmbracelet/crush/internal/pubsub"
13 "github.com/charmbracelet/crush/internal/session"
14 "github.com/charmbracelet/crush/internal/session"
15+ "github.com/charmbracelet/crush/internal/tui/components/chat"
14 "github.com/charmbracelet/crush/internal/tui/styles"
16 "github.com/charmbracelet/crush/internal/tui/styles"
15 "github.com/charmbracelet/crush/internal/tui/util"
17 "github.com/charmbracelet/crush/internal/tui/util"
16 "github.com/charmbracelet/lipgloss/v2"
18 "github.com/charmbracelet/lipgloss/v2"
@@ -44,6 +46,14 @@ func (p *header) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
44 switch msg := msg.(type) {
46 switch msg := msg.(type) {
45 case tea.WindowSizeMsg:
47 case tea.WindowSizeMsg:
46 p.width = msg.Width - 2
48 p.width = msg.Width - 2
49+ case chat.SessionSelectedMsg:
50+ p.session = msg
51+ case pubsub.Event[session.Session]:
52+ if msg.Type == pubsub.UpdatedEvent {
53+ if p.session.ID == msg.Payload.ID {
54+ p.session = msg.Payload
55+ }
56+ }
47 }
57 }
48 return p, nil
58 return p, nil
49}
59}
internal/tui/page/chat/chat.go+14−21
@@ -64,10 +64,10 @@ type chatPage struct {
64}
64}
65
65
66func (p *chatPage) Init() tea.Cmd {
66func (p *chatPage) Init() tea.Cmd {
67− cmd := p.layout.Init()
68 return tea.Batch(
67 return tea.Batch(
69− cmd,
68+ p.layout.Init(),
69+ p.compactSidebar.Init(),
70− p.layout.FocusPanel(layout.BottomPanel), // Focus on the bottom panel (editor)
70+ p.layout.FocusPanel(layout.BottomPanel), // Focus on the bottom panel (editor),
71 )
71 )
72}
72}
73
73
@@ -88,9 +88,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
88 h, cmd := p.header.Update(msg)
88 h, cmd := p.header.Update(msg)
89 cmds = append(cmds, cmd)
89 cmds = append(cmds, cmd)
90 p.header = h.(header.Header)
90 p.header = h.(header.Header)
91− if p.compactMode && p.showDetails {
92− cmds = append(cmds, p.compactSidebar.SetSize(msg.Width-4, 0))
91+ cmds = append(cmds, p.compactSidebar.SetSize(msg.Width-4, 0))
93− }
94 // the mode is only relevant when there is a session
92 // the mode is only relevant when there is a session
95 if p.session.ID != "" {
93 if p.session.ID != "" {
96 // Only auto-switch to compact mode if not forced
94 // Only auto-switch to compact mode if not forced
@@ -213,13 +211,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
213 p.showDetails = !p.showDetails
211 p.showDetails = !p.showDetails
214 p.header.SetDetailsOpen(p.showDetails)
212 p.header.SetDetailsOpen(p.showDetails)
215 if p.showDetails {
213 if p.showDetails {
216− p.compactSidebar = sidebarCmp(p.app, true)
217− c, cmd := p.compactSidebar.Update(chat.SessionSelectedMsg(p.session))
218− p.compactSidebar = c.(layout.Container)
219− return p, tea.Batch(
214+ return p, tea.Batch()
220− cmd,
221− p.compactSidebar.SetSize(p.wWidth-4, 0),
222− )
223 }
215 }
224
216
225 return p, nil
217 return p, nil
@@ -228,12 +220,12 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
228 u, cmd := p.layout.Update(msg)
220 u, cmd := p.layout.Update(msg)
229 cmds = append(cmds, cmd)
221 cmds = append(cmds, cmd)
230 p.layout = u.(layout.SplitPaneLayout)
222 p.layout = u.(layout.SplitPaneLayout)
231−
223+ h, cmd := p.header.Update(msg)
232− if p.compactMode && p.showDetails {
224+ p.header = h.(header.Header)
225+ cmds = append(cmds, cmd)
233− s, cmd := p.compactSidebar.Update(msg)
226+ s, cmd := p.compactSidebar.Update(msg)
234− p.compactSidebar = s.(layout.Container)
227+ p.compactSidebar = s.(layout.Container)
235− cmds = append(cmds, cmd)
228+ cmds = append(cmds, cmd)
236− }
237 return p, tea.Batch(cmds...)
229 return p, tea.Batch(cmds...)
238}
230}
239
231
@@ -409,7 +401,8 @@ func NewChatPage(app *app.App) ChatPage {
409 layout.WithFixedBottomHeight(5),
401 layout.WithFixedBottomHeight(5),
410 layout.WithFixedRightWidth(31),
402 layout.WithFixedRightWidth(31),
411 ),
403 ),
404+ compactSidebar: sidebarCmp(app, true),
412− keyMap: DefaultKeyMap(),
405+ keyMap: DefaultKeyMap(),
413− header: header.New(app.LSPClients),
406+ header: header.New(app.LSPClients),
414 }
407 }
415}
408}