Skip to content

Commit 949aa74

Browse files
committed
support session delete to session browser
1 parent aeaaca9 commit 949aa74

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

pkg/tui/dialog/session_browser.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dialog
22

33
import (
44
"fmt"
5+
"slices"
56
"strings"
67
"time"
78

@@ -29,6 +30,7 @@ type sessionBrowserKeyMap struct {
2930
Star key.Binding
3031
FilterStar key.Binding
3132
CopyID key.Binding
33+
Delete key.Binding
3234
}
3335

3436
// Session browser dialog dimension constants
@@ -82,6 +84,7 @@ func NewSessionBrowserDialog(sessions []session.Summary) Dialog {
8284
Star: key.NewBinding(key.WithKeys("ctrl+s")),
8385
FilterStar: key.NewBinding(key.WithKeys("ctrl+f")),
8486
CopyID: key.NewBinding(key.WithKeys("ctrl+y")),
87+
Delete: key.NewBinding(key.WithKeys("ctrl+d")),
8588
},
8689
openedAt: time.Now(),
8790
}
@@ -195,6 +198,17 @@ func (d *sessionBrowserDialog) Update(msg tea.Msg) (layout.Model, tea.Cmd) {
195198
}
196199
return d, nil
197200

201+
case key.Matches(msg, d.keyMap.Delete):
202+
if d.selected >= 0 && d.selected < len(d.filtered) {
203+
sessionID := d.filtered[d.selected].ID
204+
d.sessions = slices.DeleteFunc(d.sessions, func(s session.Summary) bool {
205+
return s.ID == sessionID
206+
})
207+
d.filterSessions()
208+
return d, core.CmdHandler(messages.DeleteSessionMsg{SessionID: sessionID})
209+
}
210+
return d, nil
211+
198212
default:
199213
var cmd tea.Cmd
200214
d.textInput, cmd = d.textInput.Update(msg)
@@ -333,7 +347,8 @@ func (d *sessionBrowserDialog) View() string {
333347
AddSeparator().
334348
AddContent(idFooter).
335349
AddSpace().
336-
AddHelpKeys("↑/↓", "navigate", "ctrl+s", "star", "ctrl+f", filterDesc, "ctrl+y", "copy id", "enter", "load", "esc", "close").
350+
AddHelpKeys("↑/↓", "navigate", "ctrl+s", "star", "ctrl+f", filterDesc, "ctrl+y", "copy id", "ctrl+d", "delete").
351+
AddHelpKeys("enter", "load", "esc", "close").
337352
Build()
338353

339354
return styles.DialogStyle.Width(dialogWidth).Render(content)

pkg/tui/handlers.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ func (m *appModel) handleRegenerateTitle() (tea.Model, tea.Cmd) {
150150
return m, tea.Batch(spinnerCmd, notification.SuccessCmd("Regenerating title..."))
151151
}
152152

153+
func (m *appModel) handleDeleteSession(sessionID string) (tea.Model, tea.Cmd) {
154+
store := m.application.SessionStore()
155+
if store == nil {
156+
return m, notification.ErrorCmd("No session store configured")
157+
}
158+
159+
if err := store.DeleteSession(context.Background(), sessionID); err != nil {
160+
return m, notification.ErrorCmd("Failed to delete session: " + err.Error())
161+
}
162+
163+
return m, notification.SuccessCmd("Session deleted.")
164+
}
165+
153166
func isErrTitleGenerating(err error) bool {
154167
return err != nil && err.Error() == app.ErrTitleGenerating.Error()
155168
}

pkg/tui/messages/session.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type (
5959
// ToggleSessionStarMsg toggles star on a session; empty ID means current session.
6060
ToggleSessionStarMsg struct{ SessionID string }
6161

62+
// DeleteSessionMsg deletes a session by ID.
63+
DeleteSessionMsg struct{ SessionID string }
64+
6265
// SetSessionTitleMsg sets the session title to specified value.
6366
SetSessionTitleMsg struct{ Title string }
6467

pkg/tui/tui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,9 @@ func (m *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
836836
}
837837
return m.handleToggleSessionStar(sessionID)
838838

839+
case messages.DeleteSessionMsg:
840+
return m.handleDeleteSession(msg.SessionID)
841+
839842
case messages.SetSessionTitleMsg:
840843
return m.handleSetSessionTitle(msg.Title)
841844

0 commit comments

Comments
 (0)