summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-29 06:42:58 -0500
committeradamdottv <[email protected]>2025-05-29 06:42:58 -0500
commit9f1a75e93848fc8a714d3d43eb67a33e188a6523 (patch)
treecdafa751c185adeea975831cb889d56a53672ed5
parent2b77a7f71473c868fd0472c9284ddff18c83388a (diff)
downloadopencode-9f1a75e93848fc8a714d3d43eb67a33e188a6523.tar.gz
opencode-9f1a75e93848fc8a714d3d43eb67a33e188a6523.zip
wip: refactoring tui
-rw-r--r--internal/tui/app/app.go31
-rw-r--r--internal/tui/app/bridge.go63
-rw-r--r--internal/tui/tui.go2
3 files changed, 38 insertions, 58 deletions
diff --git a/internal/tui/app/app.go b/internal/tui/app/app.go
index c7ea0cc66..10ff74914 100644
--- a/internal/tui/app/app.go
+++ b/internal/tui/app/app.go
@@ -2,6 +2,7 @@ package app
import (
"context"
+ "fmt"
"maps"
"sync"
"time"
@@ -158,6 +159,36 @@ func (a *App) SendChatMessage(ctx context.Context, text string, attachments []me
return tea.Batch(cmds...)
}
+func (a *App) ListSessions(ctx context.Context) ([]session.Session, error) {
+ resp, err := a.Client.PostSessionListWithResponse(ctx)
+ if err != nil {
+ return nil, err
+ }
+
+ if resp.StatusCode() != 200 {
+ return nil, fmt.Errorf("failed to list sessions: %d", resp.StatusCode())
+ }
+
+ if resp.JSON200 == nil {
+ return []session.Session{}, nil
+ }
+
+ infos := *resp.JSON200
+
+ // Convert to old session type
+ sessions := make([]session.Session, len(infos))
+ for i, info := range infos {
+ sessions[i] = session.Session{
+ ID: info.Id,
+ Title: info.Title,
+ CreatedAt: time.Now(), // API doesn't provide this yet
+ UpdatedAt: time.Now(), // API doesn't provide this yet
+ }
+ }
+
+ return sessions, nil
+}
+
// initTheme sets the application theme based on the configuration
func (app *App) initTheme() {
cfg := config.Get()
diff --git a/internal/tui/app/bridge.go b/internal/tui/app/bridge.go
index f9c075cf5..b8af35fa5 100644
--- a/internal/tui/app/bridge.go
+++ b/internal/tui/app/bridge.go
@@ -24,71 +24,20 @@ func NewSessionServiceBridge(client *client.ClientWithResponses) *SessionService
// Create creates a new session
func (s *SessionServiceBridge) Create(ctx context.Context, title string) (session.Session, error) {
- resp, err := s.client.PostSessionCreateWithResponse(ctx)
- if err != nil {
- return session.Session{}, err
- }
- if resp.StatusCode() != 200 {
- return session.Session{}, fmt.Errorf("failed to create session: %d", resp.StatusCode())
- }
- info := resp.JSON200
-
- // Convert to old session type
- return session.Session{
- ID: info.Id,
- Title: info.Title,
- CreatedAt: time.Now(), // API doesn't provide this yet
- UpdatedAt: time.Now(), // API doesn't provide this yet
- }, nil
+ // Moved to app.CreateSession
+ return session.Session{}, fmt.Errorf("don't use this")
}
// Get retrieves a session by ID
func (s *SessionServiceBridge) Get(ctx context.Context, id string) (session.Session, error) {
- // TODO: API doesn't have a get by ID endpoint yet
- // For now, list all and find the one we want
- sessions, err := s.List(ctx)
- if err != nil {
- return session.Session{}, err
- }
-
- for _, sess := range sessions {
- if sess.ID == id {
- return sess, nil
- }
- }
-
- return session.Session{}, fmt.Errorf("session not found: %s", id)
+ // Moved to app.GetSession
+ return session.Session{}, fmt.Errorf("don't use this")
}
// List retrieves all sessions
func (s *SessionServiceBridge) List(ctx context.Context) ([]session.Session, error) {
- resp, err := s.client.PostSessionListWithResponse(ctx)
- if err != nil {
- return nil, err
- }
-
- if resp.StatusCode() != 200 {
- return nil, fmt.Errorf("failed to list sessions: %d", resp.StatusCode())
- }
-
- if resp.JSON200 == nil {
- return []session.Session{}, nil
- }
-
- infos := *resp.JSON200
-
- // Convert to old session type
- sessions := make([]session.Session, len(infos))
- for i, info := range infos {
- sessions[i] = session.Session{
- ID: info.Id,
- Title: info.Title,
- CreatedAt: time.Now(), // API doesn't provide this yet
- UpdatedAt: time.Now(), // API doesn't provide this yet
- }
- }
-
- return sessions, nil
+ // Moved to app.ListSessions
+ return []session.Session{}, fmt.Errorf("don't use this")
}
// Update updates a session - NOT IMPLEMENTED IN API YET
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index 5165e7cb3..19125210d 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -463,7 +463,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
a.showFilepicker = false
// Load sessions and show the dialog
- sessions, err := a.app.Sessions.List(context.Background())
+ sessions, err := a.app.ListSessions(context.Background())
if err != nil {
status.Error(err.Error())
return a, nil