mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-28 13:14:28 +01:00
wip: refactoring
This commit is contained in:
@@ -110,7 +110,7 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.viewport.GotoBottom()
|
||||
case pubsub.Event[message.Message]:
|
||||
needsRerender := false
|
||||
if msg.Type == pubsub.CreatedEvent {
|
||||
if msg.Type == message.EventMessageCreated {
|
||||
if msg.Payload.SessionID == m.session.ID {
|
||||
|
||||
messageExists := false
|
||||
@@ -142,7 +142,7 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if msg.Type == pubsub.UpdatedEvent && msg.Payload.SessionID == m.session.ID {
|
||||
} else if msg.Type == message.EventMessageUpdated && msg.Payload.SessionID == m.session.ID {
|
||||
for i, v := range m.messages {
|
||||
if v.ID == msg.Payload.ID {
|
||||
m.messages[i] = msg.Payload
|
||||
@@ -155,8 +155,8 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if needsRerender {
|
||||
m.renderView()
|
||||
if len(m.messages) > 0 {
|
||||
if (msg.Type == pubsub.CreatedEvent) ||
|
||||
(msg.Type == pubsub.UpdatedEvent && msg.Payload.ID == m.messages[len(m.messages)-1].ID) {
|
||||
if (msg.Type == message.EventMessageCreated) ||
|
||||
(msg.Type == message.EventMessageUpdated && msg.Payload.ID == m.messages[len(m.messages)-1].ID) {
|
||||
m.viewport.GotoBottom()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.loadModifiedFiles(ctx)
|
||||
}
|
||||
case pubsub.Event[session.Session]:
|
||||
if msg.Type == pubsub.UpdatedEvent {
|
||||
if msg.Type == session.EventSessionUpdated {
|
||||
if m.session.ID == msg.Payload.ID {
|
||||
m.session = msg.Payload
|
||||
}
|
||||
|
||||
@@ -65,13 +65,13 @@ func (m statusCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case chat.SessionClearedMsg:
|
||||
m.session = session.Session{}
|
||||
case pubsub.Event[session.Session]:
|
||||
if msg.Type == pubsub.UpdatedEvent {
|
||||
if msg.Type == session.EventSessionUpdated {
|
||||
if m.session.ID == msg.Payload.ID {
|
||||
m.session = msg.Payload
|
||||
}
|
||||
}
|
||||
case pubsub.Event[status.StatusMessage]:
|
||||
if msg.Type == pubsub.CreatedEvent {
|
||||
if msg.Type == status.EventStatusPublished {
|
||||
statusMsg := statusMessage{
|
||||
Level: msg.Payload.Level,
|
||||
Message: msg.Payload.Message,
|
||||
@@ -308,4 +308,3 @@ func NewStatusCmp(lspClients map[string]*lsp.Client) StatusCmp {
|
||||
|
||||
return statusComponent
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ func (s *sessionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if len(s.sessions) > 0 {
|
||||
selectedSession := s.sessions[s.selectedIdx]
|
||||
// Update the session manager with the selected session
|
||||
session.SetCurrentSession(selectedSession.ID)
|
||||
// session.SetCurrentSession(selectedSession.ID)
|
||||
return s, util.CmdHandler(SessionSelectedMsg{
|
||||
Session: selectedSession,
|
||||
})
|
||||
@@ -111,7 +111,7 @@ func (s *sessionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
func (s *sessionDialogCmp) View() string {
|
||||
t := theme.CurrentTheme()
|
||||
baseStyle := styles.BaseStyle()
|
||||
|
||||
|
||||
if len(s.sessions) == 0 {
|
||||
return baseStyle.Padding(1, 2).
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/opencode-ai/opencode/internal/logging"
|
||||
"github.com/opencode-ai/opencode/internal/pubsub"
|
||||
"github.com/opencode-ai/opencode/internal/session"
|
||||
"github.com/opencode-ai/opencode/internal/tui/components/chat"
|
||||
"github.com/opencode-ai/opencode/internal/tui/layout"
|
||||
"github.com/opencode-ai/opencode/internal/tui/theme"
|
||||
@@ -49,7 +48,7 @@ func (i *tableCmp) fetchLogs() tea.Cmd {
|
||||
|
||||
var logs []logging.Log
|
||||
var err error
|
||||
sessionId := session.CurrentSessionID()
|
||||
sessionId := "" //session.CurrentSessionID()
|
||||
|
||||
// Limit the number of logs to improve performance
|
||||
const logLimit = 100
|
||||
@@ -85,7 +84,7 @@ func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
case pubsub.Event[logging.Log]:
|
||||
// Only handle created events
|
||||
if msg.Type == pubsub.CreatedEvent {
|
||||
if msg.Type == logging.EventLogCreated {
|
||||
// Add the new log to our list
|
||||
i.logs = append([]logging.Log{msg.Payload}, i.logs...)
|
||||
// Keep the list at a reasonable size
|
||||
@@ -105,7 +104,7 @@ func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
t, cmd := i.table.Update(msg)
|
||||
cmds = append(cmds, cmd)
|
||||
i.table = t
|
||||
|
||||
|
||||
// Only send selected log message when selection changes
|
||||
selectedRow := i.table.SelectedRow()
|
||||
if selectedRow != nil {
|
||||
|
||||
@@ -137,7 +137,7 @@ func (p *chatPage) sendMessage(text string, attachments []message.Attachment) te
|
||||
|
||||
p.session = newSession
|
||||
// Update the current session in the session manager
|
||||
session.SetCurrentSession(newSession.ID)
|
||||
// session.SetCurrentSession(newSession.ID)
|
||||
|
||||
cmd := p.setSidebar()
|
||||
if cmd != nil {
|
||||
|
||||
@@ -212,11 +212,11 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
switch msg.Action {
|
||||
case dialog.PermissionAllow:
|
||||
a.app.Permissions.Grant(msg.Permission)
|
||||
a.app.Permissions.Grant(context.Background(), msg.Permission)
|
||||
case dialog.PermissionAllowForSession:
|
||||
a.app.Permissions.GrantPersistant(msg.Permission)
|
||||
a.app.Permissions.GrantPersistant(context.Background(), msg.Permission)
|
||||
case dialog.PermissionDeny:
|
||||
a.app.Permissions.Deny(msg.Permission)
|
||||
a.app.Permissions.Deny(context.Background(), msg.Permission)
|
||||
}
|
||||
a.showPermissions = false
|
||||
return a, cmd
|
||||
|
||||
Reference in New Issue
Block a user